Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
635 changes: 635 additions & 0 deletions yaml-tests/src/test/java/CascadesQueryTests.java

Large diffs are not rendered by default.

835 changes: 835 additions & 0 deletions yaml-tests/src/test/resources/cascades-query-tests/MIGRATION.md

Large diffs are not rendered by default.

490 changes: 490 additions & 0 deletions yaml-tests/src/test/resources/cascades-query-tests/README.md

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
and-query-to-intersection-choice-unique:
- query: EXPLAIN select * from my_simple_record where str_value_indexed = 'even'
and num_value_unique = 0 and num_value_2 = 1 and num_value_3_indexed >= 2
and num_value_3_indexed <= 3
ref: and-query-to-intersection-choice-unique.yamsql:57
explain: ISCAN(MY_SIMPLE_RECORD_NUM_VALUE_UNIQUE [EQUALS promote(@c11 AS INT)])
| FILTER _.STR_VALUE_INDEXED EQUALS promote(@c7 AS STRING) AND _.NUM_VALUE_2
EQUALS promote(@c15 AS INT) AND _.NUM_VALUE_3_INDEXED GREATER_THAN_OR_EQUALS
promote(@c20 AS INT) AND _.NUM_VALUE_3_INDEXED LESS_THAN_OR_EQUALS promote(@c25
AS INT)
task_count: 910
task_total_time_ms: 9
transform_count: 195
transform_time_ms: 4
transform_yield_count: 78
insert_time_ms: 0
insert_new_count: 107
insert_reused_count: 6
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#
# and-query-to-intersection-choice-unique.yamsql
#
# This source file is part of the FoundationDB open source project
#
# Copyright 2015-2026 Apple Inc. and the FoundationDB project authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Ported from `FDBAndQueryToIntersectionTest.intersectionVersusRange2` — the same five-way AND, but
# with the unique index on NUM_VALUE_UNIQUE present. Because an equality on a unique column proves a
# maximum cardinality of one, the planner should scan that index and filter rather than build any
# range or intersection plan.
#
# A plan-choice test, so no `USE INDEX`. The result is empty for the same reason as in
# and-query-to-intersection-choice.yamsql; the real assertion arrives with the `explain:` value.
---
schema_template:
create table my_simple_record(
rec_no bigint,
str_value_indexed string,
num_value_unique integer,
num_value_2 integer,
num_value_3_indexed integer,
repeater integer array,
primary key(rec_no))
create index my_simple_record_str_value_indexed as select str_value_indexed from my_simple_record
create unique index my_simple_record_num_value_unique as select num_value_unique from my_simple_record
create index my_simple_record_num_value_2 as select num_value_2 from my_simple_record
create index index_2_3 as select num_value_2, num_value_3_indexed from my_simple_record
order by num_value_2, num_value_3_indexed
WITH OPTIONS(INTERMINGLE_TABLES=true)
---
include:
cascades-query-tests/includes/simple-record-100.yamsql
---
test_block:
name: and-query-to-intersection-choice-unique
preset: single_repetition_ordered
tests:
-
# intersectionVersusRange2
- query: select * from my_simple_record
where str_value_indexed = 'even' and num_value_unique = 0 and num_value_2 = 1
and num_value_3_indexed >= 2 and num_value_3_indexed <= 3
- explain: "ISCAN(MY_SIMPLE_RECORD_NUM_VALUE_UNIQUE [EQUALS promote(@c11 AS INT)]) | FILTER _.STR_VALUE_INDEXED EQUALS promote(@c7 AS STRING) AND _.NUM_VALUE_2 EQUALS promote(@c15 AS INT) AND _.NUM_VALUE_3_INDEXED GREATER_THAN_OR_EQUALS promote(@c20 AS INT) AND _.NUM_VALUE_3_INDEXED LESS_THAN_OR_EQUALS promote(@c25 AS INT)"
- result: []
...

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
and-query-to-intersection-choice:
- query: EXPLAIN select * from my_simple_record where str_value_indexed = 'even'
and num_value_unique = 0 and num_value_2 = 1 and num_value_3_indexed >= 2
and num_value_3_indexed <= 3
ref: and-query-to-intersection-choice.yamsql:60
explain: ISCAN(INDEX_2_3 [EQUALS promote(@c15 AS INT), [GREATER_THAN_OR_EQUALS
promote(@c20 AS INT) && LESS_THAN_OR_EQUALS promote(@c25 AS INT)]]) | FILTER
_.STR_VALUE_INDEXED EQUALS promote(@c7 AS STRING) AND _.NUM_VALUE_UNIQUE EQUALS
promote(@c11 AS INT)
task_count: 738
task_total_time_ms: 6
transform_count: 161
transform_time_ms: 3
transform_yield_count: 62
insert_time_ms: 0
insert_new_count: 86
insert_reused_count: 5
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#
# and-query-to-intersection-choice.yamsql
#
# This source file is part of the FoundationDB open source project
#
# Copyright 2015-2026 Apple Inc. and the FoundationDB project authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Ported from `FDBAndQueryToIntersectionTest.intersectionVersusRange` — a five-way AND should be
# served by the single INDEX_2_3 range scan with the remaining predicates as residual filters,
# rather than by an intersection of narrower scans.
#
# A plan-choice test, so it deliberately does not use `USE INDEX`. The source removes both
# MySimpleRecord$num_value_3_indexed and MySimpleRecord$num_value_unique — the latter because the
# Cascades planner would otherwise (correctly) prefer it. The companion file
# and-query-to-intersection-choice-unique.yamsql keeps the unique index and asserts exactly that.
#
# NUM_VALUE_UNIQUE is 1000 - i over the fixture, so it is never 0 and the result is empty; the
# source likewise never executes the query. The real assertion arrives with the `explain:` value.
---
schema_template:
create table my_simple_record(
rec_no bigint,
str_value_indexed string,
num_value_unique integer,
num_value_2 integer,
num_value_3_indexed integer,
repeater integer array,
primary key(rec_no))
create index my_simple_record_str_value_indexed as select str_value_indexed from my_simple_record
create index my_simple_record_num_value_2 as select num_value_2 from my_simple_record
create index index_2_3 as select num_value_2, num_value_3_indexed from my_simple_record
order by num_value_2, num_value_3_indexed
WITH OPTIONS(INTERMINGLE_TABLES=true)
---
include:
cascades-query-tests/includes/simple-record-100.yamsql
---
test_block:
name: and-query-to-intersection-choice
preset: single_repetition_ordered
tests:
-
# intersectionVersusRange
- query: select * from my_simple_record
where str_value_indexed = 'even' and num_value_unique = 0 and num_value_2 = 1
and num_value_3_indexed >= 2 and num_value_3_indexed <= 3
- explain: "ISCAN(INDEX_2_3 [EQUALS promote(@c15 AS INT), [GREATER_THAN_OR_EQUALS promote(@c20 AS INT) && LESS_THAN_OR_EQUALS promote(@c25 AS INT)]]) | FILTER _.STR_VALUE_INDEXED EQUALS promote(@c7 AS STRING) AND _.NUM_VALUE_UNIQUE EQUALS promote(@c11 AS INT)"
- result: []
...

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
and-query-to-intersection-compound-pk:
- query: EXPLAIN select * from my_simple_record where str_value_indexed = 'even'
and num_value_2 = 1 and num_value_3_indexed = 3
ref: and-query-to-intersection-compound-pk.yamsql:57
explain: 'COVERING(STR_VALUE_3_INDEX [EQUALS promote(@c7 AS STRING), EQUALS promote(@c15
AS INT)] -> [NUM_VALUE_3_INDEXED: KEY:[1], NUM_VALUE_UNIQUE: KEY:[2], STR_VALUE_INDEXED:
KEY:[0]]) ∩ COVERING(STR_VALUE_2_INDEX [EQUALS promote(@c7 AS STRING), EQUALS
promote(@c11 AS INT)] -> [NUM_VALUE_2: KEY:[1], NUM_VALUE_UNIQUE: KEY:[2],
STR_VALUE_INDEXED: KEY:[0]]) COMPARE BY (_.NUM_VALUE_UNIQUE) | FETCH'
task_count: 892
task_total_time_ms: 10
transform_count: 188
transform_time_ms: 5
transform_yield_count: 77
insert_time_ms: 0
insert_new_count: 106
insert_reused_count: 6
Loading
Loading