From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Use generateClonedIndexStmt to propagate CREATE INDEX to partiti
Date: Sat, 05 Oct 2024 18:46:55 +0000
Message-ID: <E1sx9nr-002JlA-DG@gemulon.postgresql.org> (raw)
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
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/68dfecbef210dc000271553cfcb2342989d4ca0f
Modified Files
--------------
contrib/seg/Makefile | 2 +-
contrib/seg/expected/partition.out | 54 +++++++++++++++++++++++++++++
contrib/seg/meson.build | 1 +
contrib/seg/sql/partition.sql | 36 ++++++++++++++++++++
src/backend/commands/indexcmds.c | 56 ++++++-------------------------
src/test/regress/expected/alter_table.out | 5 ++-
src/test/regress/sql/alter_table.sql | 2 --
7 files changed, 105 insertions(+), 51 deletions(-)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-committers@postgresql.org
Cc: tgl@sss.pgh.pa.us, pgsql-committers@lists.postgresql.org
Subject: Re: pgsql: Use generateClonedIndexStmt to propagate CREATE INDEX to partiti
In-Reply-To: <E1sx9nr-002JlA-DG@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox