]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix subtly-incorrect matching of parent and child partitioned indexes.
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 18 Aug 2022 16:11:47 +0000 (12:11 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 18 Aug 2022 16:11:47 +0000 (12:11 -0400)
commit2cf16cd7497d1dd465f0b1ff67e6c15347233d71
treeed63cf5877cd7909e3211ed1f6af586bbe3ad3f3
parentd0e5dc7d30aa1f62ce131b58c4c116b585521f8d
Fix subtly-incorrect matching of parent and child partitioned indexes.

When creating a partitioned index, DefineIndex tries to identify
any existing indexes on the partitions that match the partitioned
index, so that it can absorb those as child indexes instead of
building new ones.  Part of the matching is to compare IndexInfo
structs --- but that wasn't done quite right.  We're comparing
the IndexInfo built within DefineIndex itself to one made from
existing catalog contents by BuildIndexInfo.  Notably, while
BuildIndexInfo will run index expressions and predicates through
expression preprocessing, that has not happened to DefineIndex's
struct.  The result is failure to match and subsequent creation
of duplicate indexes.

The easiest and most bulletproof fix is to build a new IndexInfo
using BuildIndexInfo, thereby guaranteeing that the processing done
is identical.

While here, let's also extract the opfamily and collation data
from the new partitioned index, removing ad-hoc logic that
duplicated knowledge about how those are constructed.

Per report from Christophe Pettus.  Back-patch to v11 where
we invented partitioned indexes.

Richard Guo and Tom Lane

Discussion: https://postgr.es/m/8864BFAA-81FD-4BF9-8E06-7DEB8D4164ED@thebuild.com
src/backend/commands/indexcmds.c
src/test/regress/expected/indexing.out
src/test/regress/sql/indexing.sql