Repository navigation
feat: clone partitioned tables with PARTITION BY / PARTITION OF - #39
Merged
Merged
Conversation
Recreate partitioned parents with PARTITION BY, partitions with PARTITION OF (incl. sub-partitions), copy rows from leaf partitions only, skip partition-inherited constraints/indexes/triggers, and order tables so parents precede partitions (pool workers wait for the parent). Adds test/test_partitions.sh (sync, skip rerun, async, parallel).
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #38
Problem
pgclone.schema()created a partitioned parent as a plain table and then aborted withcannot copy from partitioned table "m"; the partitions were never cloned.Changes
PARTITION BY <pg_get_partkeydef>; no data copy (COPY of a partitioned table is rejected).PARTITION OF <parent> FOR VALUES ...(sub-partitioned partitions also get their ownPARTITION BY); rows are copied from leaf partitions only, so nothing is loaded twice.conparentid = 0), indexes (not inpg_inherits) and triggers (tgparentid = 0) that a partition inherits are no longer cloned separately; a parent index dumped asON ONLYis created as a normal partitioned index so partitions inherit it.PGCLONE_TABLE_DEPTH_SQL) so parents exist before partitions. In the parallel pool a partition worker waits up to ~60 s for its parent to appear.pgclone_table) and the async paths (bgw_clone_one_table, schema async, parallel pool).Behaviour notes
pgclone.table()on a partitioned parent creates only the parent; clone the schema (or each partition) for the partitions. Documented indocs/USAGE.md.conflict=skipmatches existing parents/partitions by name (verified: all skipped when names match). Target partitions with different names look new and are created as extra partitions of the cloned parent.Testing
New
test/test_partitions.sh(wired intorun_tests.sh): syncschema(),conflict=skiprerun,schema_async(),schema_async()with 3 parallel workers. Fixture has a sub-partitioned partition and a partition that sorts before its parent by name. Asserts relkinds, each row exactly once (parent 5, leaves 2/2/1), PK/index inherited not duplicated.Full
./test/run_all.shpasses on PG14, 15, 16, 17 and 18 (partition tests 33/33, async 24/24, chaos 5/5 on each).Not covered
columns/ mask filters on partitioned tables were not specifically tested.🤖 Generated with Claude Code