]> granicus.if.org Git - postgresql/commitdiff
Remove pg_class.relhaspkey
authorPeter Eisentraut <peter_e@gmx.net>
Wed, 14 Mar 2018 18:59:40 +0000 (14:59 -0400)
committerPeter Eisentraut <peter_e@gmx.net>
Wed, 14 Mar 2018 19:31:34 +0000 (15:31 -0400)
It is not used for anything internally, and it cannot be relied on for
external uses, so it can just be removed.  To correct recommended way to
check for a primary key is in pg_index.

Discussion: https://www.postgresql.org/message-id/flat/b1a24c6c-6913-f89c-674e-0704f0ed69db@2ndquadrant.com

doc/src/sgml/catalogs.sgml
src/backend/catalog/heap.c
src/backend/catalog/index.c
src/backend/commands/vacuum.c
src/backend/rewrite/rewriteDefine.c
src/include/catalog/catversion.h
src/include/catalog/pg_class.h

index a0e6d7062b045dea21303b49686ed5ed5d2bee3e..30e674130504e7846a66bc508ff55f02fe279d12 100644 (file)
@@ -1848,15 +1848,6 @@ SCRAM-SHA-256$<replaceable>&lt;iteration count&gt;</replaceable>:<replaceable>&l
       </entry>
      </row>
 
-     <row>
-      <entry><structfield>relhaspkey</structfield></entry>
-      <entry><type>bool</type></entry>
-      <entry></entry>
-      <entry>
-       True if the table has (or once had) a primary key
-      </entry>
-     </row>
-
      <row>
       <entry><structfield>relhasrules</structfield></entry>
       <entry><type>bool</type></entry>
