Skip to content

Commit 969e3fd

Browse files
committed
responding to more comments
1 parent 6c00818 commit 969e3fd

File tree

12 files changed

+122
-82
lines changed

12 files changed

+122
-82
lines changed

fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/cascades/Compensation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ default Compensation intersect(@Nonnull Compensation otherCompensation) {
753753
// matter which side we take as both create the same compensating filter. If at any point in the
754754
// future one data access has a better reapplication we need to generate plan variants with
755755
// either compensation and let the planner figure out which one wins. We just pick one side here.
756-
// 2. Either one or both compensation functions are impossible, but thee intersection is possible.
756+
// 2. Either one or both compensation functions are impossible, but the intersection is possible.
757757
// We take the compensation function from this side and amend it with the compensation function
758758
// from the other side.
759759
final var newPredicateCompensationFunction = entry.getValue().amend(unmatchedAggregateMap, newMatchedAggregatesMap);

fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/cascades/GroupByMappings.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,32 @@
2525
import com.google.common.collect.ImmutableBiMap;
2626

2727
import javax.annotation.Nonnull;
28+
import java.util.Set;
29+
import java.util.function.Function;
2830

31+
/**
32+
* Class to keep track of matched groupings, matched aggregates, as well as unmatched aggregates (so far).
33+
*/
2934
public class GroupByMappings {
35+
/**
36+
* A {@link BiMap} from original query grouping {@link Value} to translated query grouping {@link Value} which is
37+
* specific to a {@link MatchCandidate}.
38+
*/
3039
@Nonnull
3140
private final BiMap<Value, Value> matchedGroupingsMap;
41+
42+
/**
43+
* A {@link BiMap} from original query aggregate {@link Value} to translated query aggregate {@link Value} which is
44+
* specific to a {@link MatchCandidate}.
45+
*/
3246
@Nonnull
3347
private final BiMap<Value, Value> matchedAggregatesMap;
3448

49+
/**
50+
* A {@link BiMap} from a unique id to an original query aggregate that is not yet matched. The unique id used here
51+
* is the same id that is used to handle unmatched aggregate functions in
52+
* {@link com.apple.foundationdb.record.query.plan.cascades.values.translation.MaxMatchMap#compute(Value, Value, Set, ValueEquivalence, Function)}.
53+
*/
3554
@Nonnull
3655
private final BiMap<CorrelationIdentifier, Value> unmatchedAggregatesMap;
3756

fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/cascades/PredicateMultiMap.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,14 @@ public Set<QueryPredicate> applyCompensationForPredicate(@Nonnull final Translat
156156

157157
boolean isImpossible();
158158

159+
/**
160+
* Recreates this predicate compensation function, and if appropriate, allows this compensation function
161+
* to become possible.
162+
* @param unmatchedAggregateMap unmatched aggregated map; the resulting predicate compensation function
163+
* can only become possible if the unmatched aggregates are not referenced by the predicate
164+
* @param amendedMatchedAggregateMap matched aggregate map (amended)
165+
* @return a new {@link PredicateCompensationFunction}
166+
*/
159167
@Nonnull
160168
PredicateCompensationFunction amend(@Nonnull BiMap<CorrelationIdentifier, Value> unmatchedAggregateMap,
161169
@Nonnull Map<Value, Value> amendedMatchedAggregateMap);
@@ -365,6 +373,14 @@ public Value applyCompensationForResult(@Nonnull final TranslationMap translatio
365373

366374
boolean isImpossible();
367375

376+
/**
377+
* Recreates this result compensation function, and if appropriate, allows this compensation function
378+
* to become possible.
379+
* @param unmatchedAggregateMap unmatched aggregated map; the resulting predicate compensation function
380+
* can only become possible if the unmatched aggregates are not referenced by the predicate
381+
* @param amendedMatchedAggregateMap matched aggregate map (amended)
382+
* @return a new {@link ResultCompensationFunction}
383+
*/
368384
@Nonnull
369385
ResultCompensationFunction amend(@Nonnull BiMap<CorrelationIdentifier, Value> unmatchedAggregateMap,
370386
@Nonnull Map<Value, Value> amendedMatchedAggregateMap);

fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/cascades/expressions/GroupByExpression.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -578,12 +578,11 @@ private SubsumedGroupingsResult groupingSubsumedBy(@Nonnull final Quantifier can
578578
// by the prefix of the candidate side. Iterate up to the smaller query side's grouping values to
579579
// find out.
580580
//
581-
for (int i = 0; i < translatedGroupingValues.size(); i++) {
582-
if (unmatchedCandidateValues.contains(candidateGroupingValues.get(i))) {
581+
for (final var translatedGroupingValue : translatedGroupingValuesSet) {
582+
if (unmatchedCandidateValues.contains(translatedGroupingValue)) {
583583
return SubsumedGroupingsResult.noSubsumption();
584584
}
585585
}
586-
587586
return SubsumedGroupingsResult.of(booleanWithConstraint, matchedGroupingsMap, translatedGroupingValues);
588587
}
589588

fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/cascades/rules/AbstractDataAccessRule.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,19 +106,18 @@
106106
*
107107
* The logic that this rules delegates to and actually creates the expressions can be found in
108108
* {@link MatchCandidate#toEquivalentPlan(PartialMatch, PlanContext, Memoizer, boolean)}.
109-
* @param <R> subtype of {@link RelationalExpression}
110109
*/
111110
@API(API.Status.EXPERIMENTAL)
112111
@SuppressWarnings({"java:S3776", "java:S4738", "OptionalUsedAsFieldOrParameterType"})
113-
public abstract class AbstractDataAccessRule<R extends RelationalExpression> extends CascadesRule<MatchPartition> {
112+
public abstract class AbstractDataAccessRule extends CascadesRule<MatchPartition> {
114113
private static final Logger logger = LoggerFactory.getLogger(AbstractDataAccessRule.class);
115114

116115
private final BindingMatcher<PartialMatch> completeMatchMatcher;
117-
private final BindingMatcher<R> expressionMatcher;
116+
private final BindingMatcher<? extends RelationalExpression> expressionMatcher;
118117

119118
protected AbstractDataAccessRule(@Nonnull final BindingMatcher<MatchPartition> rootMatcher,
120119
@Nonnull final BindingMatcher<PartialMatch> completeMatchMatcher,
121-
@Nonnull final BindingMatcher<R> expressionMatcher) {
120+
@Nonnull final BindingMatcher<? extends RelationalExpression> expressionMatcher) {
122121
super(rootMatcher, ImmutableSet.of(ReferencedFieldsConstraint.REFERENCED_FIELDS, RequestedOrderingConstraint.REQUESTED_ORDERING));
123122
this.completeMatchMatcher = completeMatchMatcher;
124123
this.expressionMatcher = expressionMatcher;
@@ -130,7 +129,7 @@ protected BindingMatcher<PartialMatch> getCompleteMatchMatcher() {
130129
}
131130

132131
@Nonnull
133-
protected BindingMatcher<R> getExpressionMatcher() {
132+
protected BindingMatcher<? extends RelationalExpression> getExpressionMatcher() {
134133
return expressionMatcher;
135134
}
136135

@@ -213,9 +212,8 @@ public void onMatch(@Nonnull final CascadesRuleCall call) {
213212
final var matchPartition = matchPartitionEntry.getValue();
214213

215214
//
216-
// The current match partition covers all matches that match the aliases in matchedAliases
217-
// as well as all predicates in matchedPredicates. In other words we now have to compensate
218-
// for all the remaining quantifiers and all remaining predicates.
215+
// The current match partition covers all matches that match a certain set of aliases and predicates.
216+
// We now have to compensate for all the those quantifiers and predicates.
219217
//
220218
final var dataAccessExpressions =
221219
dataAccessForMatchPartition(call,
@@ -912,6 +910,8 @@ private static Optional<RelationalExpression> applyCompensationForSingleDataAcce
912910
* before using the resulting {@link Compensation} to compute the compensating expression for the entire
913911
* intersection.
914912
* @param memoizer the memoizer
913+
* @param intersectionInfoMap the intersection info map being maintained by the caller (that enumerates the possible
914+
* intersections)
915915
* @param matchToPlanMap a map from match to single data access expression
916916
* @param partition a partition (i.e. a list of {@link SingleMatchedAccess}es that the caller would like to compute
917917
* and intersected data access for
@@ -976,6 +976,7 @@ protected static boolean isPartitionRedundant(@Nonnull final Map<BitSet, Interse
976976
@Nonnull
977977
private static Optional<Set<CorrelationIdentifier>> unmatchedIdsMaybe(@Nonnull final Map<BitSet, IntersectionInfo> intersectionInfoMap,
978978
@Nonnull final List<Vectored<SingleMatchedAccess>> partition) {
979+
Verify.verify(!partition.isEmpty());
979980
final var iterator = partition.iterator();
980981

981982
var unmatchedIdsOptional =

fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/cascades/rules/AdjustMatchRule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
* <li>referencing the {@link MatchCandidate}'s traversal w.r.t. the (partially) matched query.</li>
5151
* <li>does not have a corresponding match on the query side.</li>
5252
* </ul>
53-
* For more information, see {@link RelationalExpression#adjustMatch(PartialMatch, Quantifier)}.
53+
* For more information, see {@link RelationalExpression#adjustMatch(PartialMatch)}.
5454
* Currently the only such expression that can be absorbed is
5555
* {@link com.apple.foundationdb.record.query.plan.cascades.expressions.MatchableSortExpression}.
5656
* TODO Maybe that expression should just be a generic property-defining expression or properties should be kept on quantifiers.

fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/cascades/rules/AggregateDataAccessRule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
*/
7272
@API(API.Status.EXPERIMENTAL)
7373
@SuppressWarnings("PMD.TooManyStaticImports")
74-
public class AggregateDataAccessRule extends AbstractDataAccessRule<RelationalExpression> {
74+
public class AggregateDataAccessRule extends AbstractDataAccessRule {
7575
private static final BindingMatcher<PartialMatch> completeMatchMatcher =
7676
completeMatch().and(matchingAggregateIndexMatchCandidate());
7777
private static final BindingMatcher<RelationalExpression> expressionMatcher = anyExpression();

fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/cascades/rules/WithPrimaryKeyDataAccessRule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
*/
7272
@API(API.Status.EXPERIMENTAL)
7373
@SuppressWarnings("PMD.TooManyStaticImports")
74-
public class WithPrimaryKeyDataAccessRule extends AbstractDataAccessRule<RelationalExpression> {
74+
public class WithPrimaryKeyDataAccessRule extends AbstractDataAccessRule {
7575
private static final BindingMatcher<PartialMatch> completeMatchMatcher =
7676
completeMatch().and(matchingWithPrimaryKeyMatchCandidate());
7777
private static final BindingMatcher<RelationalExpression> expressionMatcher = anyExpression();

fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/plans/RecordQueryMultiIntersectionOnValuesPlan.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
import java.util.Objects;
5858
import java.util.Set;
5959
import java.util.function.Function;
60-
import java.util.stream.Collectors;
6160
import java.util.stream.Stream;
6261

6362
/**

0 commit comments

Comments
 (0)