Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Eisentraut2018-03-14 18:59:40 +0000
committerPeter Eisentraut2018-03-14 19:31:34 +0000
commitf66e8bf875f691db4c5d0173fc39b5a9c3ec969c (patch)
tree69ebd3ed87cd2b9e729ea5c9d0008844d1bdd7a6 /src/backend
parent6b960aae90164cf85cf629e0af9286f97a9e51df (diff)
Remove pg_class.relhaspkey
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
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/catalog/heap.c1
-rw-r--r--src/backend/catalog/index.c32
-rw-r--r--src/backend/commands/vacuum.c10
-rw-r--r--src/backend/rewrite/rewriteDefine.c1
4 files changed, 2 insertions, 42 deletions
diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c
index cf36ce4add7..3d80ff9e5bb 100644
--- a/src/backend/catalog/heap.c
+++ b/src/backend/catalog/heap.c
@@ -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);
diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c
index 431bc319699..9e2dd0e729e 100644
--- a/src/backend/catalog/index.c
+++ b/src/backend/catalog/index.c
@@ -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();
@@ -1365,21 +1364,6 @@ index_constraint_create(Relation heapRelation,
}
/*
- * 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.
*
* Note: When making an existing index into a constraint, caller must have
@@ -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,12 +2330,10 @@ index_build(Relation heapRelation,
*/
index_update_stats(heapRelation,
true,
- isprimary,
stats->heap_tuples);
index_update_stats(indexRelation,
false,
- false,
stats->index_tuples);
/* Make the updated catalog row versions visible */
diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c
index b50c554c517..18b3966a1f7 100644
--- a/src/backend/commands/vacuum.c
+++ b/src/backend/commands/vacuum.c
@@ -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)
{
diff --git a/src/backend/rewrite/rewriteDefine.c b/src/backend/rewrite/rewriteDefine.c
index f3a9b639a80..679be605f14 100644
--- a/src/backend/rewrite/rewriteDefine.c
+++ b/src/backend/rewrite/rewriteDefine.c
@@ -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;