-
Notifications
You must be signed in to change notification settings - Fork 176
perf(duckdb): push down list length expressions #8544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mhk197
wants to merge
3
commits into
mk/list-length
Choose a base branch
from
mk/duckdb-list-length-pushdown
base: mk/list-length
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
vortex-sqllogictest/slt/duckdb/list_length_pushdown.slt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # SPDX-FileCopyrightText: Copyright the Vortex contributors | ||
|
|
||
| include ../setup.slt.no | ||
|
|
||
| # Two list columns so we can exercise list-length pushdown over the same and | ||
| # different columns, in both SELECT and WHERE. | ||
| statement ok | ||
| CREATE TABLE list_test (id INTEGER, a INTEGER[], b INTEGER[]); | ||
|
|
||
| statement ok | ||
| INSERT INTO list_test VALUES | ||
| (1, [10, 20, 30], [1]), | ||
| (2, [40, 50, 60, 70], [2, 3]), | ||
| (3, [80], [4, 5, 6]), | ||
| (4, [90, 100, 110, 120, 130], [7, 8, 9, 10]), | ||
| (5, [140, 150], []); | ||
|
|
||
| statement ok | ||
| COPY (SELECT * FROM list_test) TO '$__TEST_DIR__/list-length.vortex'; | ||
|
|
||
| # array_length projection is pushed into the scan. The "SELECT projections" | ||
| # marker in the Vortex EXPLAIN output indicates pushdown succeeded. | ||
| query TT | ||
| EXPLAIN (FORMAT json) | ||
| SELECT array_length(a) FROM '$__TEST_DIR__/list-length.vortex'; | ||
| ---- | ||
| <REGEX>:SELECT projections | ||
|
|
||
| # len/length/array_length all map to list_length for list arguments. | ||
| query I | ||
| SELECT array_length(a) FROM '$__TEST_DIR__/list-length.vortex' ORDER BY id; | ||
| ---- | ||
| 3 | ||
| 4 | ||
| 1 | ||
| 5 | ||
| 2 | ||
|
|
||
| query I | ||
| SELECT len(a) FROM '$__TEST_DIR__/list-length.vortex' ORDER BY id; | ||
| ---- | ||
| 3 | ||
| 4 | ||
| 1 | ||
| 5 | ||
| 2 | ||
|
|
||
| query I | ||
| SELECT length(a) FROM '$__TEST_DIR__/list-length.vortex' ORDER BY id; | ||
| ---- | ||
| 3 | ||
| 4 | ||
| 1 | ||
| 5 | ||
| 2 | ||
|
|
||
| # array_length over the other list column, including the empty list (length 0). | ||
| query I | ||
| SELECT array_length(b) FROM '$__TEST_DIR__/list-length.vortex' ORDER BY id; | ||
| ---- | ||
| 1 | ||
| 2 | ||
| 3 | ||
| 4 | ||
| 0 | ||
|
|
||
| # array_length in WHERE is pushed into the scan as a complex filter: it shows up under the | ||
| # scan's "Filters" as a list_length expression (and DuckDB drops its own filter operator). The | ||
| # SELECT here is a plain column, so `list.length` can only appear via the pushed-down filter. | ||
| query TT | ||
| EXPLAIN (FORMAT json) SELECT id FROM '$__TEST_DIR__/list-length.vortex' | ||
| WHERE array_length(a) >= 4; | ||
| ---- | ||
| <REGEX>:"Filters".*vortex\.list\.length | ||
|
|
||
| # array_length in WHERE on the same column used in the SELECT projection. | ||
| query I | ||
| SELECT array_length(a) FROM '$__TEST_DIR__/list-length.vortex' | ||
| WHERE array_length(a) >= 4 | ||
| ORDER BY id; | ||
| ---- | ||
| 4 | ||
| 5 | ||
|
|
||
| # array_length in WHERE filtering a different column than the SELECT projection. | ||
| query II | ||
| SELECT id, array_length(a) FROM '$__TEST_DIR__/list-length.vortex' | ||
| WHERE array_length(b) >= 3 | ||
| ORDER BY id; | ||
| ---- | ||
| 3 1 | ||
| 4 5 | ||
|
|
||
| # array_length over different columns in both SELECT and WHERE is pushed on both sides: the | ||
| # projection on `a` appears under "SELECT projections" and the filter on `b` under "Filters", | ||
| # both as list_length expressions. | ||
| query TT | ||
| EXPLAIN (FORMAT json) | ||
| SELECT array_length(a) FROM '$__TEST_DIR__/list-length.vortex' | ||
| WHERE array_length(b) >= 2; | ||
| ---- | ||
| <REGEX>:"Filters".*vortex\.list\.length.*"SELECT projections".*vortex\.list\.length | ||
|
|
||
| # array_length over different columns in both SELECT and WHERE. | ||
| query II | ||
| SELECT array_length(a), array_length(b) FROM '$__TEST_DIR__/list-length.vortex' | ||
| WHERE array_length(b) >= 2 | ||
| ORDER BY id; | ||
| ---- | ||
| 4 2 | ||
| 1 3 | ||
| 5 4 | ||
|
|
||
| # Mixing the len/length/array_length aliases across SELECT and WHERE. | ||
| query I | ||
| SELECT len(a) FROM '$__TEST_DIR__/list-length.vortex' | ||
| WHERE length(b) >= 2 | ||
| ORDER BY id; | ||
| ---- | ||
| 4 | ||
| 1 | ||
| 5 | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add EXPLAIN for all queries in the test to test pushdown happened