@@ -640,6 +640,13 @@ ColumnPtr FunctionArrayIntersect<Mode>::execute(const UnpackedArrays & arrays, M
640640 // We have NULL in output only once if it should be there
641641 bool null_added = false ;
642642 bool use_null_map;
643+ const auto & arg = arrays.args [0 ];
644+ size_t off;
645+ // const array has only one row
646+ if (arg.is_const )
647+ off = (*arg.offsets )[0 ];
648+ else
649+ off = (*arg.offsets )[row];
643650
644651 if constexpr (std::is_same_v<Mode, ArrayModeUnion>)
645652 {
@@ -657,12 +664,6 @@ ColumnPtr FunctionArrayIntersect<Mode>::execute(const UnpackedArrays & arrays, M
657664 null_map.push_back (1 );
658665 null_added = true ;
659666 }
660- const auto & arg = arrays.args [0 ];
661- // const array has only one row
662- if (arg.is_const )
663- prev_off[0 ] = 0 ;
664- else
665- prev_off[0 ] = (*arg.offsets )[row];
666667 }
667668 else if constexpr (std::is_same_v<Mode, ArrayModeSymmetricDifference>)
668669 {
@@ -680,23 +681,10 @@ ColumnPtr FunctionArrayIntersect<Mode>::execute(const UnpackedArrays & arrays, M
680681 null_map.push_back (1 );
681682 null_added = true ;
682683 }
683- const auto & arg = arrays.args [0 ];
684- // const array has only one row
685- if (arg.is_const )
686- prev_off[0 ] = 0 ;
687- else
688- prev_off[0 ] = (*arg.offsets )[row];
689684 }
690685 else if constexpr (std::is_same_v<Mode, ArrayModeIntersect>)
691686 {
692687 use_null_map = all_nullable;
693- const auto & arg = arrays.args [0 ];
694- size_t off;
695- // const array has only one row
696- if (arg.is_const )
697- off = (*arg.offsets )[0 ];
698- else
699- off = (*arg.offsets )[row];
700688
701689 for (auto i : collections::range (prev_off[0 ], off))
702690 {
@@ -725,9 +713,6 @@ ColumnPtr FunctionArrayIntersect<Mode>::execute(const UnpackedArrays & arrays, M
725713 const char * data = nullptr ;
726714 pair = map.find (columns[0 ]->serializeValueIntoArena (i, arena, data));
727715 }
728- prev_off[0 ] = off;
729- if (arg.is_const )
730- prev_off[0 ] = 0 ;
731716
732717 if (!current_has_nullable)
733718 all_has_nullable = false ;
@@ -738,6 +723,10 @@ ColumnPtr FunctionArrayIntersect<Mode>::execute(const UnpackedArrays & arrays, M
738723 insertElement<Map, ColumnType, is_numeric_column>(pair, result_offset, result_data, null_map, use_null_map);
739724 }
740725 }
726+ // Now we update the offsets for the first array
727+ prev_off[0 ] = off;
728+ if (arg.is_const )
729+ prev_off[0 ] = 0 ;
741730
742731 result_offsets.getElement (row) = result_offset;
743732 }
0 commit comments