Skip to content

Commit 1b1fe84

Browse files
authored
Update more of FDBFilterCoalescingTest to use DualPlannerTest. (#1729)
This exposes that issue #2 works with Cascades.
1 parent 5692777 commit 1b1fe84

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

fdb-record-layer-core/src/test/java/com/apple/foundationdb/record/provider/foundationdb/query/FDBFilterCoalescingQueryTest.java

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,13 @@
3232
import com.apple.foundationdb.record.provider.foundationdb.FDBRecordVersion;
3333
import com.apple.foundationdb.record.query.RecordQuery;
3434
import com.apple.foundationdb.record.query.expressions.Query;
35+
import com.apple.foundationdb.record.query.expressions.QueryComponent;
36+
import com.apple.foundationdb.record.query.plan.RecordQueryPlanner;
3537
import com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan;
3638
import com.apple.test.Tags;
3739
import com.google.common.collect.Collections2;
3840
import com.google.protobuf.Message;
41+
import org.hamcrest.Matcher;
3942
import org.junit.jupiter.api.Tag;
4043
import org.junit.jupiter.api.Test;
4144

@@ -47,7 +50,8 @@
4750
import static com.apple.foundationdb.record.TestHelpers.assertDiscardedNone;
4851
import static com.apple.foundationdb.record.query.plan.match.PlanMatchers.bounds;
4952
import static com.apple.foundationdb.record.query.plan.match.PlanMatchers.coveringIndexScan;
50-
import static com.apple.foundationdb.record.query.plan.match.PlanMatchers.descendant;
53+
import static com.apple.foundationdb.record.query.plan.match.PlanMatchers.fetch;
54+
import static com.apple.foundationdb.record.query.plan.match.PlanMatchers.filter;
5155
import static com.apple.foundationdb.record.query.plan.match.PlanMatchers.hasTupleString;
5256
import static com.apple.foundationdb.record.query.plan.match.PlanMatchers.indexName;
5357
import static com.apple.foundationdb.record.query.plan.match.PlanMatchers.indexScan;
@@ -156,29 +160,39 @@ public void versionRangeCoalesce() throws Exception {
156160

157161
/**
158162
* Verify that the planner removes duplicate filters.
159-
* TODO We currently don't. Update this test when it gets implemented.
160-
* TODO: Some query plans include redundant filtering operations even when the index is a complete specification (https://github.com/FoundationDB/fdb-record-layer/issues/2)
161163
*/
162-
@Test
164+
@DualPlannerTest
163165
public void duplicateFilters() throws Exception {
164166
RecordMetaDataHook hook = metaData -> {
165167
metaData.addIndex("MySimpleRecord", new Index("multi_index", "str_value_indexed", "num_value_3_indexed"));
166168
};
167169
complexQuerySetup(hook);
170+
QueryComponent filter = Query.field("num_value_3_indexed").equalsValue(3);
168171
RecordQuery query = RecordQuery.newBuilder()
169172
.setRecordType("MySimpleRecord")
170173
.setFilter(Query.and(
171174
Query.field("str_value_indexed").equalsValue("even"),
172-
Query.field("num_value_3_indexed").equalsValue(3),
173-
Query.field("num_value_3_indexed").equalsValue(3)))
175+
filter,
176+
filter))
174177
.build();
175178

176-
// Fetch(Covering(Index(multi_index [[even, 3],[even, 3]]) -> [num_value_3_indexed: KEY[1], rec_no: KEY[2], str_value_indexed: KEY[0]]) | num_value_3_indexed EQUALS 3)
177179
RecordQueryPlan plan = planner.plan(query);
178-
assertThat(plan, descendant(coveringIndexScan(indexScan(allOf(indexName("multi_index"), bounds(hasTupleString("[[even, 3],[even, 3]]")))))));
179-
assertEquals(-766201402, plan.planHash(PlanHashable.PlanHashKind.LEGACY));
180-
assertEquals(-1632715349, plan.planHash(PlanHashable.PlanHashKind.FOR_CONTINUATION));
181-
assertEquals(-1418679945, plan.planHash(PlanHashable.PlanHashKind.STRUCTURAL_WITHOUT_LITERALS));
180+
// Index(multi_index [[even, 3],[even, 3]]) -> [num_value_3_indexed: KEY[1], rec_no: KEY[2], str_value_indexed: KEY[0]])
181+
final Matcher<RecordQueryPlan> matcher = indexScan(allOf(indexName("multi_index"), bounds(hasTupleString("[[even, 3],[even, 3]]"))));
182+
if (planner instanceof RecordQueryPlanner) {
183+
// TODO: Update this test when it gets implemented for old planner.
184+
// Some query plans include redundant filtering operations even when the index is a complete specification (https://github.com/FoundationDB/fdb-record-layer/issues/2)
185+
// Fetch(Covering(...) | num_value_3_indexed EQUALS 3)
186+
assertThat(plan, fetch(filter(filter, coveringIndexScan(matcher))));
187+
assertEquals(-766201402, plan.planHash(PlanHashable.PlanHashKind.LEGACY));
188+
assertEquals(-1632715349, plan.planHash(PlanHashable.PlanHashKind.FOR_CONTINUATION));
189+
assertEquals(-1418679945, plan.planHash(PlanHashable.PlanHashKind.STRUCTURAL_WITHOUT_LITERALS));
190+
} else {
191+
assertThat(plan, matcher);
192+
assertEquals(681699231, plan.planHash(PlanHashable.PlanHashKind.LEGACY));
193+
assertEquals(-1692140528, plan.planHash(PlanHashable.PlanHashKind.FOR_CONTINUATION));
194+
assertEquals(463756249, plan.planHash(PlanHashable.PlanHashKind.STRUCTURAL_WITHOUT_LITERALS));
195+
}
182196

183197
try (FDBRecordContext context = openContext()) {
184198
openSimpleRecordStore(context, hook);
@@ -203,7 +217,7 @@ public void duplicateFilters() throws Exception {
203217
* TODO The planner does not currently coalesce the overlapping filters (>= 3 and > 0).
204218
* TODO: Planner does not currently coalesce overlapping filters (https://github.com/FoundationDB/fdb-record-layer/issues/1)
205219
*/
206-
@Test
220+
@DualPlannerTest
207221
public void overlappingFilters() throws Exception {
208222
RecordMetaDataHook hook = metaData -> {
209223
metaData.addIndex("MySimpleRecord", new Index("multi_index", "str_value_indexed", "num_value_3_indexed"));

0 commit comments

Comments
 (0)