pgsql: Use generateClonedIndexStmt to propagate CREATE INDEX to partiti

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Use generateClonedIndexStmt to propagate CREATE INDEX to partiti
Date: 2024-10-05 18:46:55
Message-ID: E1sx9nr-002JlA-DG@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Michael Paquier 2024-10-06 09:23:31 pgsql: libpq: Discard leading and trailing spaces for parameters and va
Previous Message Heikki Linnakangas 2024-10-05 12:37:07 pgsql: Clean up WaitLatch calls that passed latch without WL_LATCH_SET