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