]> granicus.if.org Git - postgresql/commitdiff
The following patch finishes primary key support. Previously, when
authorBruce Momjian <bruce@momjian.us>
Thu, 21 Jan 1999 22:48:20 +0000 (22:48 +0000)
committerBruce Momjian <bruce@momjian.us>
Thu, 21 Jan 1999 22:48:20 +0000 (22:48 +0000)
a field was labelled as a primary key, the system automatically
created a unique index on the field.  This patch extends it so
that the index has the indisprimary field set.  You can pull a list
of primary keys with the followiing select.

SELECT pg_class.relname, pg_attribute.attname
    FROM pg_class, pg_attribute, pg_index
    WHERE pg_class.oid = pg_attribute.attrelid AND
        pg_class.oid = pg_index.indrelid AND
        pg_index.indkey[0] = pg_attribute.attnum AND
        pg_index.indisunique = 't';

There is nothing in this patch that modifies the template database to
set the indisprimary attribute for system tables.  Should they be
changed or should we only be concerned with user tables?

D'Arcy

src/backend/bootstrap/bootparse.y
src/backend/catalog/index.c
src/backend/commands/cluster.c
src/backend/commands/defind.c
src/backend/parser/analyze.c
src/backend/storage/large_object/inv_api.c
src/backend/tcop/utility.c
src/include/catalog/index.h
src/include/commands/defrem.h
src/include/nodes/parsenodes.h

index 162ca00e78dd02c5fd226f18dff332b28067572e..5a2a6e09fd42d5cdb283fd79704590e1e5124287 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/bootstrap/bootparse.y,v 1.21 1998/08/24 01:13:36 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/bootstrap/bootparse.y,v 1.22 1999/01/21 22:48:04 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -225,7 +225,7 @@ Boot_DeclareIndexStmt:
                                        DefineIndex(LexIDStr($5),
                                                                LexIDStr($3),
                                                                LexIDStr($7),
-                                                               $9, NIL, 0, 0, NIL);
+                                                               $9, NIL, 0, 0, 0, NIL);
                                        DO_END;
                                }
                ;
index 29565ba285e51572ca862a9071df30009cb025fa..ce9d7343c84ecbcdc075941219b15153fe877fee 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.66 1998/12/15 12:45:43 vadim Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.67 1999/01/21 22:48:05 momjian Exp $
  *
  *
  * INTERFACE ROUTINES
@@ -82,7 +82,7 @@ static void
 static void UpdateIndexRelation(Oid indexoid, Oid heapoid,
                                        FuncIndexInfo *funcInfo, int natts,
                                        AttrNumber *attNums, Oid *classOids, Node *predicate,
-                                       List *attributeList, bool islossy, bool unique);
+                                       List *attributeList, bool islossy, bool unique, bool primary);
 static void DefaultBuild(Relation heapRelation, Relation indexRelation,
                         int numberOfAttributes, AttrNumber *attributeNumber,
                         IndexStrategy indexStrategy, uint16 parameterCount,
@@ -734,7 +734,8 @@ UpdateIndexRelation(Oid indexoid,
                                        Node *predicate,
                                        List *attributeList,
                                        bool islossy,
-                                       bool unique)
+                                       bool unique,
+                    bool primary)
 {
        Form_pg_index indexForm;
        IndexElem  *IndexKey;
@@ -775,6 +776,7 @@ UpdateIndexRelation(Oid indexoid,
        indexForm->indproc = (PointerIsValid(funcInfo)) ?
                FIgetProcOid(funcInfo) : InvalidOid;
        indexForm->indislossy = islossy;
+       indexForm->indisprimary = primary;
        indexForm->indisunique = unique;
 
        indexForm->indhaskeytype = 0;
@@ -1014,7 +1016,8 @@ index_create(char *heapRelationName,
                         Datum *parameter,
                         Node *predicate,
                         bool islossy,
-                        bool unique)
+                        bool unique,
+             bool primary)
 {
        Relation        heapRelation;
        Relation        indexRelation;
@@ -1126,7 +1129,7 @@ index_create(char *heapRelationName,
         */
        UpdateIndexRelation(indexoid, heapoid, funcInfo,
                                                numatts, attNums, classObjectId, predicate,
-                                               attributeList, islossy, unique);
+                                               attributeList, islossy, unique, primary);
 
        predInfo = (PredInfo *) palloc(sizeof(PredInfo));
        predInfo->pred = predicate;
index 9d9324e8ff5b44198c2eb7be6eef85523fd3f612..a8103912063e141b68efb236e907a1c76f634de2 100644 (file)
@@ -14,7 +14,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.34 1998/12/14 05:18:39 scrappy Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.35 1999/01/21 22:48:06 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -321,7 +321,8 @@ copy_index(Oid OIDOldIndex, Oid OIDNewHeap)
                                 Old_pg_index_Form->indclass,
                                 (uint16) 0, (Datum) NULL, NULL,
                                 Old_pg_index_Form->indislossy,
-                                Old_pg_index_Form->indisunique);
+                                Old_pg_index_Form->indisunique,
+                 Old_pg_index_Form->indisprimary);
 
        heap_close(OldIndex);
        heap_close(NewHeap);
