FOR PORTION OF assertion failure in ExecInitPartitionInfo()
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?
On Wed, Aug 19, 2026 at 10:26 PM Peter Eisentraut <peter@eisentraut.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?
Thanks for catching this! I'm on a family backpacking trip, so the
earliest I'll be able to look closely is after the 30th.
Yours,
--
Paul ~{:-)
pj@illuminatedcomputing.com
Does this one deserve a mention on the open items wiki [0]https://wiki.postgresql.org/wiki/PostgreSQL_19_Open_Items?
[0]: https://wiki.postgresql.org/wiki/PostgreSQL_19_Open_Items
--
nathan
On Wed, Aug 19, 2026 at 10:26 PM Peter Eisentraut <peter@eisentraut.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@illuminatedcomputing.com
On 31.08.26 19:44, Paul A Jungwirth wrote:
On Wed, Aug 19, 2026 at 10:26 PM Peter Eisentraut <peter@eisentraut.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.
Committed, thanks.