Re: MERGE/SPLIT PARTITIONS issues/questions

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org, Alexander Korotkov <aekorotkov(at)gmail(dot)com>
Subject: Re: MERGE/SPLIT PARTITIONS issues/questions
Date: 2026-08-07 03:41:30
Message-ID: CACJufxHk0F+1UyvExHoMfBZrsUeGQiB8MBm1PC5Fd3MtAszLGw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

On Fri, Aug 7, 2026 at 6:59 AM Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com> wrote:
>
> > Copying the value of generated column "as is" can produce data that differs from
> > what the generated expression would compute if any merged partition's generation
> > expression differs from the partitioned table's.
>
> I think this would be probably fine, as we can get the same effect by
> replacing a function used by the expression, a preexisting condition
> for many existing cases. But I do agree that requiring the same
> expression is a better approach.
>
> Also, not directly related to this patch, but now that I looked into
> this, I can still use tableoids for check constraints with a text
> cast:
>
> CREATE TABLE t (i int) PARTITION BY RANGE (i);
> CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
> CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
> ALTER TABLE t ADD CONSTRAINT cc CHECK (tableoid::regclass::text <> 'tp_0_2');
> INSERT INTO t VALUES (0),(1);
> ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2; --
> SUCCESS, but should ERROR instead?

Interesting!

Before we call MergePartitionsMoveRows, we did RestrictSearchPath(),
which will set GUC search_path
to "pg_catalog, pg_temp" temporally, and text_regclass will consider
search_path when resolve object name.

On the other hand, if we unconditionally validate all the partitioned
table's inherited CHECK constraints, it may fail
and the resulting message isn't helpful.
The error message below shows what happens when evaluating all CHECK
constraints during MERGE PARTITIONS.

DROP TABLE IF EXISTS t;
CREATE TABLE t (i int, b text default 't') PARTITION BY RANGE (i);
CREATE TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1);
CREATE TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2);
ALTER TABLE t ADD CONSTRAINT cc CHECK (b::regclass::text in ('t',
'tp_0_1', 'tp_0_2', 'tp_1_2'));
INSERT INTO t VALUES (0);
INSERT INTO t VALUES (0, 'tp_0_1'), (1, 'tp_1_2'), (1, 'public.tp_1_2');
ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2;
ERROR: relation "t" does not exist

--
jian
https://www.enterprisedb.com/

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Michael Paquier 2026-08-07 06:34:38 Re: PostgreSQL 18.4 backend SIGSEGV in pgstat_gc_entry_refs() after caught DSM attach error
Previous Message Zexin Li 2026-08-07 01:58:31 Re: BUG #19598: pg_waldump: -s/-e accept out-of-range WAL locations and silently use the low 32 bits

Browse pgsql-hackers by date

  From Date Subject
Next Message Fujii Masao 2026-08-07 03:42:41 Re: 030_pg_recvlogical fails because the same PID is assigned
Previous Message Chao Li 2026-08-07 03:07:17 Re: Optimize UUID parse using SIMD