Skip to content

Fix wrong result in parallel ChunkAppend - #9388

Draft
akuzm wants to merge 23 commits into
timescale:mainfrom
akuzm:exclude-chunk
Draft

Fix wrong result in parallel ChunkAppend#9388
akuzm wants to merge 23 commits into
timescale:mainfrom
akuzm:exclude-chunk

Conversation

@akuzm

@akuzm akuzm commented Mar 10, 2026

Copy link
Copy Markdown
Member

Some fields were not initialized properly in case when there's no startup exclusion but runtime parent exclusion, which led us to excluding the chunks that actually match.

Refactor the way we work with the lists of the matched plans to prevent confusion. Now we use the same initial list of matched plans always, and keep a separate list of plan states (excluded/finished/etc) which is used for iteration.

Parts:

Some fields were not initialized properly in case when there's no
startup exclusion but runtime parent exclusion, which led us to
excluding the chunks that actually match.

Refactor the way we work with the lists of the matched plans to prevent
confusion. Now we use the same initial list of matched plans always, and
keep a separate list of plan states (excluded/finished/etc) which is
used for iteration.
akuzm and others added 2 commits March 10, 2026 14:55
The test for parallel ChunkAppend with InitPlan params filtered on
column i (the partitioning column). This caused the planner to set
runtime_exclusion_children, which made it pick a Single Copy Gather
plan instead of a parallel-aware ChunkAppend. The shared-memory
subplan coordination path was never exercised, so the test passed
even with the buggy code.

Switch the filter to column j (non-partitioning column) so the
planner produces a truly parallel ChunkAppend with only
runtime_exclusion_parent. This correctly exposes the bug where
parallel workers received empty subplan lists from shared memory.

Verified on PG17 and PG18:
- Old code + new test: workers_ok = f (bug detected)
- Fixed code + new test: workers_ok = t (bug fixed)
@codecov

codecov Bot commented Mar 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.87234% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/nodes/chunk_append/exec.c 97.87% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

claude added 3 commits March 10, 2026 17:35
The partial and non-partial plan tests only ran EXPLAIN without
executing the query, so the worker code path that marks non-partial
plans as finished was never covered.  Add actual query execution to
exercise that path.
Cover the do_runtime_exclusion code path where
ts_chunk_append_get_scan_plan returns NULL for a MergeAppend child
in an ordered ChunkAppend with space partitioning. This exercises
the continue at exec.c:456 (scan == NULL skip).

The test creates a space-partitioned hypertable where one time slice
has data in both space partitions (producing a MergeAppend child)
and another has data in only one partition (producing a direct scan
child). A LATERAL join triggers runtime chunk exclusion, which must
handle both child types.
Shared tests run in parallel in the same database and must not create
new tables. Move to tsl/test/sql/ where each test gets its own database.
@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to lack of activity. This pull request will be closed in 30 days.

claude added 2 commits May 4, 2026 18:30
LIMIT 3 with the previous data sizes produced half-integer per-loop
averages (e.g. 5 result rows over 2 LATERAL loops yielded 2.5).  PG
versions disagree on how to format these: pre-PG18 rounds to integer
("2.00"), PG18 prints "2.50".  Increase the data so all per-loop
averages are integers (LIMIT 4, 4 rows in slice 1, 4 rows in slice 2).

Also drop the spurious blank line in parallel-15.out and parallel-16.out
that was introduced during the merge with main.
-- 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

Copy link
Copy Markdown
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants