| From: | jian he <jian(dot)universality(at)gmail(dot)com> |
|---|---|
| To: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: virtual generated column as partition key |
| Date: | 2025-11-17 08:08:01 |
| Message-ID: | CACJufxEV2dre3dti4+wRGEd-gDbWi0VFNG5qq0AB+Xj4n78PGQ@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
hi.
rebased and refactored a lot.
In pg_partitioned_table.partattrs, value 0 indicates that the corresponding
partition key is an expression, non-0 means key is column reference.
For a virtual generated column, partattrs refers to the attribute number of the
virtual generated column, and the corresponding generation expression is stored
in partvirtualexprs. (see below demo).
Because of this, we need to double check all the occurrences of
RelationGetPartitionKey.
CREATE TABLE gtest_part_keyxx (f2 bigint, f3 bigint GENERATED ALWAYS
AS (f2 * 2) VIRTUAL) PARTITION BY RANGE (f3, f3, f2, f3, (f2+1));
SELECT pg_get_partkeydef('gtest_part_keyxx'::regclass);
pg_get_partkeydef
------------------------------------
RANGE (f3, f3, f2, f3, ((f2 + 1)))
(1 row)
SELECT partrelid::regclass, partnatts, partattrs FROM
pg_partitioned_table WHERE partrelid = ('gtest_part_keyxx'::regclass);
partrelid | partnatts | partattrs
------------------+-----------+-----------
gtest_part_keyxx | 5 | 2 2 1 2 0
(1 row)
| Attachment | Content-Type | Size |
|---|---|---|
| v2-0001-virtual-generated-column-as-partition-key.patch | text/x-patch | 45.8 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Anthonin Bonnefoy | 2025-11-17 08:48:26 | Re: [PATCH] jit: fix build with LLVM-21 |
| Previous Message | Peter Smith | 2025-11-17 07:51:57 | Re: Skipping schema changes in publication |