index cf36ce4add7907f76f7bf50bcce9bfb91e0f0af0..3d80ff9e5bb01fd462a9bc7f5e26b0d602b3384f 100644 (file)
@@ -798,7 +798,6 @@ InsertPgClassTuple(Relation pg_class_desc,
        values[Anum_pg_class_relnatts - 1] = Int16GetDatum(rd_rel->relnatts);
        values[Anum_pg_class_relchecks - 1] = Int16GetDatum(rd_rel->relchecks);
        values[Anum_pg_class_relhasoids - 1] = BoolGetDatum(rd_rel->relhasoids);
-       values[Anum_pg_class_relhaspkey - 1] = BoolGetDatum(rd_rel->relhaspkey);
        values[Anum_pg_class_relhasrules - 1] = BoolGetDatum(rd_rel->relhasrules);
        values[Anum_pg_class_relhastriggers - 1] = BoolGetDatum(rd_rel->relhastriggers);
        values[Anum_pg_class_relrowsecurity - 1] = BoolGetDatum(rd_rel->relrowsecurity);
index 431bc3196999371252fcdcbf3f9848461e71bb8a..9e2dd0e729edbcff18b534a79a4226d602abf481 100644 (file)
@@ -125,7 +125,7 @@ static void UpdateIndexRelation(Oid indexoid, Oid heapoid,
                                        bool isvalid,
                                        bool isready);
 static void index_update_stats(Relation rel,
-                                  bool hasindex, bool isprimary,
+                                  bool hasindex,
                                   double reltuples);
 static void IndexCheckExclusion(Relation heapRelation,
                                        Relation indexRelation,
@@ -1162,7 +1162,6 @@ index_create(Relation heapRelation,
                 */
                index_update_stats(heapRelation,
                                                   true,
-                                                  isprimary,
                                                   -1.0);
                /* Make the above update visible */
                CommandCounterIncrement();
@@ -1364,21 +1363,6 @@ index_constraint_create(Relation heapRelation,
                                                         InvalidOid, conOid, indexRelationId, true);
        }
 
-       /*
-        * If needed, mark the table as having a primary key.  We assume it can't
-        * have been so marked already, so no need to clear the flag in the other
-        * case.
-        *
-        * Note: this might better be done by callers.  We do it here to avoid
-        * exposing index_update_stats() globally, but that wouldn't be necessary
-        * if relhaspkey went away.
-        */
-       if (mark_as_primary)
-               index_update_stats(heapRelation,
-                                                  true,
-                                                  true,
-                                                  -1.0);
-
        /*
         * If needed, mark the index as primary and/or deferred in pg_index.
         *
@@ -2041,7 +2025,6 @@ FormIndexDatum(IndexInfo *indexInfo,
  * to ensure we can do all the necessary work in just one update.
  *
  * hasindex: set relhasindex to this value
- * isprimary: if true, set relhaspkey true; else no change
  * reltuples: if >= 0, set reltuples to this value; else no change
  *
  * If reltuples >= 0, relpages and relallvisible are also updated (using
@@ -2058,7 +2041,6 @@ FormIndexDatum(IndexInfo *indexInfo,
 static void
 index_update_stats(Relation rel,
                                   bool hasindex,
-                                  bool isprimary,
                                   double reltuples)
 {
        Oid                     relid = RelationGetRelid(rel);
@@ -2088,7 +2070,7 @@ index_update_stats(Relation rel,
         * It is safe to use a non-transactional update even though our
         * transaction could still fail before committing.  Setting relhasindex
         * true is safe even if there are no indexes (VACUUM will eventually fix
-        * it), likewise for relhaspkey.  And of course the new relpages and
+        * it).  And of course the new relpages and
         * reltuples counts are correct regardless.  However, we don't want to
         * change relpages (or relallvisible) if the caller isn't providing an
         * updated reltuples count, because that would bollix the
@@ -2140,14 +2122,6 @@ index_update_stats(Relation rel,
                rd_rel->relhasindex = hasindex;
                dirty = true;
        }
-       if (isprimary)
-       {
-               if (!rd_rel->relhaspkey)
-               {
-                       rd_rel->relhaspkey = true;
-                       dirty = true;
-               }
-       }
 
        if (reltuples >= 0)
        {
@@ -2356,11 +2330,9 @@ index_build(Relation heapRelation,
         */
        index_update_stats(heapRelation,
                                           true,
-                                          isprimary,
                                           stats->heap_tuples);
 
        index_update_stats(indexRelation,
-                                          false,
                                           false,
                                           stats->index_tuples);
 
index b50c554c517677b9076a4e28fb7d67ff5d98f6c9..18b3966a1f7d4a024d9966705b412d79ab5f9b92 100644 (file)
@@ -909,16 +909,6 @@ vac_update_relstats(Relation relation,
                        dirty = true;
                }
 
-               /*
-                * If we have discovered that there are no indexes, then there's no
-                * primary key either.  This could be done more thoroughly...
-                */
-               if (pgcform->relhaspkey && !hasindex)
-               {
-                       pgcform->relhaspkey = false;
-                       dirty = true;
-               }
-
                /* We also clear relhasrules and relhastriggers if needed */
                if (pgcform->relhasrules && relation->rd_rules == NULL)
                {
index f3a9b639a802a2bbb4b20c9f4b89faf185166139..679be605f14bf25b34e0b877093db0743ba6404a 100644 (file)
@@ -618,7 +618,6 @@ DefineQueryRewrite(const char *rulename,
                classForm->relhasindex = false;
                classForm->relkind = RELKIND_VIEW;
                classForm->relhasoids = false;
-               classForm->relhaspkey = false;
                classForm->relfrozenxid = InvalidTransactionId;
                classForm->relminmxid = InvalidMultiXactId;
                classForm->relreplident = REPLICA_IDENTITY_NOTHING;
index 79e5af537d59fdc46cf35c113e5ca56c139e2317..96d3406abe09be62a9225a4c8ef3db260dea0e22 100644 (file)
@@ -53,6 +53,6 @@
  */
 
 /*                                                     yyyymmddN */
-#define CATALOG_VERSION_NO     201803021
+#define CATALOG_VERSION_NO     201803141
 
 #endif
index 01cf59e7a3ae312bd1ad786cdbfa6df77c133a82..7fc355acb893813ce16c01ab401bd054857f1571 100644 (file)
@@ -61,7 +61,6 @@ CATALOG(pg_class,1259) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83) BKI_SCHEMA_MACRO
         */
        int16           relchecks;              /* # of CHECK constraints for class */
        bool            relhasoids;             /* T if we generate OIDs for rows of rel */
-       bool            relhaspkey;             /* has (or has had) PRIMARY KEY index */
        bool            relhasrules;    /* has (or has had) any rules */
        bool            relhastriggers; /* has (or has had) any TRIGGERs */
        bool            relhassubclass; /* has (or has had) derived classes */
@@ -99,7 +98,7 @@ typedef FormData_pg_class *Form_pg_class;
  * ----------------
  */
 
-#define Natts_pg_class                                         33
+#define Natts_pg_class                                         32
 #define Anum_pg_class_relname                          1
 #define Anum_pg_class_relnamespace                     2
 #define Anum_pg_class_reltype                          3
@@ -119,20 +118,19 @@ typedef FormData_pg_class *Form_pg_class;
 #define Anum_pg_class_relnatts                         17
 #define Anum_pg_class_relchecks                                18
 #define Anum_pg_class_relhasoids                       19
-#define Anum_pg_class_relhaspkey                       20
-#define Anum_pg_class_relhasrules                      21
-#define Anum_pg_class_relhastriggers           22
-#define Anum_pg_class_relhassubclass           23
-#define Anum_pg_class_relrowsecurity           24
-#define Anum_pg_class_relforcerowsecurity      25
-#define Anum_pg_class_relispopulated           26
-#define Anum_pg_class_relreplident                     27
-#define Anum_pg_class_relispartition           28
-#define Anum_pg_class_relfrozenxid                     29
-#define Anum_pg_class_relminmxid                       30
-#define Anum_pg_class_relacl                           31
-#define Anum_pg_class_reloptions                       32
-#define Anum_pg_class_relpartbound                     33
+#define Anum_pg_class_relhasrules                      20
+#define Anum_pg_class_relhastriggers           21
+#define Anum_pg_class_relhassubclass           22
+#define Anum_pg_class_relrowsecurity           23
+#define Anum_pg_class_relforcerowsecurity      24
+#define Anum_pg_class_relispopulated           25
+#define Anum_pg_class_relreplident                     26
+#define Anum_pg_class_relispartition           27
+#define Anum_pg_class_relfrozenxid                     28
+#define Anum_pg_class_relminmxid                       29
+#define Anum_pg_class_relacl                           30
+#define Anum_pg_class_reloptions                       31
+#define Anum_pg_class_relpartbound                     32
 
 /* ----------------
  *             initial contents of pg_class
@@ -147,13 +145,13 @@ typedef FormData_pg_class *Form_pg_class;
  * Note: "3" in the relfrozenxid column stands for FirstNormalTransactionId;
  * similarly, "1" in relminmxid stands for FirstMultiXactId
  */
-DATA(insert OID = 1247 (  pg_type              PGNSP 71 0 PGUID 0 0 0 0 0 0 0 f f p r 30 0 t f f f f f t n f 3 1 _null_ _null_ _null_));
+DATA(insert OID = 1247 (  pg_type              PGNSP 71 0 PGUID 0 0 0 0 0 0 0 f f p r 30 0 t f f f f f t n f 3 1 _null_ _null_ _null_));
 DESCR("");
-DATA(insert OID = 1249 (  pg_attribute PGNSP 75 0 PGUID 0 0 0 0 0 0 0 f f p r 22 0 f f f f f f t n f 3 1 _null_ _null_ _null_));
+DATA(insert OID = 1249 (  pg_attribute PGNSP 75 0 PGUID 0 0 0 0 0 0 0 f f p r 22 0 f f f f f f t n f 3 1 _null_ _null_ _null_));
 DESCR("");
-DATA(insert OID = 1255 (  pg_proc              PGNSP 81 0 PGUID 0 0 0 0 0 0 0 f f p r 28 0 t f f f f f t n f 3 1 _null_ _null_ _null_));
+DATA(insert OID = 1255 (  pg_proc              PGNSP 81 0 PGUID 0 0 0 0 0 0 0 f f p r 28 0 t f f f f f t n f 3 1 _null_ _null_ _null_));
 DESCR("");
-DATA(insert OID = 1259 (  pg_class             PGNSP 83 0 PGUID 0 0 0 0 0 0 0 f f p r 33 0 t f f f f f f t n f 3 1 _null_ _null_ _null_));
+DATA(insert OID = 1259 (  pg_class             PGNSP 83 0 PGUID 0 0 0 0 0 0 0 f f p r 32 0 t f f f f f t n f 3 1 _null_ _null_ _null_));
 DESCR("");