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-17 07:51:50
Message-ID: CACJufxFTiAiN_27FzAE60Hm5yQ124EJ+b1dpNDstcSdCApFzLw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Jun 17, 2025 at 4:15 AM Dmitry Koval <d(dot)koval(at)postgrespro(dot)ru> wrote:
>
> Added patch and a bit modified test.
>

hi.
Please check the attached patch for addressing the following issues.

+ else
+ {
+ ereport(ERROR,
+ errcode(ERRCODE_DUPLICATE_TABLE),
+ errmsg("relation \"%s\" already exists", cmd->name->relname));
+ }
There are no regress tests for this, I have added a simple test for it.

SELECT c.oid::pg_catalog.regclass, c.relkind, inhdetachpending,
pg_catalog.pg_get_expr(c.relpartbound, c.oid)
FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i
WHERE c.oid = i.inhrelid AND i.inhparent = 'sales_range'::regclass
ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT',
c.oid::pg_catalog.regclass::pg_catalog.text;

I found about 10 similar queries in partition_merge. We can replace them with
prepared statement—parsing once and executing multiple times. This not only
improves the readability of the test code but also slightly speeds up test
execution.

there are some test code pattern like:
+SELECT * FROM sales_range;
+SELECT * FROM sales_jan2022;
+SELECT * FROM partitions_merge_schema2.sales_feb_mar_apr2022;
+SELECT * FROM sales_others;
since sales_jan2022, sales_feb_mar_apr2022, sales_others
are partition of sales_range, we can simply use
+SELECT tableoid::regclass, * FROM sales_range ORDER BY tableoid,
salesperson_id;

After applying the attached patch, partition_merge.out size is 61379
without the size is: 66145.

The attached patch also addressed issues raised from Álvaro Herrera in [1].
instead of making function StoreConstraints external, using
AddRelationNewConstraints to install check constraints for new relation
in createTableConstraints

[1] https://postgr.es/m/202502031640.zem6orjmmxoz@alvherre.pgsql

Attachment Content-Type Size
v46-0001-regress-test-refactoring-and-others.no-cfbot application/octet-stream 41.2 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2025-06-17 07:59:26 Re: pg_recvlogical cannot create slots with failover=true
Previous Message Peter Eisentraut 2025-06-17 07:43:13 Re: pg_dump/pg_dumpall help synopses and terminology