@@ -149,13 +149,14 @@ void StringColumn::scanSegment(const SegmentState& state, ColumnChunkData* resul
149149 auto * indexChunk = stringResultChunk->getIndexColumnChunk ();
150150 indexColumn->scanSegment (getChildState (state, ChildStateIndex::INDEX), indexChunk,
151151 startOffsetInSegment, numValuesToScan);
152+
153+ const auto initialDictSize =
154+ stringResultChunk->getDictionaryChunk ().getOffsetChunk ()->getNumValues ();
152155 if (numValuesToScan == state.metadata .numValues ) {
153156 // Append the entire dictionary into the chunk
154157 // Since the resultChunk may be non-empty, each index needs to be incremented by the initial
155158 // size of the dictionary so that the indices line up with the values that will be scanned
156159 // into the dictionary chunk
157- auto initialDictSize =
158- stringResultChunk->getDictionaryChunk ().getOffsetChunk ()->getNumValues ();
159160 for (row_idx_t i = 0 ; i < numValuesToScan; i++) {
160161 indexChunk->setValue <string_index_t >(
161162 indexChunk->getValue <string_index_t >(startOffsetInResult + i) + initialDictSize,
@@ -172,11 +173,10 @@ void StringColumn::scanSegment(const SegmentState& state, ColumnChunkData* resul
172173 auto index = indexChunk->getValue <string_index_t >(startOffsetInResult + i);
173174 auto element = indexMap.find (index);
174175 if (element == indexMap.end ()) {
175- indexMap.insert (
176- std::make_pair (index, startOffsetInResult + offsetsToScan.size ()));
177- indexChunk->setValue <string_index_t >(startOffsetInResult + offsetsToScan.size (),
176+ indexMap.insert (std::make_pair (index, initialDictSize + offsetsToScan.size ()));
177+ indexChunk->setValue <string_index_t >(initialDictSize + offsetsToScan.size (),
178178 startOffsetInResult + i);
179- offsetsToScan.emplace_back (index, startOffsetInResult + offsetsToScan.size ());
179+ offsetsToScan.emplace_back (index, initialDictSize + offsetsToScan.size ());
180180 } else {
181181 indexChunk->setValue <string_index_t >(element->second , startOffsetInResult + i);
182182 }
0 commit comments