@@ -198,6 +198,7 @@ TExprBase BuildLookupIndex(TExprContext& ctx, const TPositionHandle pos,
198198 .Columns (columns)
199199 .Index ()
200200 .Build (indexName)
201+ .LookupStrategy ().Build (TKqpStreamLookupStrategyName)
201202 .Done ();
202203 }
203204
@@ -336,6 +337,7 @@ bool IsParameterToListOfStructsRepack(const TExprBase& expr) {
336337TMaybeNode<TExprBase> BuildKqpStreamIndexLookupJoin (
337338 const TDqJoin& join,
338339 TExprBase leftInput,
340+ const TString& indexName,
339341 const TPrefixLookup& rightLookup,
340342 const TKqpMatchReadResult& rightReadMatch,
341343 TExprContext& ctx)
@@ -399,19 +401,30 @@ TMaybeNode<TExprBase> BuildKqpStreamIndexLookupJoin(
399401 ? TKqpStreamLookupSemiJoinStrategyName
400402 : TKqpStreamLookupJoinStrategyName;
401403
402- TExprBase lookupJoin = Build<TKqlStreamLookupTable>(ctx, join.Pos ())
403- .Table (rightLookup.MainTable )
404- .LookupKeys (leftInput)
405- .Columns (lookupColumns.Cast ())
406- .LookupStrategy ().Build (strategy)
407- .Done ();
404+ TMaybeNode<TExprBase> lookupJoin;
405+ if (indexName) {
406+ lookupJoin = Build<TKqlStreamLookupIndex>(ctx, join.Pos ())
407+ .Table (rightLookup.MainTable )
408+ .LookupKeys (leftInput)
409+ .Columns (lookupColumns.Cast ())
410+ .Index ().Build (indexName)
411+ .LookupStrategy ().Build (strategy)
412+ .Done ();
413+ } else {
414+ lookupJoin = Build<TKqlStreamLookupTable>(ctx, join.Pos ())
415+ .Table (rightLookup.MainTable )
416+ .LookupKeys (leftInput)
417+ .Columns (lookupColumns.Cast ())
418+ .LookupStrategy ().Build (strategy)
419+ .Done ();
420+ }
408421
409422 // Stream lookup join output: stream<tuple<left_row_struct, optional<right_row_struct>>>
410423 // so we should apply filters to second element of tuple for each row
411424
412425 if (extraRightFilter.IsValid ()) {
413426 lookupJoin = Build<TCoMap>(ctx, join.Pos ())
414- .Input (lookupJoin)
427+ .Input (lookupJoin. Cast () )
415428 .Lambda ()
416429 .Args ({" tuple" })
417430 .Body <TExprList>()
@@ -433,7 +446,7 @@ TMaybeNode<TExprBase> BuildKqpStreamIndexLookupJoin(
433446
434447 if (rightReadMatch.ExtractMembers ) {
435448 lookupJoin = Build<TCoMap>(ctx, join.Pos ())
436- .Input (lookupJoin)
449+ .Input (lookupJoin. Cast () )
437450 .Lambda ()
438451 .Args ({" tuple" })
439452 .Body <TExprList>()
@@ -455,7 +468,7 @@ TMaybeNode<TExprBase> BuildKqpStreamIndexLookupJoin(
455468
456469 if (rightReadMatch.FilterNullMembers ) {
457470 lookupJoin = Build<TCoMap>(ctx, join.Pos ())
458- .Input (lookupJoin)
471+ .Input (lookupJoin. Cast () )
459472 .Lambda ()
460473 .Args ({" tuple" })
461474 .Body <TExprList>()
@@ -477,7 +490,7 @@ TMaybeNode<TExprBase> BuildKqpStreamIndexLookupJoin(
477490
478491 if (rightReadMatch.SkipNullMembers ) {
479492 lookupJoin = Build<TCoMap>(ctx, join.Pos ())
480- .Input (lookupJoin)
493+ .Input (lookupJoin. Cast () )
481494 .Lambda ()
482495 .Args ({" tuple" })
483496 .Body <TExprList>()
@@ -499,7 +512,7 @@ TMaybeNode<TExprBase> BuildKqpStreamIndexLookupJoin(
499512
500513 if (rightReadMatch.FlatMap ) {
501514 lookupJoin = Build<TCoMap>(ctx, join.Pos ())
502- .Input (lookupJoin)
515+ .Input (lookupJoin. Cast () )
503516 .Lambda ()
504517 .Args ({" tuple" })
505518 .Body <TExprList>()
@@ -520,7 +533,7 @@ TMaybeNode<TExprBase> BuildKqpStreamIndexLookupJoin(
520533 }
521534
522535 return Build<TKqlIndexLookupJoin>(ctx, join.Pos ())
523- .Input (lookupJoin)
536+ .Input (lookupJoin. Cast () )
524537 .LeftLabel ().Build (leftLabel)
525538 .RightLabel ().Build (rightLabel)
526539 .JoinType (join.JoinType ())
@@ -597,8 +610,7 @@ TMaybeNode<TExprBase> KqpJoinToIndexLookupImpl(const TDqJoin& join, TExprContext
597610 }
598611
599612 const bool useStreamIndexLookupJoin = (kqpCtx.IsDataQuery () || kqpCtx.IsGenericQuery ())
600- && kqpCtx.Config ->EnableKqpDataQueryStreamIdxLookupJoin
601- && !indexName;
613+ && kqpCtx.Config ->EnableKqpDataQueryStreamIdxLookupJoin ;
602614
603615 auto leftRowArg = Build<TCoArgument>(ctx, join.Pos ())
604616 .Name (" leftRowArg" )
@@ -830,7 +842,7 @@ TMaybeNode<TExprBase> KqpJoinToIndexLookupImpl(const TDqJoin& join, TExprContext
830842 .Build ()
831843 .Done ();
832844
833- return BuildKqpStreamIndexLookupJoin (join, leftInput, *prefixLookup, *rightReadMatch, ctx);
845+ return BuildKqpStreamIndexLookupJoin (join, leftInput, indexName, *prefixLookup, *rightReadMatch, ctx);
834846 }
835847
836848 auto leftDataDeduplicated = DeduplicateByMembers (leftData, filter, deduplicateLeftColumns, ctx, join.Pos ());
0 commit comments