@@ -198,6 +198,7 @@ TExprBase BuildLookupIndex(TExprContext& ctx, const TPositionHandle pos,
198
198
.Columns (columns)
199
199
.Index ()
200
200
.Build (indexName)
201
+ .LookupStrategy ().Build (TKqpStreamLookupStrategyName)
201
202
.Done ();
202
203
}
203
204
@@ -336,6 +337,7 @@ bool IsParameterToListOfStructsRepack(const TExprBase& expr) {
336
337
TMaybeNode<TExprBase> BuildKqpStreamIndexLookupJoin (
337
338
const TDqJoin& join,
338
339
TExprBase leftInput,
340
+ const TString& indexName,
339
341
const TPrefixLookup& rightLookup,
340
342
const TKqpMatchReadResult& rightReadMatch,
341
343
TExprContext& ctx)
@@ -395,19 +397,34 @@ TMaybeNode<TExprBase> BuildKqpStreamIndexLookupJoin(
395
397
}
396
398
}
397
399
398
- TExprBase lookupJoin = Build<TKqlStreamLookupTable>(ctx, join.Pos ())
399
- .Table (rightLookup.MainTable )
400
- .LookupKeys (leftInput)
401
- .Columns (lookupColumns.Cast ())
402
- .LookupStrategy ().Build (TKqpStreamLookupJoinStrategyName)
403
- .Done ();
400
+ auto strategy = join.JoinType ().Value () == " LeftSemi"
401
+ ? TKqpStreamLookupSemiJoinStrategyName
402
+ : TKqpStreamLookupJoinStrategyName;
403
+
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
+ }
404
421
405
422
// Stream lookup join output: stream<tuple<left_row_struct, optional<right_row_struct>>>
406
423
// so we should apply filters to second element of tuple for each row
407
424
408
425
if (extraRightFilter.IsValid ()) {
409
426
lookupJoin = Build<TCoMap>(ctx, join.Pos ())
410
- .Input (lookupJoin)
427
+ .Input (lookupJoin. Cast () )
411
428
.Lambda ()
412
429
.Args ({" tuple" })
413
430
.Body <TExprList>()
@@ -429,7 +446,7 @@ TMaybeNode<TExprBase> BuildKqpStreamIndexLookupJoin(
429
446
430
447
if (rightReadMatch.ExtractMembers ) {
431
448
lookupJoin = Build<TCoMap>(ctx, join.Pos ())
432
- .Input (lookupJoin)
449
+ .Input (lookupJoin. Cast () )
433
450
.Lambda ()
434
451
.Args ({" tuple" })
435
452
.Body <TExprList>()
@@ -451,7 +468,7 @@ TMaybeNode<TExprBase> BuildKqpStreamIndexLookupJoin(
451
468
452
469
if (rightReadMatch.FilterNullMembers ) {
453
470
lookupJoin = Build<TCoMap>(ctx, join.Pos ())
454
- .Input (lookupJoin)
471
+ .Input (lookupJoin. Cast () )
455
472
.Lambda ()
456
473
.Args ({" tuple" })
457
474
.Body <TExprList>()
@@ -473,7 +490,7 @@ TMaybeNode<TExprBase> BuildKqpStreamIndexLookupJoin(
473
490
474
491
if (rightReadMatch.SkipNullMembers ) {
475
492
lookupJoin = Build<TCoMap>(ctx, join.Pos ())
476
- .Input (lookupJoin)
493
+ .Input (lookupJoin. Cast () )
477
494
.Lambda ()
478
495
.Args ({" tuple" })
479
496
.Body <TExprList>()
@@ -495,7 +512,7 @@ TMaybeNode<TExprBase> BuildKqpStreamIndexLookupJoin(
495
512
496
513
if (rightReadMatch.FlatMap ) {
497
514
lookupJoin = Build<TCoMap>(ctx, join.Pos ())
498
- .Input (lookupJoin)
515
+ .Input (lookupJoin. Cast () )
499
516
.Lambda ()
500
517
.Args ({" tuple" })
501
518
.Body <TExprList>()
@@ -516,7 +533,7 @@ TMaybeNode<TExprBase> BuildKqpStreamIndexLookupJoin(
516
533
}
517
534
518
535
return Build<TKqlIndexLookupJoin>(ctx, join.Pos ())
519
- .Input (lookupJoin)
536
+ .Input (lookupJoin. Cast () )
520
537
.LeftLabel ().Build (leftLabel)
521
538
.RightLabel ().Build (rightLabel)
522
539
.JoinType (join.JoinType ())
@@ -597,8 +614,7 @@ TMaybeNode<TExprBase> KqpJoinToIndexLookupImpl(const TDqJoin& join, TExprContext
597
614
}
598
615
599
616
const bool useStreamIndexLookupJoin = (kqpCtx.IsDataQuery () || kqpCtx.IsGenericQuery ())
600
- && kqpCtx.Config ->EnableKqpDataQueryStreamIdxLookupJoin
601
- && !indexName;
617
+ && kqpCtx.Config ->EnableKqpDataQueryStreamIdxLookupJoin ;
602
618
603
619
auto leftRowArg = Build<TCoArgument>(ctx, join.Pos ())
604
620
.Name (" leftRowArg" )
@@ -833,7 +849,7 @@ TMaybeNode<TExprBase> KqpJoinToIndexLookupImpl(const TDqJoin& join, TExprContext
833
849
.Build ()
834
850
.Done ();
835
851
836
- return BuildKqpStreamIndexLookupJoin (join, leftInput, *prefixLookup, *rightReadMatch, ctx);
852
+ return BuildKqpStreamIndexLookupJoin (join, leftInput, indexName, *prefixLookup, *rightReadMatch, ctx);
837
853
}
838
854
839
855
auto leftDataDeduplicated = DeduplicateByMembers (leftData, filter, deduplicateLeftColumns, ctx, join.Pos ());
0 commit comments