Re: Add SPLIT PARTITION/MERGE PARTITIONS commands

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Dmitry Koval <d(dot)koval(at)postgrespro(dot)ru>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
Date: 2025-06-18 02:55:38
Message-ID: CACJufxHjpdeDtOsmz9TyGX7jFU73LBEjX=JQpRQdAvDadT0coA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

hi.

The following are changes I made based on v47.
mainly comments refactoring, variable/argument renaming.
please see the attached patch.

+
+ /* Create the relation. */
+ newRelId = heap_create_with_catalog(newPartName->relname,
+ namespaceId,
+ modelRel->rd_rel->reltablespace,
+....
+ allowSystemTableMods,
+ false,
+ InvalidOid,
+ NULL);
heap_create_with_catalog parameter is_internal should be set to true.

+ /*
+ * Construct a map from the LIKE relation's attnos to the child rel's.
+ * This re-checks type match etc, although it shouldn't be possible to
+ * have a failure since both tables are locked.
+ */
+ attmap = build_attrmap_by_name(RelationGetDescr(newRel),
+ tupleDesc,
+ false);
this comment in createTableConstraints is confusing, especially the word "LIKE".
I didn' change it though.

+/*
+ * moveMergedTablesRows: scan partitions to be merged (mergingPartitions)
+ * of the partitioned table (rel) and move rows into the new partition
+ * (newPartRel). We also reevaulate check constraints against these rows.
+ */
+static void
+moveMergedTablesRows(List **wqueue, Relation rel,
+ List *mergingPartitions, Relation newPartRel)
the argument (Relation rel) never used in moveMergedTablesRows
we can remove it, or rename it as "parent_rel".
I didn' change it though.

moveMergedTablesRows was never used in SPLIT PARTITION,
so maybe we can rename it to
ATMergePartitionMoveTablesRows
or
ATMergePartitionMoveRows
or
ATMergePartitionRows
what do you think?

check_two_partitions_bounds_range
we can name it to
range_partition_bounds_check
I don't have a huge opinion though.

createTableConstraints(List **wqueue, AlteredTableInfo *tab,
Relation modelRel, Relation newRel)
rename argument (Relation modelRel) to parent_rel,
I think it will improve readability, since "parent_rel" can tell you it's a
partitioned table.

ATExecMergePartitions some comments position adjusted.

minor change src/test/regress/sql/partition_merge.sql
-SELECT * FROM sales_list;
-SELECT * FROM sales_nord;
-SELECT * FROM sales_all;
+SELECT tableoid::regclass, * FROM sales_list ORDER BY tableoid, salesperson_id;

we need an error case for
ERROR: cannot drop table \"%s\" because other objects depend on it
so I added a test for it. as you can see below, the error HINT message
is not great in this
context.

CREATE VIEW jan2022v as SELECT * FROM sales_jan2022;
ALTER TABLE sales_range MERGE PARTITIONS (sales_jan2022,
sales_feb2022) INTO sales_dec_jan_feb2022;
ERROR: cannot drop table sales_jan2022 because other objects depend on it
DETAIL: view jan2022v depends on table sales_jan2022
HINT: Use DROP ... CASCADE to drop the dependent objects too.
DROP VIEW jan2022v;

Attachment Content-Type Size
v47-0001-rename-function-argument-and-minor-refactor.no-cfbot application/octet-stream 18.1 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Yugo Nagata 2025-06-18 03:04:01 Re: relrewrite not documented at the top of heap_create_with_catalog()
Previous Message Fujii Masao 2025-06-18 02:21:35 Re: pg_dump misses comments on NOT NULL constraints