Re: FOR PORTION OF assertion failure in ExecInitPartitionInfo()

From: Paul A Jungwirth <pj(at)illuminatedcomputing(dot)com>
To: Peter Eisentraut <peter(at)eisentraut(dot)org>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: FOR PORTION OF assertion failure in ExecInitPartitionInfo()
Date: 2026-08-31 17:44:12
Message-ID: CA+renyUmEJSMPw7yeFx3hx=p+4qpic-ASm2Yh5QBwAEtvD8i+Q@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Aug 19, 2026 at 10:26 PM Peter Eisentraut <peter(at)eisentraut(dot)org> wrote:
>
> The following test case triggers an assertion failure in
> ExecInitPartitionInfo():
>
> CREATE TABLE temporal_partitioned_by_range (
> id int4range,
> valid_at daterange,
> name text
> ) PARTITION BY RANGE (valid_at);
>
> CREATE TABLE temporal_partitioned_early
> PARTITION OF temporal_partitioned_by_range
> FOR VALUES FROM (MINVALUE) TO ('[2000-06-01,)');
> CREATE TABLE temporal_partitioned_late
> PARTITION OF temporal_partitioned_by_range
> FOR VALUES FROM ('[2000-06-01,)') TO (MAXVALUE);
>
> INSERT INTO temporal_partitioned_by_range (id, valid_at, name)
> VALUES ('[1,2)', daterange('2000-01-01', '2010-01-01'), 'one');
>
> DELETE FROM temporal_partitioned_by_range
> FOR PORTION OF valid_at FROM '2000-03-01' TO '2000-07-01'
> WHERE valid_at < '[2000-06-01,)'::daterange
> RETURNING id, valid_at, name;
>
> It appears to work correctly with assertions disabled, so maybe just
> some of the Assert()s in ExecInitPartitionInfo() need some updates?

I looked into this a bit. Here is a patch.

The problem is that we hit this assert when the partition key depends
on the valid_at column. Then if the temporal leftover gets routed to a
different partition that was pruned away from the original query, we
call ExecInitPartitionInfo, which never needed to handle CMD_DELETE
before. Everything works, but the Assert is out of date. So I agree
that is the only change needed.

The same function has a similar Assert for WITH CHECK OPTION, and we
can trigger that too. This patch updates both and provides tests.

I changed the repro SQL to partition on lower(valid_at) instead of
valid_at, which I think is more natural and more likely to be used in
practice. Both versions trigger the Assert pre-fix and work post-fix.

I also considered GENERATED columns. Those can't be used as partition
keys today, so they are rejected well before the exec phase (or even
running a query).

Yours,

--
Paul ~{:-)
pj(at)illuminatedcomputing(dot)com

Attachment Content-Type Size
v1-0001-Fix-assertion-failures-in-DELETE-FOR-PORTION-OF-t.patch text/x-patch 14.8 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Nazir Bilal Yavuz 2026-08-31 17:48:05 Re: Speed up COPY FROM text/CSV parsing using SIMD
Previous Message Andrei Lepikhov 2026-08-31 17:31:37 SUM(int2)/SUM(int4) do not detect overflow of the int8 accumulator