-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
MDEV-38970: Streaming window functions step 1 #5267
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
Draft
OmarGamal10
wants to merge
9
commits into
MariaDB:main
Choose a base branch
from
OmarGamal10:mdev-38970
base: main
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.
+1,009
−19
Draft
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d399839
Set the base and initial structure for streaming window functions path
OmarGamal10 5559d96
Wire the streaming window functions path into the existing join loop
OmarGamal10 cc86ea9
Remove order_window_funcs_by_window_specs from preparation time, and
OmarGamal10 bf2734e
Fallback to materialization if GROUP BY due to regressions
OmarGamal10 d3e800d
Add COUNT() as a streamable window function
OmarGamal10 8f87283
Add UNBOUNDED PRECEDING as an explicit valid frame for streaming (relied
OmarGamal10 9a7ea71
Add initial testing file for streaming window functions
OmarGamal10 227812d
Cache THD in Window_funcs_sort_streaming to avoid calling current_thd in
OmarGamal10 d344567
Add missing check in Window_funcs_sort_streaming::setup
OmarGamal10 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,114 @@ | ||
| # | ||
| # Streaming Window Functions Tests | ||
| # | ||
|
|
||
| # I will remove these comments when I'm done testing, will just write the # cases I'll consider for testing here. | ||
|
|
||
| # Explain per scenario to lock up streaming path | ||
| # Explains for non streamable cases, no need to check output | ||
|
|
||
| # For now, row_number(), rank(), dense_rank() are streamable. | ||
| # should I only test on rank? would it make sense to add EXPLAIN for all? | ||
|
|
||
| # Basic streaming (one rank with explain, others only correctness) | ||
|
|
||
| # Order by and partition | ||
| # Explain with one function to show streamable and index or filesort is | ||
| # used | ||
| # Show compatible functions also stream | ||
| # show results only to prove partition tracking correctness | ||
| # windows reusing the main query order (whichever is longer) under its mdev | ||
| # incompatible orders materialize | ||
| # aggregate functions inside partition lists materialize | ||
| # aggregate functions anywhere in the select list materialize | ||
| # cases to look harder later (subqueries, expressions) | ||
|
|
||
| #test with limit and analyze to show we read only rows needed | ||
|
|
||
| CREATE TABLE t1 (pk INT PRIMARY KEY, a INT, b INT); | ||
| INSERT INTO t1 VALUES (1, 1, 3); | ||
| INSERT INTO t1 VALUES (2, 1, 1); | ||
| INSERT INTO t1 VALUES (3, 2, 2); | ||
| INSERT INTO t1 VALUES (4, 2, 4); | ||
| INSERT INTO t1 VALUES (5, 3, 1); | ||
| INSERT INTO t1 VALUES (6, 3, 2); | ||
|
|
||
| # Basic streaming: one rank with explain, others only correctness | ||
| SELECT pk, RANK() OVER (ORDER BY pk) AS rnk from t1; | ||
| --source include/explain-no-costs.inc | ||
| EXPLAIN FORMAT=JSON SELECT pk, RANK() OVER (ORDER BY pk) AS rnk from t1 limit 2; | ||
|
|
||
| # question: should i add test for other streamable functions? | ||
|
|
||
| # Order by and partition: explain with rank to show streamable | ||
| --source include/explain-no-costs.inc | ||
| EXPLAIN FORMAT=JSON SELECT rank() OVER (PARTITION BY a ORDER BY b) FROM t1; | ||
| SELECT row_number() OVER (PARTITION BY a ORDER BY b) as rn FROM t1; | ||
| SELECT rank() OVER (PARTITION BY a ORDER BY b) as rnk FROM t1; | ||
| SELECT dense_rank() OVER (PARTITION BY a ORDER BY b) as drnk FROM t1; | ||
|
|
||
| # Show compatible functions also stream | ||
| --source include/explain-no-costs.inc | ||
| EXPLAIN FORMAT=JSON SELECT rank() OVER (ORDER BY a), dense_rank() OVER (ORDER BY a) FROM t1; | ||
| SELECT rank() OVER (ORDER BY a) as rnk, dense_rank() OVER (ORDER BY a) as drnk FROM t1; | ||
|
|
||
| # Windows reusing the main query order (whichever is longer) | ||
| --source include/explain-no-costs.inc | ||
| EXPLAIN FORMAT=JSON SELECT rank() OVER (ORDER BY a, b) FROM t1 ORDER BY a; | ||
| SELECT rank() OVER (ORDER BY a, b) as rnk FROM t1 ORDER BY a; | ||
|
|
||
| --source include/explain-no-costs.inc | ||
| EXPLAIN FORMAT=JSON SELECT rank() OVER (ORDER BY a) FROM t1 ORDER BY a, b; | ||
| SELECT rank() OVER (ORDER BY a) as rnk FROM t1 ORDER BY a, b; | ||
|
|
||
| --source include/explain-no-costs.inc | ||
| EXPLAIN FORMAT=JSON SELECT rank() OVER (ORDER BY a) FROM t1 ORDER BY a; | ||
| SELECT rank() OVER (ORDER BY a) as rnk FROM t1 ORDER BY a; | ||
|
|
||
| # Incompatible orders materialize | ||
| --source include/explain-no-costs.inc | ||
| EXPLAIN FORMAT=JSON SELECT rank() OVER (ORDER BY a), rank() OVER (ORDER BY b) FROM t1; | ||
|
|
||
| # Aggregate functions inside partition lists materialize | ||
| --source include/explain-no-costs.inc | ||
| EXPLAIN FORMAT=JSON SELECT rank() OVER (PARTITION BY max(a) ORDER BY b) FROM t1; | ||
|
|
||
| # Aggregate functions anywhere in the select list materialize | ||
| --source include/explain-no-costs.inc | ||
| EXPLAIN FORMAT=JSON SELECT max(a), rank() OVER (ORDER BY b) FROM t1; | ||
|
|
||
| # Incompatible RANGE frame materializes | ||
| --source include/explain-no-costs.inc | ||
| EXPLAIN FORMAT=JSON SELECT count(*) OVER (ORDER BY a RANGE BETWEEN CURRENT ROW AND 5 FOLLOWING) FROM t1; | ||
|
|
||
| --source include/explain-no-costs.inc | ||
| EXPLAIN FORMAT=JSON SELECT count(*) OVER (ORDER BY a RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) FROM t1; | ||
|
|
||
| # GROUP BY materializes (for now?) | ||
| --source include/explain-no-costs.inc | ||
| EXPLAIN FORMAT=JSON SELECT rank() OVER (ORDER BY a) FROM t1 GROUP BY a; | ||
|
|
||
| # Multi-table join | ||
| CREATE TABLE t2 (pk INT PRIMARY KEY, c INT); | ||
| INSERT INTO t2 VALUES (1, 100); | ||
| INSERT INTO t2 VALUES (2, 200); | ||
| INSERT INTO t2 VALUES (3, 300); | ||
| INSERT INTO t2 VALUES (4, 400); | ||
| INSERT INTO t2 VALUES (5, 500); | ||
| INSERT INTO t2 VALUES (6, 600); | ||
|
|
||
| --source include/explain-no-costs.inc | ||
| EXPLAIN FORMAT=JSON SELECT rank() OVER (ORDER BY t1.b) FROM t1 JOIN t2 ON t1.pk = t2.pk; | ||
| SELECT rank() OVER (ORDER BY t1.b) as rnk FROM t1 JOIN t2 ON t1.pk = t2.pk; | ||
| SELECT rank() OVER (PARTITION BY t1.a ORDER BY t1.b) as rnk FROM t1 JOIN t2 ON t1.pk = t2.pk; | ||
| SELECT rank() OVER (ORDER BY t1.b) as rnk FROM t1 LEFT JOIN t2 ON t1.pk = t2.pk; | ||
|
|
||
| DROP TABLE t2; | ||
|
|
||
| # Subquery in FROM | ||
| --source include/explain-no-costs.inc | ||
| EXPLAIN FORMAT=JSON SELECT rank() OVER (ORDER BY a) as rnk FROM (SELECT a FROM t1 WHERE a > 1) derived; | ||
|
|
||
| # Cases to look harder later (subqueries, expressions) | ||
|
|
||
| DROP TABLE t1; |
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
Oops, something went wrong.
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.
process_rows()return value is ignored: potential error or KILLed query status is swallowed, add a check please