From 95d8fb7c2288765d044cfa95b0ccbebd955ecb19 Mon Sep 17 00:00:00 2001 From: "dgrowley@gmail.com" Date: Thu, 2 Aug 2018 16:06:10 +1200 Subject: [PATCH v1 3/4] Don't store partition index details in pg_inherits --- src/backend/catalog/index.c | 4 - src/backend/commands/indexcmds.c | 163 ++++++++------------------- src/backend/commands/tablecmds.c | 152 ++++++++++++------------- src/bin/pg_dump/pg_dump.c | 36 +++++- src/test/regress/expected/indexing.out | 195 ++++++++++++++++----------------- src/test/regress/sql/indexing.sql | 69 ++++++------ 6 files changed, 288 insertions(+), 331 deletions(-) diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index eda850edef..26683d8960 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -978,10 +978,6 @@ index_create(Relation heapRelation, !concurrent && !invalid, !concurrent); - /* update pg_inherits, if needed */ - if (OidIsValid(parentIndexRelid)) - StoreSingleInheritance(indexRelationId, parentIndexRelid, 1); - /* * Register constraint and dependencies for the index. * diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index b9dad9672e..10aa1b1f84 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -924,11 +924,15 @@ DefineIndex(Oid relationId, Relation cldidx; IndexInfo *cldIdxInfo; - /* this index is already partition of another one */ - if (has_superclass(cldidxid)) + cldidx = index_open(cldidxid, lockmode); + + /* Don't try to use any indexes which are already parented */ + if (OidIsValid(RelationGetParentRelid(cldidx))) + { + index_close(cldidx, lockmode); continue; + } - cldidx = index_open(cldidxid, lockmode); cldIdxInfo = BuildIndexInfo(cldidx); if (CompareIndexInfo(cldIdxInfo, indexInfo, cldidx->rd_indcollation, @@ -2478,142 +2482,71 @@ ReindexPartitionedIndex(Relation parentIdx) } /* - * Insert or delete an appropriate pg_inherits tuple to make the given index - * be a partition of the indicated parent index. + * IndexSetParentIndex + * Update pg_class record to mark or unmark the parent of 'partitionIdx'. * * This also corrects the pg_depend information for the affected index. */ void IndexSetParentIndex(Relation partitionIdx, Oid parentOid) { - Relation pg_inherits; - ScanKeyData key[2]; - SysScanDesc scan; Oid partRelid = RelationGetRelid(partitionIdx); + Relation classRel; HeapTuple tuple; - bool fix_dependencies; + ObjectAddress partIdx; /* Make sure this is an index */ Assert(partitionIdx->rd_rel->relkind == RELKIND_INDEX || partitionIdx->rd_rel->relkind == RELKIND_PARTITIONED_INDEX); + /* Update pg_class tuple */ + classRel = heap_open(RelationRelationId, RowExclusiveLock); + tuple = SearchSysCacheCopy1(RELOID, ObjectIdGetDatum(partRelid)); + if (!HeapTupleIsValid(tuple)) + elog(ERROR, "cache lookup failed for relation %u", partRelid); + /* - * Scan pg_inherits for rows linking our index to some parent. + * Sanity check that we're not trying to overwrite another parent, or + * trying to unset it when it's not set. */ - pg_inherits = relation_open(InheritsRelationId, RowExclusiveLock); - ScanKeyInit(&key[0], - Anum_pg_inherits_inhrelid, - BTEqualStrategyNumber, F_OIDEQ, - ObjectIdGetDatum(partRelid)); - ScanKeyInit(&key[1], - Anum_pg_inherits_inhseqno, - BTEqualStrategyNumber, F_INT4EQ, - Int32GetDatum(1)); - scan = systable_beginscan(pg_inherits, InheritsRelidSeqnoIndexId, true, - NULL, 2, key); - tuple = systable_getnext(scan); + Assert(OidIsValid(((Form_pg_class) GETSTRUCT(tuple))->relpartitionparent) + != OidIsValid(parentOid)); - if (!HeapTupleIsValid(tuple)) - { - if (parentOid == InvalidOid) - { - /* - * No pg_inherits row, and no parent wanted: nothing to do in this - * case. - */ - fix_dependencies = false; - } - else - { - Datum values[Natts_pg_inherits]; - bool isnull[Natts_pg_inherits]; + /* Set the relpartitionparent */ + ((Form_pg_class) GETSTRUCT(tuple))->relpartitionparent = parentOid; + CatalogTupleUpdate(classRel, &tuple->t_self, tuple); + heap_freetuple(tuple); + heap_close(classRel, RowExclusiveLock); - /* - * No pg_inherits row exists, and we want a parent for this index, - * so insert it. - */ - values[Anum_pg_inherits_inhrelid - 1] = ObjectIdGetDatum(partRelid); - values[Anum_pg_inherits_inhparent - 1] = - ObjectIdGetDatum(parentOid); - values[Anum_pg_inherits_inhseqno - 1] = Int32GetDatum(1); - memset(isnull, false, sizeof(isnull)); - - tuple = heap_form_tuple(RelationGetDescr(pg_inherits), - values, isnull); - CatalogTupleInsert(pg_inherits, tuple); + /* + * Insert/delete pg_depend rows. If setting a parent, add an + * INTERNAL_AUTO dependency to the parent index; if making standalone, + * remove all existing rows and put back the regular dependency on the + * table. + */ + ObjectAddressSet(partIdx, RelationRelationId, partRelid); - fix_dependencies = true; - } - } - else + if (OidIsValid(parentOid)) { - Form_pg_inherits inhForm = (Form_pg_inherits) GETSTRUCT(tuple); + ObjectAddress parentIdx; - if (parentOid == InvalidOid) - { - /* - * There exists a pg_inherits row, which we want to clear; do so. - */ - CatalogTupleDelete(pg_inherits, &tuple->t_self); - fix_dependencies = true; - } - else - { - /* - * A pg_inherits row exists. If it's the same we want, then we're - * good; if it differs, that amounts to a corrupt catalog and - * should not happen. - */ - if (inhForm->inhparent != parentOid) - { - /* unexpected: we should not get called in this case */ - elog(ERROR, "bogus pg_inherit row: inhrelid %u inhparent %u", - inhForm->inhrelid, inhForm->inhparent); - } - - /* already in the right state */ - fix_dependencies = false; - } + ObjectAddressSet(parentIdx, RelationRelationId, parentOid); + recordDependencyOn(&partIdx, &parentIdx, DEPENDENCY_INTERNAL_AUTO); } - - /* done with pg_inherits */ - systable_endscan(scan); - relation_close(pg_inherits, RowExclusiveLock); - - if (fix_dependencies) + else { - ObjectAddress partIdx; + ObjectAddress partitionTbl; - /* - * Insert/delete pg_depend rows. If setting a parent, add an - * INTERNAL_AUTO dependency to the parent index; if making standalone, - * remove all existing rows and put back the regular dependency on the - * table. - */ - ObjectAddressSet(partIdx, RelationRelationId, partRelid); + ObjectAddressSet(partitionTbl, RelationRelationId, + partitionIdx->rd_index->indrelid); - if (OidIsValid(parentOid)) - { - ObjectAddress parentIdx; + deleteDependencyRecordsForClass(RelationRelationId, partRelid, + RelationRelationId, + DEPENDENCY_INTERNAL_AUTO); - ObjectAddressSet(parentIdx, RelationRelationId, parentOid); - recordDependencyOn(&partIdx, &parentIdx, DEPENDENCY_INTERNAL_AUTO); - } - else - { - ObjectAddress partitionTbl; - - ObjectAddressSet(partitionTbl, RelationRelationId, - partitionIdx->rd_index->indrelid); - - deleteDependencyRecordsForClass(RelationRelationId, partRelid, - RelationRelationId, - DEPENDENCY_INTERNAL_AUTO); - - recordDependencyOn(&partIdx, &partitionTbl, DEPENDENCY_AUTO); - } - - /* make our updates visible */ - CommandCounterIncrement(); + recordDependencyOn(&partIdx, &partitionTbl, DEPENDENCY_AUTO); } + + /* make our updates visible */ + CommandCounterIncrement(); } diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 8a0fcd7ece..e01ca8211a 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -14906,15 +14906,18 @@ ATExecDetachPartition(Relation rel, RangeVar *name) Oid idxid = lfirst_oid(cell); Relation idx; - if (!has_superclass(idxid)) - continue; - - Assert((IndexGetRelation(get_partition_parent(idxid), false) == - RelationGetRelid(rel))); idx = index_open(idxid, AccessExclusiveLock); - IndexSetParentIndex(idx, InvalidOid); - update_relpartitionparent(pgclass, idxid, InvalidOid); + + if (OidIsValid(RelationGetParentRelid(idx))) + { + Assert((IndexGetRelation(RelationGetParentRelid(idx), false) == + RelationGetRelid(rel))); + + IndexSetParentIndex(idx, InvalidOid); + update_relpartitionparent(pgclass, idxid, InvalidOid); + } + relation_close(idx, AccessExclusiveLock); } heap_close(pgclass, RowExclusiveLock); @@ -15149,6 +15152,7 @@ ATExecAttachPartitionIdx(List **wqueue, Relation parentIdx, RangeVar *name) if (OidIsValid(constraintOid)) ConstraintSetParentConstraint(cldConstrId, constraintOid); update_relpartitionparent(NULL, partIdxId, RelationGetRelid(parentIdx)); + CommandCounterIncrement(); pfree(attmap); @@ -15170,25 +15174,16 @@ ATExecAttachPartitionIdx(List **wqueue, Relation parentIdx, RangeVar *name) static void refuseDupeIndexAttach(Relation parentIdx, Relation partIdx, Relation partitionTbl) { - Relation pg_inherits; - ScanKeyData key; - HeapTuple tuple; - SysScanDesc scan; + List *indexoids; + ListCell *lc; - pg_inherits = heap_open(InheritsRelationId, AccessShareLock); - ScanKeyInit(&key, Anum_pg_inherits_inhparent, - BTEqualStrategyNumber, F_OIDEQ, - ObjectIdGetDatum(RelationGetRelid(parentIdx))); - scan = systable_beginscan(pg_inherits, InheritsParentIndexId, true, - NULL, 1, &key); - while (HeapTupleIsValid(tuple = systable_getnext(scan))) + indexoids = RelationGetIndexList(partitionTbl); + + foreach(lc, indexoids) { - Form_pg_inherits inhForm; - Oid tab; + Oid idxOid = lfirst_oid(lc); - inhForm = (Form_pg_inherits) GETSTRUCT(tuple); - tab = IndexGetRelation(inhForm->inhrelid, false); - if (tab == RelationGetRelid(partitionTbl)) + if (get_partition_parent(idxOid) == RelationGetRelid(parentIdx)) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("cannot attach index \"%s\" as a partition of index \"%s\"", @@ -15197,9 +15192,6 @@ refuseDupeIndexAttach(Relation parentIdx, Relation partIdx, Relation partitionTb errdetail("Another index is already attached for partition \"%s\".", RelationGetRelationName(partitionTbl)))); } - - systable_endscan(scan); - heap_close(pg_inherits, AccessShareLock); } /* @@ -15211,72 +15203,82 @@ refuseDupeIndexAttach(Relation parentIdx, Relation partIdx, Relation partitionTb static void validatePartitionedIndex(Relation partedIdx, Relation partedTbl) { - Relation inheritsRel; - SysScanDesc scan; - ScanKeyData key; - int tuples = 0; - HeapTuple inhTup; - bool updated = false; + PartitionDesc partdesc; + int i; + int nparts; + Oid partedidxoid = RelationGetRelid(partedIdx); + Relation idxRel; + HeapTuple newtup; Assert(partedIdx->rd_rel->relkind == RELKIND_PARTITIONED_INDEX); - /* - * Scan pg_inherits for this parent index. Count each valid index we find - * (verifying the pg_index entry for each), and if we reach the total - * amount we expect, we can mark this parent index as valid. - */ - inheritsRel = heap_open(InheritsRelationId, AccessShareLock); - ScanKeyInit(&key, Anum_pg_inherits_inhparent, - BTEqualStrategyNumber, F_OIDEQ, - ObjectIdGetDatum(RelationGetRelid(partedIdx))); - scan = systable_beginscan(inheritsRel, InheritsParentIndexId, true, - NULL, 1, &key); - while ((inhTup = systable_getnext(scan)) != NULL) - { - Form_pg_inherits inhForm = (Form_pg_inherits) GETSTRUCT(inhTup); - HeapTuple indTup; - Form_pg_index indexForm; - - indTup = SearchSysCache1(INDEXRELID, - ObjectIdGetDatum(inhForm->inhrelid)); - if (!indTup) - elog(ERROR, "cache lookup failed for index %u", - inhForm->inhrelid); - indexForm = (Form_pg_index) GETSTRUCT(indTup); - if (IndexIsValid(indexForm)) - tuples += 1; - ReleaseSysCache(indTup); - } - - /* Done with pg_inherits */ - systable_endscan(scan); - heap_close(inheritsRel, AccessShareLock); + partdesc = RelationGetPartitionDesc(partedTbl); + nparts = partdesc->nparts; /* - * If we found as many inherited indexes as the partitioned table has - * partitions, we're good; update pg_index to set indisvalid. + * Check if all partitions have an index defined for this partitioned index. + * If they all have one then we can mark the partitioned index as valid. */ - if (tuples == RelationGetPartitionDesc(partedTbl)->nparts) + for (i = 0; i < nparts; i++) { - Relation idxRel; - HeapTuple newtup; + Relation part = relation_open(partdesc->oids[i], AccessShareLock); + List *indexoids = RelationGetIndexList(part); + ListCell *lc; + bool found = false; + + foreach(lc, indexoids) + { + Oid indexoid = lfirst_oid(lc); + HeapTuple tup; + Form_pg_class classForm; + Form_pg_index indexForm; + + tup = SearchSysCache1(RELOID, ObjectIdGetDatum(indexoid)); + if (!HeapTupleIsValid(tup)) + elog(ERROR, "cache lookup failed for relation %u", indexoid); + classForm = (Form_pg_class) GETSTRUCT(tup); + if (classForm->relpartitionparent != partedidxoid) + { + ReleaseSysCache(tup); + continue; + } + ReleaseSysCache(tup); + - idxRel = heap_open(IndexRelationId, RowExclusiveLock); + tup = SearchSysCache1(INDEXRELID, ObjectIdGetDatum(indexoid)); + if (!HeapTupleIsValid(tup)) + elog(ERROR, "cache lookup failed for index %u", indexoid); + indexForm = (Form_pg_index) GETSTRUCT(tup); - newtup = heap_copytuple(partedIdx->rd_indextuple); - ((Form_pg_index) GETSTRUCT(newtup))->indisvalid = true; - updated = true; + if (IndexIsValid(indexForm)) + found = true; - CatalogTupleUpdate(idxRel, &partedIdx->rd_indextuple->t_self, newtup); + ReleaseSysCache(tup); + break; + } - heap_close(idxRel, RowExclusiveLock); + relation_close(part, AccessShareLock); + + /* If the index was not found then we can't mark the index as valid */ + if (!found) + return; } + /* We're good; update pg_index to set indisvalid. */ + idxRel = heap_open(IndexRelationId, RowExclusiveLock); + + newtup = heap_copytuple(partedIdx->rd_indextuple); + ((Form_pg_index) GETSTRUCT(newtup))->indisvalid = true; + + CatalogTupleUpdate(idxRel, &partedIdx->rd_indextuple->t_self, newtup); + + heap_close(idxRel, RowExclusiveLock); + /* * If this index is in turn a partition of a larger index, validating it * might cause the parent to become valid also. Try that. */ - if (updated && OidIsValid(RelationGetParentRelid(partedIdx))) + if (OidIsValid(RelationGetParentRelid(partedIdx))) { Oid parentIdxId, parentTblId; diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index af7e2bd813..b616515157 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -384,7 +384,7 @@ main(int argc, char **argv) }; set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_dump")); - + pg_usleep(15000000); /* * Initialize what we need for parallel execution, especially for thread * support on Windows. @@ -6808,7 +6808,39 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables) * is not. */ resetPQExpBuffer(query); - if (fout->remoteVersion >= 110000) + + if (fout->remoteVersion >= 120000) + { + appendPQExpBuffer(query, + "SELECT t.tableoid, t.oid, " + "t.relname AS indexname, " + "t.relpartitionparent AS parentidx, " + "pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, " + "i.indnkeyatts AS indnkeyatts, " + "i.indnatts AS indnatts, " + "i.indkey, i.indisclustered, " + "i.indisreplident, t.relpages, " + "c.contype, c.conname, " + "c.condeferrable, c.condeferred, " + "c.tableoid AS contableoid, " + "c.oid AS conoid, " + "pg_catalog.pg_get_constraintdef(c.oid, false) AS condef, " + "(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, " + "t.reloptions AS indreloptions " + "FROM pg_catalog.pg_index i " + "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) " + "JOIN pg_catalog.pg_class t2 ON (t2.oid = i.indrelid) " + "LEFT JOIN pg_catalog.pg_constraint c " + "ON (i.indrelid = c.conrelid AND " + "i.indexrelid = c.conindid AND " + "c.contype IN ('p','u','x')) " + "WHERE i.indrelid = '%u'::pg_catalog.oid " + "AND (i.indisvalid OR t2.relkind = 'p') " + "AND i.indisready " + "ORDER BY indexname", + tbinfo->dobj.catId.oid); + } + else if (fout->remoteVersion >= 110000) { appendPQExpBuffer(query, "SELECT t.tableoid, t.oid, " diff --git a/src/test/regress/expected/indexing.out b/src/test/regress/expected/indexing.out index b9297c98d2..77ce91e847 100644 --- a/src/test/regress/expected/indexing.out +++ b/src/test/regress/expected/indexing.out @@ -6,20 +6,19 @@ create table idxpart2 partition of idxpart for values from (10) to (100) partition by range (b); create table idxpart21 partition of idxpart2 for values from (0) to (100); create index on idxpart (a); -select relname, relkind, inhparent::regclass - from pg_class left join pg_index ix on (indexrelid = oid) - left join pg_inherits on (ix.indexrelid = inhrelid) +select relname, relkind, relpartitionparent::regclass + from pg_class where relname like 'idxpart%' order by relname; - relname | relkind | inhparent ------------------+---------+---------------- - idxpart | p | - idxpart1 | r | + relname | relkind | relpartitionparent +-----------------+---------+-------------------- + idxpart | p | - + idxpart1 | r | idxpart idxpart1_a_idx | i | idxpart_a_idx - idxpart2 | p | - idxpart21 | r | + idxpart2 | p | idxpart + idxpart21 | r | idxpart2 idxpart21_a_idx | i | idxpart2_a_idx idxpart2_a_idx | I | idxpart_a_idx - idxpart_a_idx | I | + idxpart_a_idx | I | - (8 rows) drop table idxpart; @@ -91,16 +90,15 @@ Partition of: idxpart FOR VALUES FROM (0, 0) TO (10, 10) Indexes: "idxpart1_a_b_idx" btree (a, b) -select relname, relkind, inhparent::regclass - from pg_class left join pg_index ix on (indexrelid = oid) - left join pg_inherits on (ix.indexrelid = inhrelid) +select relname, relkind, relpartitionparent::regclass + from pg_class where relname like 'idxpart%' order by relname; - relname | relkind | inhparent -------------------+---------+----------------- - idxpart | p | - idxpart1 | r | + relname | relkind | relpartitionparent +------------------+---------+-------------------- + idxpart | p | - + idxpart1 | r | idxpart idxpart1_a_b_idx | i | idxpart_a_b_idx - idxpart_a_b_idx | I | + idxpart_a_b_idx | I | - (4 rows) drop table idxpart; @@ -238,29 +236,29 @@ Number of partitions: 2 (Use \d+ to list them.) a | integer | | | Partition of: idxpart2 FOR VALUES FROM (100) TO (200) -select indexrelid::regclass, indrelid::regclass, inhparent::regclass - from pg_index idx left join pg_inherits inh on (idx.indexrelid = inh.inhrelid) +select indexrelid::regclass, indrelid::regclass, relpartitionparent::regclass + from pg_index idx left join pg_class c on (idx.indexrelid = c.oid) where indexrelid::regclass::text like 'idxpart%' order by indexrelid::regclass::text collate "C"; - indexrelid | indrelid | inhparent ------------------+-----------+--------------- + indexrelid | indrelid | relpartitionparent +-----------------+-----------+-------------------- idxpart1_a_idx | idxpart1 | idxpart_a_idx - idxpart22_a_idx | idxpart22 | + idxpart22_a_idx | idxpart22 | - idxpart2_a_idx | idxpart2 | idxpart_a_idx - idxpart_a_idx | idxpart | + idxpart_a_idx | idxpart | - (4 rows) alter index idxpart2_a_idx attach partition idxpart22_a_idx; -select indexrelid::regclass, indrelid::regclass, inhparent::regclass - from pg_index idx left join pg_inherits inh on (idx.indexrelid = inh.inhrelid) +select indexrelid::regclass, indrelid::regclass, relpartitionparent::regclass + from pg_index idx left join pg_class c on (idx.indexrelid = c.oid) where indexrelid::regclass::text like 'idxpart%' order by indexrelid::regclass::text collate "C"; - indexrelid | indrelid | inhparent ------------------+-----------+---------------- + indexrelid | indrelid | relpartitionparent +-----------------+-----------+-------------------- idxpart1_a_idx | idxpart1 | idxpart_a_idx idxpart22_a_idx | idxpart22 | idxpart2_a_idx idxpart2_a_idx | idxpart2 | idxpart_a_idx - idxpart_a_idx | idxpart | + idxpart_a_idx | idxpart | - (4 rows) -- attaching idxpart22 is not enough to set idxpart22_a_idx valid ... @@ -309,18 +307,17 @@ Indexes: "idxpart1_a_idx" btree (a) "idxpart1_b_c_idx" btree (b, c) -select relname, relkind, inhparent::regclass - from pg_class left join pg_index ix on (indexrelid = oid) - left join pg_inherits on (ix.indexrelid = inhrelid) +select relname, relkind, relpartitionparent::regclass + from pg_class where relname like 'idxpart%' order by relname; - relname | relkind | inhparent -------------------+---------+----------- - idxpart | p | - idxpart1 | r | - idxpart1_a_idx | i | - idxpart1_b_c_idx | i | - idxparti | I | - idxparti2 | I | + relname | relkind | relpartitionparent +------------------+---------+-------------------- + idxpart | p | - + idxpart1 | r | - + idxpart1_a_idx | i | - + idxpart1_b_c_idx | i | - + idxparti | I | - + idxparti2 | I | - (6 rows) alter table idxpart attach partition idxpart1 for values from (0) to (10); @@ -336,18 +333,17 @@ Indexes: "idxpart1_a_idx" btree (a) "idxpart1_b_c_idx" btree (b, c) -select relname, relkind, inhparent::regclass - from pg_class left join pg_index ix on (indexrelid = oid) - left join pg_inherits on (ix.indexrelid = inhrelid) +select relname, relkind, relpartitionparent::regclass + from pg_class where relname like 'idxpart%' order by relname; - relname | relkind | inhparent -------------------+---------+----------- - idxpart | p | - idxpart1 | r | + relname | relkind | relpartitionparent +------------------+---------+-------------------- + idxpart | p | - + idxpart1 | r | idxpart idxpart1_a_idx | i | idxparti idxpart1_b_c_idx | i | idxparti2 - idxparti | I | - idxparti2 | I | + idxparti | I | - + idxparti2 | I | - (6 rows) drop table idxpart; @@ -482,7 +478,7 @@ select relname, relkind from pg_class where relname like 'idxpart%' order by rel ---------+--------- (0 rows) --- Verify that expression indexes inherit correctly +-- Verify that expression indexes have their parents set correctly create table idxpart (a int, b int) partition by range (a); create table idxpart1 (like idxpart); create index on idxpart1 ((a + b)); @@ -491,10 +487,11 @@ create table idxpart2 (like idxpart); alter table idxpart attach partition idxpart1 for values from (0000) to (1000); alter table idxpart attach partition idxpart2 for values from (1000) to (2000); create table idxpart3 partition of idxpart for values from (2000) to (3000); -select relname as child, inhparent::regclass as parent, pg_get_indexdef as childdef - from pg_class join pg_inherits on inhrelid = oid, +select relname as child, relpartitionparent::regclass as parent, pg_get_indexdef as childdef + from pg_class, lateral pg_get_indexdef(pg_class.oid) - where relkind in ('i', 'I') and relname like 'idxpart%' order by relname; + where relpartitionparent <> 0 and relkind in ('i', 'I') and relname like 'idxpart%' + order by relname; child | parent | childdef -------------------+------------------+--------------------------------------------------------------------------- idxpart1_expr_idx | idxpart_expr_idx | CREATE INDEX idxpart1_expr_idx ON public.idxpart1 USING btree (((a + b))) @@ -515,19 +512,19 @@ alter table idxpart attach partition idxpart2 for values from ('bbb') to ('ccc') create table idxpart3 partition of idxpart for values from ('ccc') to ('ddd'); create index on idxpart (a collate "C"); create table idxpart4 partition of idxpart for values from ('ddd') to ('eee'); -select relname as child, inhparent::regclass as parent, pg_get_indexdef as childdef - from pg_class left join pg_inherits on inhrelid = oid, +select relname as child, relpartitionparent::regclass as parent, pg_get_indexdef as childdef + from pg_class, lateral pg_get_indexdef(pg_class.oid) where relkind in ('i', 'I') and relname like 'idxpart%' order by relname; child | parent | childdef -----------------+---------------+-------------------------------------------------------------------------------- idxpart1_a_idx | idxpart_a_idx | CREATE INDEX idxpart1_a_idx ON public.idxpart1 USING btree (a COLLATE "C") - idxpart2_a_idx | | CREATE INDEX idxpart2_a_idx ON public.idxpart2 USING btree (a COLLATE "POSIX") - idxpart2_a_idx1 | | CREATE INDEX idxpart2_a_idx1 ON public.idxpart2 USING btree (a) + idxpart2_a_idx | - | CREATE INDEX idxpart2_a_idx ON public.idxpart2 USING btree (a COLLATE "POSIX") + idxpart2_a_idx1 | - | CREATE INDEX idxpart2_a_idx1 ON public.idxpart2 USING btree (a) idxpart2_a_idx2 | idxpart_a_idx | CREATE INDEX idxpart2_a_idx2 ON public.idxpart2 USING btree (a COLLATE "C") idxpart3_a_idx | idxpart_a_idx | CREATE INDEX idxpart3_a_idx ON public.idxpart3 USING btree (a COLLATE "C") idxpart4_a_idx | idxpart_a_idx | CREATE INDEX idxpart4_a_idx ON public.idxpart4 USING btree (a COLLATE "C") - idxpart_a_idx | | CREATE INDEX idxpart_a_idx ON ONLY public.idxpart USING btree (a COLLATE "C") + idxpart_a_idx | - | CREATE INDEX idxpart_a_idx ON ONLY public.idxpart USING btree (a COLLATE "C") (7 rows) drop table idxpart; @@ -542,18 +539,18 @@ create table idxpart3 partition of idxpart for values from ('ccc') to ('ddd'); create index on idxpart (a text_pattern_ops); create table idxpart4 partition of idxpart for values from ('ddd') to ('eee'); -- must *not* have attached the index we created on idxpart2 -select relname as child, inhparent::regclass as parent, pg_get_indexdef as childdef - from pg_class left join pg_inherits on inhrelid = oid, +select relname as child, relpartitionparent::regclass as parent, pg_get_indexdef as childdef + from pg_class, lateral pg_get_indexdef(pg_class.oid) where relkind in ('i', 'I') and relname like 'idxpart%' order by relname; child | parent | childdef -----------------+---------------+------------------------------------------------------------------------------------ idxpart1_a_idx | idxpart_a_idx | CREATE INDEX idxpart1_a_idx ON public.idxpart1 USING btree (a text_pattern_ops) - idxpart2_a_idx | | CREATE INDEX idxpart2_a_idx ON public.idxpart2 USING btree (a) + idxpart2_a_idx | - | CREATE INDEX idxpart2_a_idx ON public.idxpart2 USING btree (a) idxpart2_a_idx1 | idxpart_a_idx | CREATE INDEX idxpart2_a_idx1 ON public.idxpart2 USING btree (a text_pattern_ops) idxpart3_a_idx | idxpart_a_idx | CREATE INDEX idxpart3_a_idx ON public.idxpart3 USING btree (a text_pattern_ops) idxpart4_a_idx | idxpart_a_idx | CREATE INDEX idxpart4_a_idx ON public.idxpart4 USING btree (a text_pattern_ops) - idxpart_a_idx | | CREATE INDEX idxpart_a_idx ON ONLY public.idxpart USING btree (a text_pattern_ops) + idxpart_a_idx | - | CREATE INDEX idxpart_a_idx ON ONLY public.idxpart USING btree (a text_pattern_ops) (6 rows) drop index idxpart_a_idx; @@ -588,19 +585,19 @@ alter index idxpart_2_idx attach partition idxpart1_2c_idx; -- fail ERROR: cannot attach index "idxpart1_2c_idx" as a partition of index "idxpart_2_idx" DETAIL: The index definitions do not match. alter index idxpart_2_idx attach partition idxpart1_2_idx; -- ok -select relname as child, inhparent::regclass as parent, pg_get_indexdef as childdef - from pg_class left join pg_inherits on inhrelid = oid, +select relname as child, relpartitionparent::regclass as parent, pg_get_indexdef as childdef + from pg_class, lateral pg_get_indexdef(pg_class.oid) where relkind in ('i', 'I') and relname like 'idxpart%' order by relname; child | parent | childdef -----------------+---------------+----------------------------------------------------------------------------------------- idxpart1_1_idx | idxpart_1_idx | CREATE INDEX idxpart1_1_idx ON public.idxpart1 USING btree (b, a) - idxpart1_1b_idx | | CREATE INDEX idxpart1_1b_idx ON public.idxpart1 USING btree (b) + idxpart1_1b_idx | - | CREATE INDEX idxpart1_1b_idx ON public.idxpart1 USING btree (b) idxpart1_2_idx | idxpart_2_idx | CREATE INDEX idxpart1_2_idx ON public.idxpart1 USING btree (((b + a))) WHERE (a > 1) - idxpart1_2b_idx | | CREATE INDEX idxpart1_2b_idx ON public.idxpart1 USING btree (((a + b))) WHERE (a > 1) - idxpart1_2c_idx | | CREATE INDEX idxpart1_2c_idx ON public.idxpart1 USING btree (((b + a))) WHERE (b > 1) - idxpart_1_idx | | CREATE INDEX idxpart_1_idx ON ONLY public.idxpart USING btree (b, a) - idxpart_2_idx | | CREATE INDEX idxpart_2_idx ON ONLY public.idxpart USING btree (((b + a))) WHERE (a > 1) + idxpart1_2b_idx | - | CREATE INDEX idxpart1_2b_idx ON public.idxpart1 USING btree (((a + b))) WHERE (a > 1) + idxpart1_2c_idx | - | CREATE INDEX idxpart1_2c_idx ON public.idxpart1 USING btree (((b + a))) WHERE (b > 1) + idxpart_1_idx | - | CREATE INDEX idxpart_1_idx ON ONLY public.idxpart USING btree (b, a) + idxpart_2_idx | - | CREATE INDEX idxpart_2_idx ON ONLY public.idxpart USING btree (((b + a))) WHERE (a > 1) (7 rows) drop table idxpart; @@ -929,17 +926,17 @@ create table idxpart0 partition of idxpart (i) for values with (modulus 2, remai create table idxpart1 partition of idxpart (i) for values with (modulus 2, remainder 1); alter table idxpart0 add primary key(i); alter table idxpart add primary key(i); -select indrelid::regclass, indexrelid::regclass, inhparent::regclass, indisvalid, +select indrelid::regclass, indexrelid::regclass, relpartitionparent::regclass, indisvalid, conname, conislocal, coninhcount, connoinherit, convalidated - from pg_index idx left join pg_inherits inh on (idx.indexrelid = inh.inhrelid) + from pg_index idx left join pg_class c on (idx.indexrelid = c.oid) left join pg_constraint con on (idx.indexrelid = con.conindid) where indrelid::regclass::text like 'idxpart%' order by indexrelid::regclass::text collate "C"; - indrelid | indexrelid | inhparent | indisvalid | conname | conislocal | coninhcount | connoinherit | convalidated -----------+---------------+--------------+------------+---------------+------------+-------------+--------------+-------------- - idxpart0 | idxpart0_pkey | idxpart_pkey | t | idxpart0_pkey | f | 1 | t | t - idxpart1 | idxpart1_pkey | idxpart_pkey | t | idxpart1_pkey | f | 1 | f | t - idxpart | idxpart_pkey | | t | idxpart_pkey | t | 0 | t | t + indrelid | indexrelid | relpartitionparent | indisvalid | conname | conislocal | coninhcount | connoinherit | convalidated +----------+---------------+--------------------+------------+---------------+------------+-------------+--------------+-------------- + idxpart0 | idxpart0_pkey | idxpart_pkey | t | idxpart0_pkey | f | 1 | t | t + idxpart1 | idxpart1_pkey | idxpart_pkey | t | idxpart1_pkey | f | 1 | f | t + idxpart | idxpart_pkey | - | t | idxpart_pkey | t | 0 | t | t (3 rows) drop index idxpart0_pkey; -- fail @@ -953,14 +950,14 @@ ERROR: cannot drop inherited constraint "idxpart0_pkey" of relation "idxpart0" alter table idxpart1 drop constraint idxpart1_pkey; -- fail ERROR: cannot drop inherited constraint "idxpart1_pkey" of relation "idxpart1" alter table idxpart drop constraint idxpart_pkey; -- ok -select indrelid::regclass, indexrelid::regclass, inhparent::regclass, indisvalid, +select indrelid::regclass, indexrelid::regclass, relpartitionparent::regclass, indisvalid, conname, conislocal, coninhcount, connoinherit, convalidated - from pg_index idx left join pg_inherits inh on (idx.indexrelid = inh.inhrelid) + from pg_index idx left join pg_class c on (idx.indexrelid = c.oid) left join pg_constraint con on (idx.indexrelid = con.conindid) where indrelid::regclass::text like 'idxpart%' order by indexrelid::regclass::text collate "C"; - indrelid | indexrelid | inhparent | indisvalid | conname | conislocal | coninhcount | connoinherit | convalidated -----------+------------+-----------+------------+---------+------------+-------------+--------------+-------------- + indrelid | indexrelid | relpartitionparent | indisvalid | conname | conislocal | coninhcount | connoinherit | convalidated +----------+------------+--------------------+------------+---------+------------+-------------+--------------+-------------- (0 rows) drop table idxpart; @@ -987,29 +984,29 @@ create table idxpart0 (like idxpart); alter table idxpart0 add primary key (a); alter table idxpart attach partition idxpart0 for values from (0) to (1000); alter table only idxpart add primary key (a); -select indrelid::regclass, indexrelid::regclass, inhparent::regclass, indisvalid, +select indrelid::regclass, indexrelid::regclass, relpartitionparent::regclass, indisvalid, conname, conislocal, coninhcount, connoinherit, convalidated - from pg_index idx left join pg_inherits inh on (idx.indexrelid = inh.inhrelid) + from pg_index idx left join pg_class c on (idx.indexrelid = c.oid) left join pg_constraint con on (idx.indexrelid = con.conindid) where indrelid::regclass::text like 'idxpart%' order by indexrelid::regclass::text collate "C"; - indrelid | indexrelid | inhparent | indisvalid | conname | conislocal | coninhcount | connoinherit | convalidated -----------+---------------+-----------+------------+---------------+------------+-------------+--------------+-------------- - idxpart0 | idxpart0_pkey | | t | idxpart0_pkey | t | 0 | t | t - idxpart | idxpart_pkey | | f | idxpart_pkey | t | 0 | t | t + indrelid | indexrelid | relpartitionparent | indisvalid | conname | conislocal | coninhcount | connoinherit | convalidated +----------+---------------+--------------------+------------+---------------+------------+-------------+--------------+-------------- + idxpart0 | idxpart0_pkey | - | t | idxpart0_pkey | t | 0 | t | t + idxpart | idxpart_pkey | - | f | idxpart_pkey | t | 0 | t | t (2 rows) alter index idxpart_pkey attach partition idxpart0_pkey; -select indrelid::regclass, indexrelid::regclass, inhparent::regclass, indisvalid, +select indrelid::regclass, indexrelid::regclass, relpartitionparent::regclass, indisvalid, conname, conislocal, coninhcount, connoinherit, convalidated - from pg_index idx left join pg_inherits inh on (idx.indexrelid = inh.inhrelid) + from pg_index idx left join pg_class c on (idx.indexrelid = c.oid) left join pg_constraint con on (idx.indexrelid = con.conindid) where indrelid::regclass::text like 'idxpart%' order by indexrelid::regclass::text collate "C"; - indrelid | indexrelid | inhparent | indisvalid | conname | conislocal | coninhcount | connoinherit | convalidated -----------+---------------+--------------+------------+---------------+------------+-------------+--------------+-------------- - idxpart0 | idxpart0_pkey | idxpart_pkey | t | idxpart0_pkey | f | 1 | t | t - idxpart | idxpart_pkey | | t | idxpart_pkey | t | 0 | t | t + indrelid | indexrelid | relpartitionparent | indisvalid | conname | conislocal | coninhcount | connoinherit | convalidated +----------+---------------+--------------------+------------+---------------+------------+-------------+--------------+-------------- + idxpart0 | idxpart0_pkey | idxpart_pkey | t | idxpart0_pkey | f | 1 | t | t + idxpart | idxpart_pkey | - | t | idxpart_pkey | t | 0 | t | t (2 rows) drop table idxpart; @@ -1020,17 +1017,17 @@ create table idxpart1 (a int not null, b int); create unique index on idxpart1 (a); alter table idxpart add primary key (a); alter table idxpart attach partition idxpart1 for values from (1) to (1000); -select indrelid::regclass, indexrelid::regclass, inhparent::regclass, indisvalid, +select indrelid::regclass, indexrelid::regclass, relpartitionparent::regclass, indisvalid, conname, conislocal, coninhcount, connoinherit, convalidated - from pg_index idx left join pg_inherits inh on (idx.indexrelid = inh.inhrelid) + from pg_index idx left join pg_class c on (idx.indexrelid = c.oid) left join pg_constraint con on (idx.indexrelid = con.conindid) where indrelid::regclass::text like 'idxpart%' order by indexrelid::regclass::text collate "C"; - indrelid | indexrelid | inhparent | indisvalid | conname | conislocal | coninhcount | connoinherit | convalidated -----------+----------------+--------------+------------+---------------+------------+-------------+--------------+-------------- - idxpart1 | idxpart1_a_idx | | t | | | | | - idxpart1 | idxpart1_pkey | idxpart_pkey | t | idxpart1_pkey | f | 1 | f | t - idxpart | idxpart_pkey | | t | idxpart_pkey | t | 0 | t | t + indrelid | indexrelid | relpartitionparent | indisvalid | conname | conislocal | coninhcount | connoinherit | convalidated +----------+----------------+--------------------+------------+---------------+------------+-------------+--------------+-------------- + idxpart1 | idxpart1_a_idx | - | t | | | | | + idxpart1 | idxpart1_pkey | idxpart_pkey | t | idxpart1_pkey | f | 1 | f | t + idxpart | idxpart_pkey | - | t | idxpart_pkey | t | 0 | t | t (3 rows) drop table idxpart; diff --git a/src/test/regress/sql/indexing.sql b/src/test/regress/sql/indexing.sql index 2091a87ff5..efc5a63d6b 100644 --- a/src/test/regress/sql/indexing.sql +++ b/src/test/regress/sql/indexing.sql @@ -6,9 +6,8 @@ create table idxpart2 partition of idxpart for values from (10) to (100) partition by range (b); create table idxpart21 partition of idxpart2 for values from (0) to (100); create index on idxpart (a); -select relname, relkind, inhparent::regclass - from pg_class left join pg_index ix on (indexrelid = oid) - left join pg_inherits on (ix.indexrelid = inhrelid) +select relname, relkind, relpartitionparent::regclass + from pg_class where relname like 'idxpart%' order by relname; drop table idxpart; @@ -52,9 +51,8 @@ create table idxpart1 partition of idxpart for values from (0, 0) to (10, 10); create index on idxpart1 (a, b); create index on idxpart (a, b); \d idxpart1 -select relname, relkind, inhparent::regclass - from pg_class left join pg_index ix on (indexrelid = oid) - left join pg_inherits on (ix.indexrelid = inhrelid) +select relname, relkind, relpartitionparent::regclass + from pg_class where relname like 'idxpart%' order by relname; drop table idxpart; @@ -129,13 +127,13 @@ create index on idxpart (a); \d idxpart1 \d idxpart2 \d idxpart21 -select indexrelid::regclass, indrelid::regclass, inhparent::regclass - from pg_index idx left join pg_inherits inh on (idx.indexrelid = inh.inhrelid) +select indexrelid::regclass, indrelid::regclass, relpartitionparent::regclass + from pg_index idx left join pg_class c on (idx.indexrelid = c.oid) where indexrelid::regclass::text like 'idxpart%' order by indexrelid::regclass::text collate "C"; alter index idxpart2_a_idx attach partition idxpart22_a_idx; -select indexrelid::regclass, indrelid::regclass, inhparent::regclass - from pg_index idx left join pg_inherits inh on (idx.indexrelid = inh.inhrelid) +select indexrelid::regclass, indrelid::regclass, relpartitionparent::regclass + from pg_index idx left join pg_class c on (idx.indexrelid = c.oid) where indexrelid::regclass::text like 'idxpart%' order by indexrelid::regclass::text collate "C"; -- attaching idxpart22 is not enough to set idxpart22_a_idx valid ... @@ -155,15 +153,13 @@ create index idxparti on idxpart (a); create index idxparti2 on idxpart (b, c); create table idxpart1 (like idxpart including indexes); \d idxpart1 -select relname, relkind, inhparent::regclass - from pg_class left join pg_index ix on (indexrelid = oid) - left join pg_inherits on (ix.indexrelid = inhrelid) +select relname, relkind, relpartitionparent::regclass + from pg_class where relname like 'idxpart%' order by relname; alter table idxpart attach partition idxpart1 for values from (0) to (10); \d idxpart1 -select relname, relkind, inhparent::regclass - from pg_class left join pg_index ix on (indexrelid = oid) - left join pg_inherits on (ix.indexrelid = inhrelid) +select relname, relkind, relpartitionparent::regclass + from pg_class where relname like 'idxpart%' order by relname; drop table idxpart; @@ -230,7 +226,7 @@ select relname, relkind from pg_class where relname like 'idxpart%' order by rel drop table idxpart, idxpart1, idxpart2, idxpart3; select relname, relkind from pg_class where relname like 'idxpart%' order by relname; --- Verify that expression indexes inherit correctly +-- Verify that expression indexes have their parents set correctly create table idxpart (a int, b int) partition by range (a); create table idxpart1 (like idxpart); create index on idxpart1 ((a + b)); @@ -239,10 +235,11 @@ create table idxpart2 (like idxpart); alter table idxpart attach partition idxpart1 for values from (0000) to (1000); alter table idxpart attach partition idxpart2 for values from (1000) to (2000); create table idxpart3 partition of idxpart for values from (2000) to (3000); -select relname as child, inhparent::regclass as parent, pg_get_indexdef as childdef - from pg_class join pg_inherits on inhrelid = oid, +select relname as child, relpartitionparent::regclass as parent, pg_get_indexdef as childdef + from pg_class, lateral pg_get_indexdef(pg_class.oid) - where relkind in ('i', 'I') and relname like 'idxpart%' order by relname; + where relpartitionparent <> 0 and relkind in ('i', 'I') and relname like 'idxpart%' + order by relname; drop table idxpart; -- Verify behavior for collation (mis)matches @@ -257,8 +254,8 @@ alter table idxpart attach partition idxpart2 for values from ('bbb') to ('ccc') create table idxpart3 partition of idxpart for values from ('ccc') to ('ddd'); create index on idxpart (a collate "C"); create table idxpart4 partition of idxpart for values from ('ddd') to ('eee'); -select relname as child, inhparent::regclass as parent, pg_get_indexdef as childdef - from pg_class left join pg_inherits on inhrelid = oid, +select relname as child, relpartitionparent::regclass as parent, pg_get_indexdef as childdef + from pg_class, lateral pg_get_indexdef(pg_class.oid) where relkind in ('i', 'I') and relname like 'idxpart%' order by relname; drop table idxpart; @@ -274,8 +271,8 @@ create table idxpart3 partition of idxpart for values from ('ccc') to ('ddd'); create index on idxpart (a text_pattern_ops); create table idxpart4 partition of idxpart for values from ('ddd') to ('eee'); -- must *not* have attached the index we created on idxpart2 -select relname as child, inhparent::regclass as parent, pg_get_indexdef as childdef - from pg_class left join pg_inherits on inhrelid = oid, +select relname as child, relpartitionparent::regclass as parent, pg_get_indexdef as childdef + from pg_class, lateral pg_get_indexdef(pg_class.oid) where relkind in ('i', 'I') and relname like 'idxpart%' order by relname; drop index idxpart_a_idx; @@ -303,8 +300,8 @@ alter index idxpart_1_idx attach partition idxpart1_1_idx; alter index idxpart_2_idx attach partition idxpart1_2b_idx; -- fail alter index idxpart_2_idx attach partition idxpart1_2c_idx; -- fail alter index idxpart_2_idx attach partition idxpart1_2_idx; -- ok -select relname as child, inhparent::regclass as parent, pg_get_indexdef as childdef - from pg_class left join pg_inherits on inhrelid = oid, +select relname as child, relpartitionparent::regclass as parent, pg_get_indexdef as childdef + from pg_class, lateral pg_get_indexdef(pg_class.oid) where relkind in ('i', 'I') and relname like 'idxpart%' order by relname; drop table idxpart; @@ -485,9 +482,9 @@ create table idxpart0 partition of idxpart (i) for values with (modulus 2, remai create table idxpart1 partition of idxpart (i) for values with (modulus 2, remainder 1); alter table idxpart0 add primary key(i); alter table idxpart add primary key(i); -select indrelid::regclass, indexrelid::regclass, inhparent::regclass, indisvalid, +select indrelid::regclass, indexrelid::regclass, relpartitionparent::regclass, indisvalid, conname, conislocal, coninhcount, connoinherit, convalidated - from pg_index idx left join pg_inherits inh on (idx.indexrelid = inh.inhrelid) + from pg_index idx left join pg_class c on (idx.indexrelid = c.oid) left join pg_constraint con on (idx.indexrelid = con.conindid) where indrelid::regclass::text like 'idxpart%' order by indexrelid::regclass::text collate "C"; @@ -496,9 +493,9 @@ drop index idxpart1_pkey; -- fail alter table idxpart0 drop constraint idxpart0_pkey; -- fail alter table idxpart1 drop constraint idxpart1_pkey; -- fail alter table idxpart drop constraint idxpart_pkey; -- ok -select indrelid::regclass, indexrelid::regclass, inhparent::regclass, indisvalid, +select indrelid::regclass, indexrelid::regclass, relpartitionparent::regclass, indisvalid, conname, conislocal, coninhcount, connoinherit, convalidated - from pg_index idx left join pg_inherits inh on (idx.indexrelid = inh.inhrelid) + from pg_index idx left join pg_class c on (idx.indexrelid = c.oid) left join pg_constraint con on (idx.indexrelid = con.conindid) where indrelid::regclass::text like 'idxpart%' order by indexrelid::regclass::text collate "C"; @@ -527,16 +524,16 @@ create table idxpart0 (like idxpart); alter table idxpart0 add primary key (a); alter table idxpart attach partition idxpart0 for values from (0) to (1000); alter table only idxpart add primary key (a); -select indrelid::regclass, indexrelid::regclass, inhparent::regclass, indisvalid, +select indrelid::regclass, indexrelid::regclass, relpartitionparent::regclass, indisvalid, conname, conislocal, coninhcount, connoinherit, convalidated - from pg_index idx left join pg_inherits inh on (idx.indexrelid = inh.inhrelid) + from pg_index idx left join pg_class c on (idx.indexrelid = c.oid) left join pg_constraint con on (idx.indexrelid = con.conindid) where indrelid::regclass::text like 'idxpart%' order by indexrelid::regclass::text collate "C"; alter index idxpart_pkey attach partition idxpart0_pkey; -select indrelid::regclass, indexrelid::regclass, inhparent::regclass, indisvalid, +select indrelid::regclass, indexrelid::regclass, relpartitionparent::regclass, indisvalid, conname, conislocal, coninhcount, connoinherit, convalidated - from pg_index idx left join pg_inherits inh on (idx.indexrelid = inh.inhrelid) + from pg_index idx left join pg_class c on (idx.indexrelid = c.oid) left join pg_constraint con on (idx.indexrelid = con.conindid) where indrelid::regclass::text like 'idxpart%' order by indexrelid::regclass::text collate "C"; @@ -549,9 +546,9 @@ create table idxpart1 (a int not null, b int); create unique index on idxpart1 (a); alter table idxpart add primary key (a); alter table idxpart attach partition idxpart1 for values from (1) to (1000); -select indrelid::regclass, indexrelid::regclass, inhparent::regclass, indisvalid, +select indrelid::regclass, indexrelid::regclass, relpartitionparent::regclass, indisvalid, conname, conislocal, coninhcount, connoinherit, convalidated - from pg_index idx left join pg_inherits inh on (idx.indexrelid = inh.inhrelid) + from pg_index idx left join pg_class c on (idx.indexrelid = c.oid) left join pg_constraint con on (idx.indexrelid = con.conindid) where indrelid::regclass::text like 'idxpart%' order by indexrelid::regclass::text collate "C"; -- 2.16.2.windows.1