public inbox for [email protected]  
help / color / mirror / Atom feed
From: jian he <[email protected]>
To: Dmitry Koval <[email protected]>
Cc: [email protected]
Subject: Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
Date: Tue, 10 Jun 2025 13:50:12 +0800
Message-ID: <CACJufxHRX6xQtzn+KenK3SDR2+4kUpVnO+0axforV_pohwMnFw@mail.gmail.com> (raw)
In-Reply-To: <[email protected]>
References: <171085360143.2046436.7217841141682511557.pgcf@coridan.postgresql.org>
	<[email protected]>
	<CAPpHfdtXDuBaHscJn-wada6Kaf3fxmS4k-1TTVhpS+Kx=uveyw@mail.gmail.com>
	<[email protected]>
	<CAPpHfdv2V2tsvVn5LYyrJkzmPA==vbdCEKiT8j9yaaiDTfaQtA@mail.gmail.com>
	<[email protected]>
	<CALDaNm3V5DQSbZGxhYH+3MMMm-YdgOg+RdJ-ni6D0TZx_=Xd7w@mail.gmail.com>
	<[email protected]>
	<CAPpHfduH83+CW1dBppFVjxauPFGC+-ux+Y7wB0koZJCs029SXA@mail.gmail.com>
	<[email protected]>
	<CACJufxEi_JVg+=_BSS0o+TYUE_Hq+jmga_yxxuKLSGbQiAnZDg@mail.gmail.com>
	<[email protected]>
	<CACJufxFGPLTDW55bgaBTH1uCf0=YUZUVKWFrTBvOZNYKc49MxA@mail.gmail.com>
	<CACJufxHHnJm6Jb2YQpuRU1RX__tO=JJNJ5=EUMuzif_KNxGd9A@mail.gmail.com>
	<CACJufxFkscyhak2cSr8t+EPfwv11yccfEZBBnPbX4tRc_mWkXQ@mail.gmail.com>
	<[email protected]>

On Tue, Jun 10, 2025 at 6:48 AM Dmitry Koval <[email protected]> wrote:
> 3.
>  >i think, we can do the following way:
>  >if (modelRel->rd_rel->relam)
>  >  elog(ERROR, "error");
>  >relamId = modelRel->rd_rel->relam;
>
> Can you clarify what is reason to change the current AM-logic for
> creating a new partition?
>
> +       /* Look up the access method for new relation. */
> +       relamId = (modelRel->rd_rel->relam != InvalidOid) ?
> modelRel->rd_rel->relam : HEAP_TABLE_AM_OID;
>
> (If AM is set for a partitioned table, then use it, otherwise use AM for
> heap tables.)
>
I only want to allow HEAP_TABLE_AM_OID to be used
in the merge partition,
I guess that would avoid unintended consequences.

I proposed change was
+if (modelRel->rd_rel->relam != HEAP_TABLE_AM_OID)
+   elog(ERROR, "only heap table method is allowed");
+ relamId = modelRel->rd_rel->relam;


RangeVarGetAndCheckCreationNamespace
was called first on ATExecMergePartitions, then on createPartitionTable.
Maybe we can pass the first  ATExecMergePartitions call result
to createPartitionTable to avoid calling it twice.


CREATE TABLE pp (a int, b int) PARTITION BY LIST(a);
CREATE TABLE pp_p1 PARTITION OF pp FOR VALUES IN (1, 2);
CREATE TABLE pp_p2 PARTITION OF pp FOR VALUES IN (3, 4);
INSERT INTO pp(a, b) SELECT random(min=>1, max=>6),
random(min=>1::int, max=>10) FROM generate_series(0, 4) i;
alter table pp add constraint cc check(a < 0) not valid;

ALTER TABLE pp MERGE PARTITIONS (pp_p1,  pp_p2) INTO pp_p1_2;
src4=# \d+ pp_p1_2
                                         Table "public.pp_p1_2"
 Column |  Type   | Collation | Nullable | Default | Storage |
Compression | Stats target | Description
--------+---------+-----------+----------+---------+---------+-------------+--------------+-------------
 a      | integer |           |          |         | plain   |
    |              |
 b      | integer |           |          |         | plain   |
    |              |
Partition of: pp FOR VALUES IN (1, 2, 3, 4)
Partition constraint: ((a IS NOT NULL) AND (a = ANY (ARRAY[1, 2, 3, 4])))
Check constraints:
    "cc" CHECK (a < 0)
Access method: heap

constraint cc on pp_p1_2 should be NOT VALID.
also if the partitioned table has NOT ENFORCED CHECK constraint, it
will cause segfault.
attached is a possible fix, and related tests.(based on v42).


cosmetic changes:
many of the "forach" can change to "foreach_node".
for example in ATExecMergePartitions.
we can change
``foreach(listptr, cmd->partlist)``
to
``foreach_node(RangeVar, name, cmd->partlist)`


Attachments:

  [application/octet-stream] v42-0001-fix-MERGE-PARTITION-with-partitioned-table-not-enforc.no-cfbot (10.2K, ../CACJufxHRX6xQtzn+KenK3SDR2+4kUpVnO+0axforV_pohwMnFw@mail.gmail.com/2-v42-0001-fix-MERGE-PARTITION-with-partitioned-table-not-enforc.no-cfbot)
  download

view thread (178+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  In-Reply-To: <CACJufxHRX6xQtzn+KenK3SDR2+4kUpVnO+0axforV_pohwMnFw@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox