-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix wrong result in parallel ChunkAppend #9388
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
akuzm
wants to merge
23
commits into
timescale:main
Choose a base branch
from
akuzm:exclude-chunk
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.
Draft
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
f7f815a
Fix wrong result in parallel ChunkAppend
akuzm ac1bda3
format
akuzm c8d7535
Fix parallel ChunkAppend test to use non-partitioning column
8167dd5
Execute parallel mixed partial/non-partial plans
claude 34295fe
Add test for runtime exclusion with mixed MergeAppend/scan children
claude a327405
Move runtime exclusion test from shared to non-shared suite
claude 35b705a
Merge origin/main into pr9388 (using imerge)
claude 0a28b19
Stabilize chunk_append_space_runtime_exclusion across PG versions
claude 0dc3695
Merge branch 'main' into exclude-chunk
akuzm ba20237
Merge commit '903aaf030757f6f8e7351ae6faf81c829f92e96d' into HEAD
akuzm edd10a5
Merge commit 'a93f871c11b687b4cf268ede5cf80368f3231759' into HEAD
akuzm cc32de0
cleanup
akuzm 893bb82
Merge branch 'main' into exclude-chunk
akuzm 26a1ba9
tmp
akuzm cc33fa7
revert?
akuzm fa02504
Merge branch 'main' into exclude-chunk
akuzm 7f93049
Merge branch 'main' into exclude-chunk
akuzm 351285d
Merge branch 'main' into exclude-chunk
akuzm 8f7c46b
Merge remote-tracking branch 'origin/main' into HEAD
akuzm ed4375e
Merge branch 'main' into exclude-chunk
akuzm 6b36cf4
Merge branch 'main' into exclude-chunk
akuzm a9aab4a
Merge branch 'main' into exclude-chunk
akuzm 3b8597a
Merge branch 'main' into exclude-chunk
akuzm 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
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
104 changes: 104 additions & 0 deletions
104
tsl/test/expected/chunk_append_space_runtime_exclusion.out
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,104 @@ | ||
| -- This file and its contents are licensed under the Timescale License. | ||
| -- Please see the included NOTICE for copyright information and | ||
| -- LICENSE-TIMESCALE for a copy of the license. | ||
| -- Test runtime chunk exclusion in an ordered ChunkAppend with space | ||
| -- partitioning. When some time slices have multiple space partitions | ||
| -- (producing MergeAppend children) and others have a single partition | ||
| -- (producing direct scan children), the ChunkAppend must handle both | ||
| -- child types during runtime exclusion. | ||
| \set PREFIX 'EXPLAIN (COSTS OFF)' | ||
| \set PREFIX_ANALYZE 'EXPLAIN (COSTS OFF, ANALYZE, TIMING OFF, BUFFERS OFF, SUMMARY OFF)' | ||
| SET max_parallel_workers_per_gather = 0; | ||
| SET enable_material = off; | ||
| SET enable_seqscan = off; | ||
| SET enable_hashjoin = off; | ||
| SET enable_mergejoin = off; | ||
| CREATE TABLE space_mixed(time timestamptz NOT NULL, device_id int NOT NULL, value float); | ||
| SELECT create_hypertable('space_mixed', 'time', 'device_id', | ||
| number_partitions => 2, | ||
| chunk_time_interval => '5 days'::interval); | ||
| create_hypertable | ||
| -------------------------- | ||
| (1,public,space_mixed,t) | ||
|
|
||
| -- Row counts and LIMIT below are chosen so EXPLAIN ANALYZE per-loop | ||
| -- averages are integers; otherwise PG versions differ in how they | ||
| -- format half-integer values. | ||
| -- Time slice 1: both space partitions have data (produces MergeAppend). | ||
| INSERT INTO space_mixed VALUES | ||
| ('2024-01-01 01:00', 1, 1.0), ('2024-01-01 02:00', 1, 2.0), | ||
| ('2024-01-02 01:00', 3, 3.0), ('2024-01-02 02:00', 3, 4.0); | ||
| -- Time slice 2: only one space partition has data (produces direct scan). | ||
| INSERT INTO space_mixed VALUES | ||
| ('2024-01-06 01:00', 1, 5.0), ('2024-01-06 02:00', 1, 6.0), | ||
| ('2024-01-07 01:00', 1, 7.0), ('2024-01-07 02:00', 1, 8.0); | ||
| CREATE INDEX ON space_mixed(time); | ||
| ANALYZE space_mixed; | ||
| -- The driver table provides join parameters for runtime exclusion. | ||
| CREATE TABLE driver_times(t timestamptz PRIMARY KEY); | ||
| INSERT INTO driver_times VALUES ('2024-01-01'), ('2024-01-06'); | ||
| -- Plan should show ordered ChunkAppend with mixed children: | ||
| -- MergeAppend for the first time slice, direct IndexScan for the second. | ||
| :PREFIX | ||
| SELECT d.t, m.* | ||
| FROM driver_times d, | ||
| LATERAL (SELECT * FROM space_mixed m WHERE m.time >= d.t ORDER BY m.time LIMIT 4) m; | ||
| --- QUERY PLAN --- | ||
| Nested Loop | ||
| -> Index Only Scan using driver_times_pkey on driver_times d | ||
| -> Limit | ||
| -> Custom Scan (ChunkAppend) on space_mixed m | ||
| Order: m."time" | ||
| -> Merge Append | ||
| Sort Key: m."time" | ||
| -> Index Scan using _hyper_1_1_chunk_space_mixed_time_idx1 on _hyper_1_1_chunk m_1 | ||
| Index Cond: ("time" >= d.t) | ||
| -> Index Scan using _hyper_1_2_chunk_space_mixed_time_idx1 on _hyper_1_2_chunk m_2 | ||
| Index Cond: ("time" >= d.t) | ||
| -> Index Scan using _hyper_1_3_chunk_space_mixed_time_idx1 on _hyper_1_3_chunk m_3 | ||
| Index Cond: ("time" >= d.t) | ||
|
|
||
| -- Execute to trigger runtime exclusion. The MergeAppend child is | ||
| -- skipped by do_runtime_exclusion (scan == NULL path), while the | ||
| -- direct scan child participates in constraint exclusion. | ||
| :PREFIX_ANALYZE | ||
| SELECT d.t, m.* | ||
| FROM driver_times d, | ||
| LATERAL (SELECT * FROM space_mixed m WHERE m.time >= d.t ORDER BY m.time LIMIT 4) m; | ||
| --- QUERY PLAN --- | ||
| Nested Loop (actual rows=8.00 loops=1) | ||
| -> Index Only Scan using driver_times_pkey on driver_times d (actual rows=2.00 loops=1) | ||
| -> Limit (actual rows=4.00 loops=2) | ||
| -> Custom Scan (ChunkAppend) on space_mixed m (actual rows=4.00 loops=2) | ||
| Order: m."time" | ||
| Chunks excluded during runtime: 0 | ||
| -> Merge Append (actual rows=2.00 loops=2) | ||
| Sort Key: m."time" | ||
| -> Index Scan using _hyper_1_1_chunk_space_mixed_time_idx1 on _hyper_1_1_chunk m_1 (actual rows=1.00 loops=2) | ||
| Index Cond: ("time" >= d.t) | ||
| -> Index Scan using _hyper_1_2_chunk_space_mixed_time_idx1 on _hyper_1_2_chunk m_2 (actual rows=1.00 loops=2) | ||
| Index Cond: ("time" >= d.t) | ||
| -> Index Scan using _hyper_1_3_chunk_space_mixed_time_idx1 on _hyper_1_3_chunk m_3 (actual rows=4.00 loops=1) | ||
| Index Cond: ("time" >= d.t) | ||
|
|
||
| SELECT d.t, m.* | ||
| FROM driver_times d, | ||
| LATERAL (SELECT * FROM space_mixed m WHERE m.time >= d.t ORDER BY m.time LIMIT 4) m; | ||
| t | time | device_id | value | ||
| ------------------------------+------------------------------+-----------+------- | ||
| Mon Jan 01 00:00:00 2024 PST | Mon Jan 01 01:00:00 2024 PST | 1 | 1 | ||
| Mon Jan 01 00:00:00 2024 PST | Mon Jan 01 02:00:00 2024 PST | 1 | 2 | ||
| Mon Jan 01 00:00:00 2024 PST | Tue Jan 02 01:00:00 2024 PST | 3 | 3 | ||
| Mon Jan 01 00:00:00 2024 PST | Tue Jan 02 02:00:00 2024 PST | 3 | 4 | ||
| Sat Jan 06 00:00:00 2024 PST | Sat Jan 06 01:00:00 2024 PST | 1 | 5 | ||
| Sat Jan 06 00:00:00 2024 PST | Sat Jan 06 02:00:00 2024 PST | 1 | 6 | ||
| Sat Jan 06 00:00:00 2024 PST | Sun Jan 07 01:00:00 2024 PST | 1 | 7 | ||
| Sat Jan 06 00:00:00 2024 PST | Sun Jan 07 02:00:00 2024 PST | 1 | 8 | ||
|
|
||
| DROP TABLE space_mixed; | ||
| DROP TABLE driver_times; | ||
| RESET max_parallel_workers_per_gather; | ||
| RESET enable_material; | ||
| RESET enable_seqscan; | ||
| RESET enable_hashjoin; | ||
| RESET enable_mergejoin; | ||
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.
This test is just for improving coverage, it doesn't trigger any bug, that's why it's passing on main too.