Code review and documentation updates for indisclustered patch.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 3 Sep 2002 01:04:41 +0000 (01:04 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 3 Sep 2002 01:04:41 +0000 (01:04 +0000)
doc/src/sgml/catalogs.sgml
src/backend/catalog/index.c
src/backend/commands/cluster.c
src/include/catalog/pg_index.h

index 73d0da7e72fc480d0fa855bc6e2dcb58b0017e02..a8fd81e19c948bf285e9ae82d1d5135264c04785 100644 (file)
@@ -1,6 +1,6 @@
 <!--
  Documentation of the system catalogs, directed toward PostgreSQL developers
- $Header: /cvsroot/pgsql/doc/src/sgml/catalogs.sgml,v 2.58 2002/09/02 05:52:34 momjian Exp $
+ $Header: /cvsroot/pgsql/doc/src/sgml/catalogs.sgml,v 2.59 2002/09/03 01:04:40 tgl Exp $
  -->
 
 <chapter id="catalogs">
       <entry>indisclustered</entry>
       <entry><type>bool</type></entry>
       <entry></entry>
-      <entry>unused</entry>
+      <entry>If true, the table was last clustered on this index.</entry>
      </row>
 
      <row>
index 93939a978e5e67fe4c68057d61c8011ccaa9703a..489d1c607ea7025e1b94e62b31e24ac3803a3f3a 100644 (file)
@@ -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);
index ab0110a3f4fc098e7e1ea98dc2ddae840e269bb9..d49aa0b678f1c2723057822541c8b439ffe07dda 100644 (file)
@@ -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;
index 88dbd98e5570bf5cf5002b31ba93235c761f2774..092487b7c9971dce5125fb162f1c867177485813 100644 (file)
@@ -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