Skip to content

Commit 7bb3fc8

Browse files
authored
Resolves #1026: index matching mechanics (#1027)
* Resolves #987: introduce concept of correlations (using quantifiers) * matching infrastructure * address review comments
1 parent 06716d8 commit 7bb3fc8

File tree

77 files changed

+8605
-982
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+8605
-982
lines changed

.idea/runConfigurations/ReplRunner.xml

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/ReleaseNotes.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ In this realase, the various implementations of the `RecordQueryPlan` interface
2424
* **Performance** Improvement 3 [(Issue #NNN)](https://github.com/FoundationDB/fdb-record-layer/issues/NNN)
2525
* **Performance** Improvement 4 [(Issue #NNN)](https://github.com/FoundationDB/fdb-record-layer/issues/NNN)
2626
* **Performance** Improvement 5 [(Issue #NNN)](https://github.com/FoundationDB/fdb-record-layer/issues/NNN)
27-
* **Feature** Feature 1 [(Issue #NNN)](https://github.com/FoundationDB/fdb-record-layer/issues/NNN)
27+
* **Feature** General index matching framework and mechanics needed for the new planner implementation. [(Issue #1026)](https://github.com/FoundationDB/fdb-record-layer/issues/1026)
2828
* **Feature** Feature 2 [(Issue #NNN)](https://github.com/FoundationDB/fdb-record-layer/issues/NNN)
2929
* **Feature** Feature 3 [(Issue #NNN)](https://github.com/FoundationDB/fdb-record-layer/issues/NNN)
3030
* **Feature** Feature 4 [(Issue #NNN)](https://github.com/FoundationDB/fdb-record-layer/issues/NNN)

fdb-record-layer-core/fdb-record-layer-core.gradle

+20-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ if (!hasProperty('coreNotStrict')) {
2727
apply from: rootProject.file('gradle/strict.gradle')
2828
}
2929

30+
configurations {
31+
repl.extendsFrom testRuntime
32+
}
33+
3034
dependencies {
3135
compile project(':fdb-extensions')
3236

@@ -48,10 +52,13 @@ dependencies {
4852
testRuntime "org.apache.logging.log4j:log4j-slf4j-impl:${log4jVersion}" // binding
4953
testCompile "org.apache.logging.log4j:log4j-core:${log4jVersion}" // library
5054

51-
testImplementation "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
55+
testCompile "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
5256
testCompile "org.junit.jupiter:junit-jupiter-params:${junitVersion}"
5357
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
5458
testAnnotationProcessor "com.google.auto.service:auto-service:${autoServiceVersion}"
59+
testCompile "org.jline:jline:${jlineVersion}"
60+
testCompile "org.junit.platform:junit-platform-launcher:${junitPlatformVersion}"
61+
repl "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
5562
}
5663

5764
sourceSets {
@@ -118,6 +125,18 @@ task testShadowJar(type: com.github.jengelman.gradle.plugins.shadow.tasks.Shadow
118125
exclude 'log4j.properties'
119126
}
120127

128+
task replJar(type: com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
129+
classifier = 'repl'
130+
from sourceSets.main.output
131+
from sourceSets.test.output
132+
configurations = [ project.configurations.repl ]
133+
manifest {
134+
inheritFrom project.tasks.jar.manifest
135+
attributes 'Main-Class': 'com.apple.foundationdb.record.query.plan.debug.ReplRunner'
136+
}
137+
mergeServiceFiles()
138+
}
139+
121140
publishing {
122141
publications {
123142
library(MavenPublication) {

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

+1
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ public RecordQueryCoveringIndexPlan rebase(@Nonnull final AliasMap translationMa
172172
return new RecordQueryCoveringIndexPlan(indexPlan, recordTypeName, availableFields, toRecord);
173173
}
174174

175+
@Nonnull
175176
@Override
176177
public boolean equalsWithoutChildren(@Nonnull RelationalExpression otherExpression,
177178
@Nonnull final AliasMap equivalencesMap) {

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ public PlannerGraph rewritePlannerGraph(@Nonnull List<? extends PlannerGraph> ch
156156
NodeInfo.NESTED_LOOP_JOIN_OPERATOR);
157157
final PlannerGraph graphForInner = Iterables.getOnlyElement(childGraphs);
158158
final PlannerGraph.NodeWithInfo explodeNode =
159-
new PlannerGraph.LogicalOperatorNodeWithInfo(NodeInfo.TABLE_FUNCTION_OPERATOR,
159+
new PlannerGraph.LogicalOperatorNodeWithInfo(this,
160+
NodeInfo.TABLE_FUNCTION_OPERATOR,
160161
ImmutableList.of("EXPLODE({{externalBinding}})"),
161162
ImmutableMap.of("externalBinding", Attribute.gml(externalBinding)));
162163
final PlannerGraph.Edge fromExplodeEdge = new PlannerGraph.Edge();

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

+7-31
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,19 @@
3030
import com.apple.foundationdb.record.provider.foundationdb.FDBRecordStoreBase;
3131
import com.apple.foundationdb.record.query.plan.AvailableFields;
3232
import com.apple.foundationdb.record.query.plan.temp.AliasMap;
33-
import com.apple.foundationdb.record.query.plan.temp.CorrelationIdentifier;
3433
import com.apple.foundationdb.record.query.plan.temp.GroupExpressionRef;
3534
import com.apple.foundationdb.record.query.plan.temp.Quantifier;
3635
import com.apple.foundationdb.record.query.plan.temp.Quantifiers;
3736
import com.apple.foundationdb.record.query.plan.temp.RelationalExpression;
3837
import com.apple.foundationdb.record.query.plan.temp.explain.PlannerGraphRewritable;
3938
import com.apple.foundationdb.record.query.plan.visitor.RecordQueryPlannerSubstitutionVisitor;
4039
import com.google.common.base.Verify;
41-
import com.google.common.collect.ImmutableSet;
42-
import com.google.common.collect.Sets;
4340
import com.google.protobuf.Message;
4441

4542
import javax.annotation.Nonnull;
4643
import javax.annotation.Nullable;
4744
import java.util.List;
4845
import java.util.Objects;
49-
import java.util.Set;
5046

5147
/**
5248
* An executable query plan for producing records.
@@ -181,7 +177,7 @@ default int structuralHashCode() {
181177
*/
182178
@API(API.Status.EXPERIMENTAL)
183179
default boolean structuralEquals(@Nullable final Object other) {
184-
return structuralEquals(other, AliasMap.empty());
180+
return structuralEquals(other, AliasMap.emptyMap());
185181
}
186182

187183
/**
@@ -222,37 +218,17 @@ default boolean structuralEquals(@Nullable final Object other,
222218
return false;
223219
}
224220

225-
final Set<CorrelationIdentifier> correlatedTo = getCorrelatedTo();
226-
final Set<CorrelationIdentifier> otherCorrelatedTo = otherExpression.getCorrelatedTo();
227-
228-
Sets.SetView<CorrelationIdentifier> unboundCorrelatedTo = Sets.difference(correlatedTo, equivalenceMap.sources());
229-
Sets.SetView<CorrelationIdentifier> unboundOtherCorrelatedTo = Sets.difference(otherCorrelatedTo, equivalenceMap.targets());
230-
231-
final Sets.SetView<CorrelationIdentifier> commonUnbound = Sets.intersection(unboundCorrelatedTo, unboundOtherCorrelatedTo);
232-
final AliasMap identitiesMap = AliasMap.identitiesFor(commonUnbound);
233-
unboundCorrelatedTo = Sets.difference(correlatedTo, commonUnbound);
234-
unboundOtherCorrelatedTo = Sets.difference(otherCorrelatedTo, commonUnbound);
235-
236221
final Iterable<AliasMap> boundCorrelatedReferencesIterable =
237-
AliasMap.empty()
238-
.match(unboundCorrelatedTo,
239-
alias -> ImmutableSet.of(),
240-
unboundOtherCorrelatedTo,
241-
otherAlias -> ImmutableSet.of(),
242-
false,
243-
(alias, otherAlias, nestedEquivalencesMap) -> true);
222+
enumerateUnboundCorrelatedTo(equivalenceMap, otherExpression);
244223

245224
for (final AliasMap boundCorrelatedReferencesMap : boundCorrelatedReferencesIterable) {
246-
final AliasMap.Builder boundEquivalenceMapBuilder = equivalenceMap.derived();
247-
248-
boundEquivalenceMapBuilder.putAll(identitiesMap);
249-
boundEquivalenceMapBuilder.putAll(boundCorrelatedReferencesMap);
225+
final AliasMap.Builder boundCorrelatedToBuilder = boundCorrelatedReferencesMap.derived();
250226

251-
AliasMap boundEquivalenceMap = AliasMap.empty();
227+
AliasMap boundCorrelatedToMap = AliasMap.emptyMap();
252228

253229
int i;
254230
for (i = 0; i < quantifiers.size(); i++) {
255-
boundEquivalenceMap = boundEquivalenceMapBuilder.build();
231+
boundCorrelatedToMap = boundCorrelatedToBuilder.build();
256232

257233
final Quantifier.Physical quantifier = quantifiers.get(i);
258234
final Quantifier.Physical otherQuantifier = otherQuantifiers.get(i);
@@ -266,11 +242,11 @@ default boolean structuralEquals(@Nullable final Object other,
266242
}
267243

268244
if (canCorrelate()) {
269-
boundEquivalenceMapBuilder.put(quantifier.getAlias(), otherQuantifier.getAlias());
245+
boundCorrelatedToBuilder.put(quantifier.getAlias(), otherQuantifier.getAlias());
270246
}
271247
}
272248

273-
if (i == quantifiers.size() && (equalsWithoutChildren(otherExpression, boundEquivalenceMap))) {
249+
if (i == quantifiers.size() && (equalsWithoutChildren(otherExpression, boundCorrelatedToMap))) {
274250
return true;
275251
}
276252
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ public boolean equalsWithoutChildren(@Nonnull RelationalExpression otherExpressi
144144
filter.semanticEquals(otherPlan.getPredicate(), equivalencesMap);
145145
}
146146

147+
@Nonnull
147148
@Override
148149
public String toString() {
149150
return getInnerPlan() + " | " + getPredicate();

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

-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ public boolean equalsWithoutChildren(@Nonnull RelationalExpression otherExpressi
152152
if (getClass() != otherExpression.getClass()) {
153153
return false;
154154
}
155-
156155
return comparisonKey.equals(((RecordQueryUnorderedDistinctPlan)otherExpression).comparisonKey);
157156
}
158157

0 commit comments

Comments
 (0)