Skip to content

Reset inherited flags on chunks attached to a hypertable - #10352

Merged
svenklemm merged 1 commit into
mainfrom
sven/attislocal
Jul 31, 2026
Merged

Reset inherited flags on chunks attached to a hypertable#10352
svenklemm merged 1 commit into
mainfrom
sven/attislocal

Conversation

@svenklemm

Copy link
Copy Markdown
Member

When attaching a chunk to a hypertable we would mark the relation as
inherited but leave the columns marked as local so a later DROP COLUMN
on the hypertable would not propagate to the chunk.

Clear the local flag on the inherited columns when a chunk is attached
so column changes on the hypertable propagate to it. Also add a
migration that fixes chunks already left in this state by an earlier
detach and attach round-trip.

@github-actions
github-actions Bot requested review from antekresic and dbeck July 28, 2026 20:14
@github-actions

Copy link
Copy Markdown

@dbeck, @antekresic: please review this pull request.

Powered by pull-review

@svenklemm svenklemm added this to the v2.29.1 milestone Jul 28, 2026
@svenklemm svenklemm added the force-auto-backport Automatically backport this PR or fix of this issue, even if it's not marked as "bug" label Jul 28, 2026
@codecov

codecov Bot commented Jul 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.66667% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/chunk.c 86.66% 1 Missing and 3 partials ⚠️

📢 Thoughts on this report? Let us know!

@svenklemm svenklemm changed the title Reset attislocal on chunks attached to a hypertable Reset inherited flags on chunks attached to a hypertable Jul 29, 2026
Comment thread tsl/test/expected/attach_chunk-18.out
Comment thread src/chunk.c
Comment on lines 1228 to +1230
AlterTable(&alterstmt, lockmode, &atcontext);

chunk_reset_inherited_flags(atcontext.relid);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chunk_add_inheritance is also called by add_foreign_table_as_chunk. would that caller be affected by this change?

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.

yes

Comment thread src/chunk.c Outdated
@svenklemm
svenklemm force-pushed the sven/attislocal branch 2 times, most recently from ca022d1 to 538dcc3 Compare July 30, 2026 10:47

@antekresic antekresic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also add a test with attaching foreign table for completeness.

Otherwise, lgtm.

@svenklemm
svenklemm force-pushed the sven/attislocal branch 2 times, most recently from 61e2524 to 1f04d33 Compare July 31, 2026 08:52
@svenklemm

Copy link
Copy Markdown
Member Author

We should also add a test with attaching foreign table for completeness.

Otherwise, lgtm.

done

Attaching an existing table as a chunk uses ALTER TABLE ... INHERIT,
which raises the inheritance count of the child columns and constraints
but leaves them marked as locally defined. A chunk is meant to be a pure
inheritance child, so a later DROP COLUMN or DROP CONSTRAINT on the
hypertable did not reach such a chunk and left an orphaned column or
constraint behind instead.

Clear the local flag on the inherited columns and constraints when a
chunk is attached so schema changes on the hypertable propagate to it.
Also add a migration that fixes chunks already left in this state by an
earlier detach and attach round-trip.
@svenklemm
svenklemm merged commit 49cac59 into main Jul 31, 2026
73 of 76 checks passed
@svenklemm
svenklemm deleted the sven/attislocal branch July 31, 2026 12:08
@timescale-automation

Copy link
Copy Markdown
Member

Automated backport to 2.29.x not done: cherry-pick failed.

Git status

HEAD detached at origin/2.29.x
You are currently cherry-picking commit 49cac5959.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	new file:   .unreleased/fix_attach_chunk_attislocal
	modified:   src/chunk.c
	renamed:    tsl/test/expected/attach_chunk.out -> tsl/test/expected/attach_chunk-16.out
	new file:   tsl/test/expected/attach_chunk-17.out
	new file:   tsl/test/expected/attach_chunk-18.out
	new file:   tsl/test/expected/attach_chunk-19.out
	modified:   tsl/test/sql/.gitignore
	modified:   tsl/test/sql/CMakeLists.txt
	renamed:    tsl/test/sql/attach_chunk.sql -> tsl/test/sql/attach_chunk.sql.in

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   sql/updates/latest-dev.sql


Job log

@timescale-automation timescale-automation added auto-backport-not-done Automated backport of this PR has failed non-retriably (e.g. conflicts) backported-2.29.x labels Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-backport-not-done Automated backport of this PR has failed non-retriably (e.g. conflicts) backported-2.29.x force-auto-backport Automatically backport this PR or fix of this issue, even if it's not marked as "bug"

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants