diff options
author | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2024-05-13 11:31:09 +0200 |
---|---|---|
committer | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2024-05-13 11:31:09 +0200 |
commit | 6f8bb7c1e9610dd7af20cdaf74c4ff6e6d678d44 (patch) | |
tree | d490c49cc914cc625dbbf8d17e1975dabb15e7e5 /src/backend/utils/cache/relcache.c | |
parent | e89f4c66182e409b6643b1e8426371011dc25217 (diff) | |
download | postgresql-6f8bb7c1e9610dd7af20cdaf74c4ff6e6d678d44.tar.gz postgresql-6f8bb7c1e9610dd7af20cdaf74c4ff6e6d678d44.zip |
Revert structural changes to not-null constraints
There are some problems with the new way to handle these constraints
that were detected at the last minute, and require fixes that appear too
invasive to be doing this late in the cycle. Revert this (again) for
now, we'll try again with these problems fixed.
The following commits are reverted:
b0e96f311985 Catalog not-null constraints
9b581c534186 Disallow changing NO INHERIT status of a not-null constraint
d0ec2ddbe088 Fix not-null constraint test
ac22a9545ca9 Move privilege check to the right place
b0f7dd915bca Check stack depth in new recursive functions
3af721794272 Update information_schema definition for not-null constraints
c3709100be73 Fix propagating attnotnull in multiple inheritance
d9f686a72ee9 Fix restore of not-null constraints with inheritance
d72d32f52d26 Don't try to assign smart names to constraints
0cd711271d42 Better handle indirect constraint drops
13daa33fa5a6 Disallow NO INHERIT not-null constraints on partitioned tables
d45597f72fe5 Disallow direct change of NO INHERIT of not-null constraints
21ac38f498b3 Fix inconsistencies in error messages
Discussion: https://postgr.es/m/202405110940.joxlqcx4dogd@alvherre.pgsql
Diffstat (limited to 'src/backend/utils/cache/relcache.c')
-rw-r--r-- | src/backend/utils/cache/relcache.c | 42 |
1 files changed, 7 insertions, 35 deletions
diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 262c9878dd3..e6072cbdd9e 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -4810,46 +4810,18 @@ RelationGetIndexList(Relation relation) result = lappend_oid(result, index->indexrelid); /* - * Non-unique or predicate indexes aren't interesting for either oid - * indexes or replication identity indexes, so don't check them. - * Deferred ones are not useful for replication identity either; but - * we do include them if they are PKs. + * Invalid, non-unique, non-immediate or predicate indexes aren't + * interesting for either oid indexes or replication identity indexes, + * so don't check them. */ - if (!index->indisunique || + if (!index->indisvalid || !index->indisunique || + !index->indimmediate || !heap_attisnull(htup, Anum_pg_index_indpred, NULL)) continue; - /* - * Remember primary key index, if any. We do this only if the index - * is valid; but if the table is partitioned, then we do it even if - * it's invalid. - * - * The reason for returning invalid primary keys for foreign tables is - * because of pg_dump of NOT NULL constraints, and the fact that PKs - * remain marked invalid until the partitions' PKs are attached to it. - * If we make rd_pkindex invalid, then the attnotnull flag is reset - * after the PK is created, which causes the ALTER INDEX ATTACH - * PARTITION to fail with 'column ... is not marked NOT NULL'. With - * this, dropconstraint_internal() will believe that the columns must - * not have attnotnull reset, so the PKs-on-partitions can be attached - * correctly, until finally the PK-on-parent is marked valid. - * - * Also, this doesn't harm anything, because rd_pkindex is not a - * "real" index anyway, but a RELKIND_PARTITIONED_INDEX. - */ - if (index->indisprimary && - (index->indisvalid || - relation->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)) - { + /* remember primary key index if any */ + if (index->indisprimary) pkeyIndex = index->indexrelid; - pkdeferrable = !index->indimmediate; - } - - if (!index->indimmediate) - continue; - - if (!index->indisvalid) - continue; /* remember explicitly chosen replica index */ if (index->indisreplident) |