index 33d069e6517fa8968c6a4e92da6a73cff5598dbc..692e1782368c47b8bf4d2766626a61dbd448742f 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/commands/Attic/defind.c,v 1.29 1998/12/15 12:45:56 vadim Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/commands/Attic/defind.c,v 1.30 1999/01/21 22:48:06 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -71,6 +71,7 @@ DefineIndex(char *heapRelationName,
                        List *attributeList,
                        List *parameterList,
                        bool unique,
+                       bool primary,
                        Expr *predicate,
                        List *rangetable)
 {
@@ -189,7 +190,7 @@ DefineIndex(char *heapRelationName,
                                         &fInfo, NULL, accessMethodId,
                                         numberOfAttributes, attributeNumberA,
                         classObjectId, parameterCount, parameterA, (Node *) cnfPred,
-                                        lossy, unique);
+                                        lossy, unique, primary);
        }
        else
        {
@@ -206,7 +207,7 @@ DefineIndex(char *heapRelationName,
                                         attributeList,
                                         accessMethodId, numberOfAttributes, attributeNumberA,
                         classObjectId, parameterCount, parameterA, (Node *) cnfPred,
-                                        lossy, unique);
+                                        lossy, unique, primary);
        }
 }
 
index af94800d2ed8c39057ba0bf0e56ed48ca3c0fbdb..9f61e83b35dd6f90eeedda606b34801fdbeb43fd 100644 (file)
@@ -5,7 +5,7 @@
  *
  * Copyright (c) 1994, Regents of the University of California
  *
- *  $Id: analyze.c,v 1.93 1999/01/21 16:08:38 vadim Exp $
+ *  $Id: analyze.c,v 1.94 1999/01/21 22:48:07 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -721,10 +721,14 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt)
                                elog(ERROR, "CREATE TABLE/PRIMARY KEY multiple keys for table %s are not legal", stmt->relname);
 
                        have_pkey = TRUE;
+                       index->primary = TRUE;
                        index->idxname = makeTableName(stmt->relname, "pkey", NULL);
                }
                else
+               {
+                       index->primary = FALSE;
                        index->idxname = NULL;
+               }
 
                index->relname = stmt->relname;
                index->accessMethod = "btree";
index 404604041972b8826b60a6880014cb0ba05ecc6e..255b05c7c159626a59d43d7c7a0b9c137c81fb25 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/storage/large_object/inv_api.c,v 1.44 1998/12/15 12:46:26 vadim Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/storage/large_object/inv_api.c,v 1.45 1999/01/21 22:48:09 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -178,7 +178,7 @@ inv_create(int flags)
        classObjectId[0] = INT4_OPS_OID;
        index_create(objname, indname, NULL, NULL, BTREE_AM_OID,
                                 1, &attNums[0], &classObjectId[0],
-                                0, (Datum) NULL, NULL, FALSE, FALSE);
+                                0, (Datum) NULL, NULL, FALSE, FALSE, FALSE);
 
        /* make the index visible in this transaction */
        CommandCounterIncrement();
index 7d9e11ba5bd5ba83ae4bd5bb21f60e32b293f750..22f915c5920c9a53f85962a7ee52f42c4e0e57f2 100644 (file)
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.52 1999/01/17 06:18:44 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.53 1999/01/21 22:48:11 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -404,6 +404,7 @@ ProcessUtility(Node *parsetree,
                                                        stmt->indexParams,      /* parameters */
                                                        stmt->withClause,
                                                        stmt->unique,
+                                                       0,              /* CREATE INDEX can't be primary */
                                                        (Expr *) stmt->whereClause,
                                                        stmt->rangetable);
                        }
index d377832241b6b5cf80bf6a897b9b1eb8d03ea875..b08d72e7d17fb4d6d39748910a40e1304fb5353a 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Copyright (c) 1994, Regents of the University of California
  *
- * $Id: index.h,v 1.13 1998/09/01 04:34:43 momjian Exp $
+ * $Id: index.h,v 1.14 1999/01/21 22:48:14 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -38,7 +38,8 @@ extern void index_create(char *heapRelationName,
                         Datum *parameter,
                         Node *predicate,
                         bool islossy,
-                        bool unique);
+                        bool unique,
+             bool primary);
 
 extern void index_destroy(Oid indexId);
 
index 37b287d9fac108859bda5d0639af378f8829099e..f5867bd3fa44134f558ad909bda87e9d2649efa3 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Copyright (c) 1994, Regents of the University of California
  *
- * $Id: defrem.h,v 1.13 1998/09/01 04:35:30 momjian Exp $
+ * $Id: defrem.h,v 1.14 1999/01/21 22:48:16 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -25,6 +25,7 @@ extern void DefineIndex(char *heapRelationName,
                        List *attributeList,
                        List *parameterList,
                        bool unique,
+                       bool primary,
                        Expr *predicate,
                        List *rangetable);
 extern void ExtendIndex(char *indexRelationName,
index 0e6c8e5068bc49a3fa1f64da4544c86a0ff5ad21..32fd65c69ee9874cb27d9ec664546cf4def96a53 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Copyright (c) 1994, Regents of the University of California
  *
- * $Id: parsenodes.h,v 1.67 1999/01/21 16:08:55 vadim Exp $
+ * $Id: parsenodes.h,v 1.68 1999/01/21 22:48:20 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -333,6 +333,7 @@ typedef struct IndexStmt
                                                                 * transformStmt() */
        bool       *lossy;                      /* is index lossy? */
        bool            unique;                 /* is index unique? */
+       bool            primary;                /* is index on primary key? */
 } IndexStmt;
 
 /* ----------------------