@@ -337,7 +337,7 @@ protected Set<? extends RelationalExpression> dataAccessForMatchPartition(@Nonnu
337
337
bestMatchToDistinctPlanMap ,
338
338
binaryPartition ,
339
339
requestedOrderings );
340
- if (binaryIntersections .hasCommonIntersectionOrdering ()) {
340
+ if (binaryIntersections .hasViableIntersection ()) {
341
341
updateIntersectionInfoMap (intersectionInfoMap , binaryPartition , binaryIntersections );
342
342
} else {
343
343
if (sieveBitMatrix != null ) {
@@ -395,7 +395,10 @@ protected Set<? extends RelationalExpression> dataAccessForMatchPartition(@Nonnu
395
395
kPartition ,
396
396
requestedOrderings );
397
397
398
- Verify .verify (intersectionResult .hasCommonIntersectionOrdering ());
398
+ if (!intersectionResult .hasViableIntersection ()) {
399
+ continue ;
400
+ }
401
+
399
402
hasCommonOrderingForK = true ;
400
403
401
404
updateIntersectionInfoMap (intersectionInfoMap , kPartition , intersectionResult );
@@ -432,14 +435,6 @@ protected static Optional<List<Value>> commonRecordKeyValuesMaybe(@Nonnull Itera
432
435
}
433
436
key = keyMaybe .get ();
434
437
} else if (matchCandidate instanceof AggregateIndexMatchCandidate ) {
435
- // final var aggregateIndexMatchCandidate = (AggregateIndexMatchCandidate)matchCandidate;
436
- // final var rollUpToGroupingValues = regularMatchInfo.getRollUpToGroupingValues();
437
- // if (rollUpToGroupingValues == null) {
438
- // key = aggregateIndexMatchCandidate.getGroupByValues();
439
- // } else {
440
- // key = aggregateIndexMatchCandidate.getGroupByValues().subList(0, rollUpToGroupingValues.size());
441
- // }
442
-
443
438
final var aggregateIndexMatchCandidate = (AggregateIndexMatchCandidate )matchCandidate ;
444
439
final var rollUpToGroupingValues = regularMatchInfo .getRollUpToGroupingValues ();
445
440
if (rollUpToGroupingValues == null ) {
@@ -582,8 +577,13 @@ private static List<SingleMatchedAccess> prepareMatchesAndCompensations(final @N
582
577
final @ Nonnull Set <RequestedOrdering > requestedOrderings ) {
583
578
final var partialMatchesWithCompensation = new ArrayList <SingleMatchedAccess >();
584
579
for (final var partialMatch : partialMatches ) {
580
+ final var topToTopTranslationMapOptional = computeTopToTopTranslationMapMaybe (partialMatch );
581
+ if (topToTopTranslationMapOptional .isEmpty ()) {
582
+ continue ;
583
+ }
584
+ final var topToTopTranslationMap = topToTopTranslationMapOptional .get ();
585
585
final var satisfyingOrderingsPairOptional =
586
- satisfiesAnyRequestedOrderings (partialMatch , requestedOrderings );
586
+ satisfiesAnyRequestedOrderings (partialMatch , topToTopTranslationMap , requestedOrderings );
587
587
if (satisfyingOrderingsPairOptional .isEmpty ()) {
588
588
continue ;
589
589
}
@@ -603,7 +603,7 @@ private static List<SingleMatchedAccess> prepareMatchesAndCompensations(final @N
603
603
604
604
if (scanDirection == ScanDirection .FORWARD || scanDirection == ScanDirection .BOTH ) {
605
605
partialMatchesWithCompensation .add (new SingleMatchedAccess (partialMatch , compensation ,
606
- topAlias , false , satisfyingOrderingsPair .getRight ()));
606
+ topAlias , false , topToTopTranslationMap , satisfyingOrderingsPair .getRight ()));
607
607
}
608
608
609
609
//
@@ -616,7 +616,7 @@ private static List<SingleMatchedAccess> prepareMatchesAndCompensations(final @N
616
616
//
617
617
if (scanDirection == ScanDirection .REVERSE /* || scanDirection == ScanDirection.BOTH */ ) {
618
618
partialMatchesWithCompensation .add (new SingleMatchedAccess (partialMatch , compensation ,
619
- topAlias , true , satisfyingOrderingsPair .getRight ()));
619
+ topAlias , true , topToTopTranslationMap , satisfyingOrderingsPair .getRight ()));
620
620
}
621
621
}
622
622
@@ -626,6 +626,12 @@ private static List<SingleMatchedAccess> prepareMatchesAndCompensations(final @N
626
626
return partialMatchesWithCompensation ;
627
627
}
628
628
629
+ @ Nonnull
630
+ private static Optional <TranslationMap > computeTopToTopTranslationMapMaybe (final PartialMatch partialMatch ) {
631
+ final var maxMatchMap = partialMatch .getMatchInfo ().getMaxMatchMap ();
632
+ return maxMatchMap .pullUpMaybe (Quantifier .current (), Quantifier .current ());
633
+ }
634
+
629
635
/**
630
636
* Private helper method to compute the subset of orderings passed in that would be satisfied by a scan
631
637
* if the given {@link PartialMatch} were to be planned.
@@ -638,21 +644,14 @@ private static List<SingleMatchedAccess> prepareMatchesAndCompensations(final @N
638
644
@ Nonnull
639
645
@ SuppressWarnings ("java:S135" )
640
646
private static Optional <NonnullPair <ScanDirection , Set <RequestedOrdering >>> satisfiesAnyRequestedOrderings (@ Nonnull final PartialMatch partialMatch ,
647
+ @ Nonnull final TranslationMap topToTopTranslationMap ,
641
648
@ Nonnull final Set <RequestedOrdering > requestedOrderings ) {
642
- final var maxMatchMap = partialMatch .getMatchInfo ().getMaxMatchMap ();
643
- final var translationMapOptional =
644
- maxMatchMap .pullUpMaybe (Quantifier .current (), Quantifier .current ());
645
- if (translationMapOptional .isEmpty ()) {
646
- return Optional .empty ();
647
- }
648
- final var translationMap = translationMapOptional .get ();
649
-
650
649
boolean seenForward = false ;
651
650
boolean seenReverse = false ;
652
651
final var satisfyingRequestedOrderings = ImmutableSet .<RequestedOrdering >builder ();
653
652
for (final var requestedOrdering : requestedOrderings ) {
654
653
final var translatedRequestedOrdering =
655
- requestedOrdering .translateCorrelations (translationMap , true );
654
+ requestedOrdering .translateCorrelations (topToTopTranslationMap , true );
656
655
657
656
final var scanDirectionForRequestedOrderingOptional =
658
657
satisfiesRequestedOrdering (partialMatch , translatedRequestedOrdering );
@@ -1040,11 +1039,6 @@ private static Ordering orderingFromOrderingParts(final @Nonnull List<MatchedOrd
1040
1039
protected static boolean isCompatibleComparisonKey (@ Nonnull Collection <Value > comparisonKeyValues ,
1041
1040
@ Nonnull List <Value > commonPrimaryKeyValues ,
1042
1041
@ Nonnull ImmutableSet <Value > equalityBoundKeyValues ) {
1043
- // if (comparisonKeyValues.isEmpty()) {
1044
- // // everything is in one row
1045
- // return true;
1046
- // }
1047
-
1048
1042
return commonPrimaryKeyValues
1049
1043
.stream ()
1050
1044
.filter (commonPrimaryKeyValue -> !equalityBoundKeyValues .contains (commonPrimaryKeyValue ))
@@ -1084,7 +1078,7 @@ private static void updateIntersectionInfoMap(@Nonnull final Map<BitSet, Interse
1084
1078
@ Nonnull final IntersectionResult intersectionResult ) {
1085
1079
Verify .verify (partition .size () >= 2 );
1086
1080
final var cacheKey = intersectionInfoKey (partition );
1087
- if (intersectionResult .hasCommonIntersectionOrdering ()) {
1081
+ if (intersectionResult .hasViableIntersection ()) {
1088
1082
if (!intersectionResult .getExpressions ().isEmpty ()) {
1089
1083
// This loop loops partition.size() times
1090
1084
for (final var subPartition : ChooseK .chooseK (partition , partition .size () - 1 )) {
@@ -1136,6 +1130,8 @@ protected static class SingleMatchedAccess {
1136
1130
private final CorrelationIdentifier candidateTopAlias ;
1137
1131
private final boolean reverseScanOrder ;
1138
1132
@ Nonnull
1133
+ private final TranslationMap topToTopTranslationMap ;
1134
+ @ Nonnull
1139
1135
private final Set <RequestedOrdering > satisfyingRequestedOrderings ;
1140
1136
@ Nonnull
1141
1137
private final Supplier <GroupByMappings > pulledUpGroupByMappingsSupplier ;
@@ -1144,12 +1140,14 @@ public SingleMatchedAccess(@Nonnull final PartialMatch partialMatch,
1144
1140
@ Nonnull final Compensation compensation ,
1145
1141
@ Nonnull final CorrelationIdentifier candidateTopAlias ,
1146
1142
final boolean reverseScanOrder ,
1143
+ @ Nonnull final TranslationMap topToTopTranslationMap ,
1147
1144
@ Nonnull final Set <RequestedOrdering > satisfyingRequestedOrderings ) {
1148
1145
this .partialMatch = partialMatch ;
1149
1146
this .compensation = compensation ;
1150
1147
this .candidateTopAlias = candidateTopAlias ;
1151
1148
this .reverseScanOrder = reverseScanOrder ;
1152
1149
this .satisfyingRequestedOrderings = ImmutableSet .copyOf (satisfyingRequestedOrderings );
1150
+ this .topToTopTranslationMap = topToTopTranslationMap ;
1153
1151
this .pulledUpGroupByMappingsSupplier =
1154
1152
Suppliers .memoize (() -> partialMatch .getMatchInfo ()
1155
1153
.adjustGroupByMappings (Quantifier .current (), partialMatch .getCandidateRef ().get ()));
@@ -1174,6 +1172,11 @@ public boolean isReverseScanOrder() {
1174
1172
return reverseScanOrder ;
1175
1173
}
1176
1174
1175
+ @ Nonnull
1176
+ public TranslationMap getTopToTopTranslationMap () {
1177
+ return topToTopTranslationMap ;
1178
+ }
1179
+
1177
1180
@ Nonnull
1178
1181
public Set <RequestedOrdering > getSatisfyingRequestedOrderings () {
1179
1182
return satisfyingRequestedOrderings ;
@@ -1261,7 +1264,7 @@ public List<RelationalExpression> getExpressions() {
1261
1264
return Objects .requireNonNull (expressions );
1262
1265
}
1263
1266
1264
- public boolean hasCommonIntersectionOrdering () {
1267
+ public boolean hasViableIntersection () {
1265
1268
return commonIntersectionOrdering != null ;
1266
1269
}
1267
1270
@@ -1276,7 +1279,7 @@ public Compensation getCompensation() {
1276
1279
}
1277
1280
1278
1281
@ Nonnull
1279
- public static IntersectionResult noCommonOrdering () {
1282
+ public static IntersectionResult noViableIntersection () {
1280
1283
return new IntersectionResult (null , Compensation .noCompensation (), ImmutableList .of ());
1281
1284
}
1282
1285
0 commit comments