disallow alter individual column if partition key contains wholerow reference

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: disallow alter individual column if partition key contains wholerow reference
Date: 2025-04-22 11:39:24
Message-ID: CACJufxG5wLiATocRTaC=z+kw4mUaasC-50+q9K=fOdAr3=OGRw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

hi.

while reviewing disallow generated column as partition key in [1],
I found out this bug.

demo:
drop table if exists t4;
CREATE TABLE t4(f1 int, f2 bigint) PARTITION BY list ((t4));
create table t4_1 partition of t4 for values in ((1,2));
alter table t4 alter column f2 set data type text using f2;

insert into t4 select 1, '2';
ERROR: invalid memory alloc request size 18446744073709551615

turns out the fix seems pretty simple, mainly on has_partition_attrs.
has_partition_attrs is used to
Checks if any of the 'attnums' is a partition key attribute for rel.
if partition keys have column references, then has_partition_attrs
should return true.

[1]: https://postgr.es/m/CACJufxF=WDGthXSAQr9thYUsfx_1_t9E6N8tE3B8EqXcVoVfQw@mail.gmail.com

Attachment Content-Type Size
v1-0001-fix-wholerow-as-partition-key-reference.patch text/x-patch 3.7 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Nisha Moond 2025-04-22 11:47:17 Re: Large expressions in indexes can't be stored (non-TOASTable)
Previous Message Nikolay Shaplov 2025-04-22 11:16:27 Re: Check for tuplestorestate nullness before dereferencing