postgresql/contrib/seg/expected/partition.out
Tom Lane 68dfecbef2 Use generateClonedIndexStmt to propagate CREATE INDEX to partitions.
When instantiating an existing partitioned index for a new child
partition, we use generateClonedIndexStmt to build a suitable
IndexStmt to pass to DefineIndex.  However, when DefineIndex needs
to recurse to instantiate a newly created partitioned index on an
existing child partition, it was doing copyObject on the given
IndexStmt and then applying a bunch of ad-hoc fixups.  This has
a number of problems, primarily that it implies fresh lookups of
referenced objects such as opclasses and collations.  Since commit
2af07e2f7 caused DefineIndex to restrict search_path internally, those
lookups could fail or deliver different results than the original one.
We can avoid those problems and save a few dozen lines of code by
using generateClonedIndexStmt in this code path too.

Another thing this fixes is incorrect propagation of parent-index
comments to child indexes (because the copyObject approach copies
the idxcomment field while generateClonedIndexStmt doesn't).  I had
noticed this in connection with commit c01eb619a, but not run the
problem to ground.

I'm tempted to back-patch this further than v17, but the only thing
it's known to fix in older branches is the comment issue, which is
pretty minor and doesn't seem worth the risk of introducing new
issues in stable branches.  (If anyone does care about that,
clearing idxcomment in the copied IndexStmt would be a safer fix.)

Per bug #18637 from usamoi.  Back-patch to v17 where the search_path
change came in.

Discussion: https://postgr.es/m/18637-f51e314546e3ba2a@postgresql.org
2024-10-05 14:46:44 -04:00

55 lines
2.6 KiB
Plaintext

--
-- Test that partitioned-index operations cope with objects that are
-- not in the secure search path. (This has little to do with seg,
-- but we need an opclass that isn't in pg_catalog, and the base system
-- has no such opclass.) Note that we need to test propagation of the
-- partitioned index's properties both to partitions that pre-date it
-- and to partitions created later.
--
create function mydouble(int) returns int strict immutable parallel safe
begin atomic select $1 * 2; end;
create collation mycollation from "POSIX";
create table pt (category int, sdata seg, tdata text)
partition by list (category);
-- pre-existing partition
create table pt12 partition of pt for values in (1,2);
insert into pt values(1, '0 .. 1'::seg, 'zed');
-- expression references object in public schema
create index pti1 on pt ((mydouble(category) + 1));
-- opclass in public schema
create index pti2 on pt (sdata seg_ops);
-- collation in public schema
create index pti3 on pt (tdata collate mycollation);
-- new partition
create table pt34 partition of pt for values in (3,4);
insert into pt values(4, '-1 .. 1'::seg, 'foo');
\d+ pt
Partitioned table "public.pt"
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
----------+---------+-----------+----------+---------+----------+--------------+-------------
category | integer | | | | plain | |
sdata | seg | | | | plain | |
tdata | text | | | | extended | |
Partition key: LIST (category)
Indexes:
"pti1" btree ((mydouble(category) + 1))
"pti2" btree (sdata)
"pti3" btree (tdata COLLATE mycollation)
Partitions: pt12 FOR VALUES IN (1, 2),
pt34 FOR VALUES IN (3, 4)
\d+ pt12
Table "public.pt12"
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
----------+---------+-----------+----------+---------+----------+--------------+-------------
category | integer | | | | plain | |
sdata | seg | | | | plain | |
tdata | text | | | | extended | |
Partition of: pt FOR VALUES IN (1, 2)
Partition constraint: ((category IS NOT NULL) AND (category = ANY (ARRAY[1, 2])))
Indexes:
"pt12_expr_idx" btree ((mydouble(category) + 1))
"pt12_sdata_idx" btree (sdata)
"pt12_tdata_idx" btree (tdata COLLATE mycollation)