From: Tom Lane Date: Tue, 3 Sep 2002 01:04:41 +0000 (+0000) Subject: Code review and documentation updates for indisclustered patch. X-Git-Tag: REL7_3~606 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ab82bde7e08e2b763b14b48aeb62daf0b2c09ce3;p=postgresql Code review and documentation updates for indisclustered patch. --- diff --git a/doc/src/sgml/catalogs.sgml b/doc/src/sgml/catalogs.sgml index 73d0da7e72..a8fd81e19c 100644 --- a/doc/src/sgml/catalogs.sgml +++ b/doc/src/sgml/catalogs.sgml @@ -1,6 +1,6 @@ @@ -1865,7 +1865,7 @@ indisclustered bool - unused + If true, the table was last clustered on this index. diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 93939a978e..489d1c607e 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.193 2002/09/02 01:05:04 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.194 2002/09/03 01:04:41 tgl Exp $ * * * INTERFACE ROUTINES @@ -453,7 +453,7 @@ UpdateIndexRelation(Oid indexoid, indexForm->indexrelid = indexoid; indexForm->indrelid = heapoid; indexForm->indproc = indexInfo->ii_FuncOid; - indexForm->indisclustered = false; /* not used */ + indexForm->indisclustered = false; /* not clustered, yet */ indexForm->indisunique = indexInfo->ii_Unique; indexForm->indisprimary = primary; memcpy((char *) &indexForm->indpred, (char *) predText, predLen); diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index ab0110a3f4..d49aa0b678 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -11,7 +11,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.88 2002/09/02 01:05:04 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.89 2002/09/03 01:04:41 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -304,12 +304,7 @@ get_indexattr_list(Relation OldHeap, Oid OldIndex) palloc(sizeof(Oid) * attrs->indexInfo->ii_NumIndexAttrs); memcpy(attrs->classOID, indexForm->indclass, sizeof(Oid) * attrs->indexInfo->ii_NumIndexAttrs); - - /* We'll set indisclustered at index creation time on the - * index we are currently clustering, and reset it on other - * indexes. - */ - attrs->isclustered = (OldIndex == indexOID ? true : false); + attrs->isclustered = (OldIndex == indexOID); /* Name and access method of each index come from pg_class */ classTuple = SearchSysCache(RELOID, @@ -373,19 +368,25 @@ recreate_indexattr(Oid OIDOldHeap, List *indexes) CommandCounterIncrement(); - /* Set indisclustered to the correct value. Only one index is - * allowed to be clustered. + /* + * Make sure that indisclustered is correct: it should be set + * only for the index we just clustered on. */ pg_index = heap_openr(IndexRelationName, RowExclusiveLock); tuple = SearchSysCacheCopy(INDEXRELID, - ObjectIdGetDatum(attrs->indexOID), - 0, 0, 0); + ObjectIdGetDatum(attrs->indexOID), + 0, 0, 0); + if (!HeapTupleIsValid(tuple)) + elog(ERROR, "cache lookup failed for index %u", attrs->indexOID); index = (Form_pg_index) GETSTRUCT(tuple); - index->indisclustered = attrs->isclustered; - simple_heap_update(pg_index, &tuple->t_self, tuple); - CatalogUpdateIndexes(pg_index, tuple); + if (index->indisclustered != attrs->isclustered) + { + index->indisclustered = attrs->isclustered; + simple_heap_update(pg_index, &tuple->t_self, tuple); + CatalogUpdateIndexes(pg_index, tuple); + } heap_freetuple(tuple); - heap_close(pg_index, NoLock); + heap_close(pg_index, RowExclusiveLock); /* Destroy new index with old filenode */ object.classId = RelOid_pg_class; diff --git a/src/include/catalog/pg_index.h b/src/include/catalog/pg_index.h index 88dbd98e55..092487b7c9 100644 --- a/src/include/catalog/pg_index.h +++ b/src/include/catalog/pg_index.h @@ -8,7 +8,7 @@ * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $Id: pg_index.h,v 1.28 2002/06/20 20:29:44 momjian Exp $ + * $Id: pg_index.h,v 1.29 2002/09/03 01:04:41 tgl Exp $ * * NOTES * the genbki.sh script reads this file and generates .bki @@ -38,7 +38,7 @@ CATALOG(pg_index) BKI_WITHOUT_OIDS regproc indproc; /* OID of function for functional index */ int2vector indkey; /* column numbers of indexed attributes */ oidvector indclass; /* opclass identifiers */ - bool indisclustered; /* presently unused */ + bool indisclustered; /* is this the index last clustered by? */ bool indisunique; /* is this a unique index? */ bool indisprimary; /* is this index for primary key? */ Oid indreference; /* oid of index of referenced relation (ie