pgsql: Fix marking of indisvalid for partitioned indexes at creation

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix marking of indisvalid for partitioned indexes at creation
Date: 2023-06-30 04:55:48
Message-ID: E1qF6Ae-0018gy-SS@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix marking of indisvalid for partitioned indexes at creation

The logic that introduced partitioned indexes missed a few things when
invalidating a partitioned index when these are created, still the code
is written to handle recursions:
1) If created from scratch because a mapping index could not be found,
the new index created could be itself invalid, if for example it was a
partitioned index with one of its leaves invalid.
2) A CCI was missing when indisvalid is set for a parent index, leading
to inconsistent trees when recursing across more than one level for a
partitioned index creation if an invalidation of the parent was
required.

This could lead to the creation of a partition index tree where some of
the partitioned indexes are marked as invalid, but some of the parents
are marked valid, which is not something that should happen (as
validatePartitionedIndex() defines, indisvalid is switched to true for a
partitioned index iff all its partitions are themselves valid).

This patch makes sure that indisvalid is set to false on a partitioned
index if at least one of its partition is invalid. The flag is set to
true if *all* its partitions are valid.

The regression test added in this commit abuses of a failed concurrent
index creation, marked as invalid, that maps with an index created on
its partitioned table afterwards.

Reported-by: Alexander Lakhin
Reviewed-by: Alexander Lakhin
Discussion: https://postgr.es/m/14987634-43c0-0cb3-e075-94d423607e08@gmail.com
Backpatch-through: 11

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/cfc43aeb3810ebaa8dbda4807046a4c953d9e992

Modified Files
--------------
src/backend/commands/indexcmds.c | 31 +++++++++++++++++++++++-------
src/test/regress/expected/indexing.out | 35 ++++++++++++++++++++++++++++++++++
src/test/regress/sql/indexing.sql | 26 +++++++++++++++++++++++++
3 files changed, 85 insertions(+), 7 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Nathan Bossart 2023-06-30 05:09:21 Re: pgsql: Fix search_path to a safe value during maintenance operations.
Previous Message Michael Paquier 2023-06-30 01:29:33 pgsql: Add tab completion for CREATE SCHEMA in psql