Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f66e8bf

Browse files
committed
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
1 parent 6b960aa commit f66e8bf

File tree

7 files changed

+21
-72
lines changed

7 files changed

+21
-72
lines changed

doc/src/sgml/catalogs.sgml

-9
Original file line numberDiff line numberDiff line change
@@ -1848,15 +1848,6 @@ SCRAM-SHA-256$<replaceable>&lt;iteration count&gt;</replaceable>:<replaceable>&l
18481848
</entry>
18491849
</row>
18501850

1851-
<row>
1852-
<entry><structfield>relhaspkey</structfield></entry>
1853-
<entry><type>bool</type></entry>
1854-
<entry></entry>
1855-
<entry>
1856-
True if the table has (or once had) a primary key
1857-
</entry>
1858-
</row>
1859-
18601851
<row>
18611852
<entry><structfield>relhasrules</structfield></entry>
18621853
<entry><type>bool</type></entry>

src/backend/catalog/heap.c

-1
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,6 @@ InsertPgClassTuple(Relation pg_class_desc,
798798
values[Anum_pg_class_relnatts - 1] = Int16GetDatum(rd_rel->relnatts);
799799
values[Anum_pg_class_relchecks - 1] = Int16GetDatum(rd_rel->relchecks);
800800
values[Anum_pg_class_relhasoids - 1] = BoolGetDatum(rd_rel->relhasoids);
801-
values[Anum_pg_class_relhaspkey - 1] = BoolGetDatum(rd_rel->relhaspkey);
802801
values[Anum_pg_class_relhasrules - 1] = BoolGetDatum(rd_rel->relhasrules);
803802
values[Anum_pg_class_relhastriggers - 1] = BoolGetDatum(rd_rel->relhastriggers);
804803
values[Anum_pg_class_relrowsecurity - 1] = BoolGetDatum(rd_rel->relrowsecurity);

src/backend/catalog/index.c

+2-30
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ static void UpdateIndexRelation(Oid indexoid, Oid heapoid,
125125
bool isvalid,
126126
bool isready);
127127
static void index_update_stats(Relation rel,
128-
bool hasindex, bool isprimary,
128+
bool hasindex,
129129
double reltuples);
130130
static void IndexCheckExclusion(Relation heapRelation,
131131
Relation indexRelation,
@@ -1162,7 +1162,6 @@ index_create(Relation heapRelation,
11621162
*/
11631163
index_update_stats(heapRelation,
11641164
true,
1165-
isprimary,
11661165
-1.0);
11671166
/* Make the above update visible */
11681167
CommandCounterIncrement();
@@ -1364,21 +1363,6 @@ index_constraint_create(Relation heapRelation,
13641363
InvalidOid, conOid, indexRelationId, true);
13651364
}
13661365

1367-
/*
1368-
* If needed, mark the table as having a primary key. We assume it can't
1369-
* have been so marked already, so no need to clear the flag in the other
1370-
* case.
1371-
*
1372-
* Note: this might better be done by callers. We do it here to avoid
1373-
* exposing index_update_stats() globally, but that wouldn't be necessary
1374-
* if relhaspkey went away.
1375-
*/
1376-
if (mark_as_primary)
1377-
index_update_stats(heapRelation,
1378-
true,
1379-
true,
1380-
-1.0);
1381-
13821366
/*
13831367
* If needed, mark the index as primary and/or deferred in pg_index.
13841368
*
@@ -2041,7 +2025,6 @@ FormIndexDatum(IndexInfo *indexInfo,
20412025
* to ensure we can do all the necessary work in just one update.
20422026
*
20432027
* hasindex: set relhasindex to this value
2044-
* isprimary: if true, set relhaspkey true; else no change
20452028
* reltuples: if >= 0, set reltuples to this value; else no change
20462029
*
20472030
* If reltuples >= 0, relpages and relallvisible are also updated (using
@@ -2058,7 +2041,6 @@ FormIndexDatum(IndexInfo *indexInfo,
20582041
static void
20592042
index_update_stats(Relation rel,
20602043
bool hasindex,
2061-
bool isprimary,
20622044
double reltuples)
20632045
{
20642046
Oid relid = RelationGetRelid(rel);
@@ -2088,7 +2070,7 @@ index_update_stats(Relation rel,
20882070
* It is safe to use a non-transactional update even though our
20892071
* transaction could still fail before committing. Setting relhasindex
20902072
* true is safe even if there are no indexes (VACUUM will eventually fix
2091-
* it), likewise for relhaspkey. And of course the new relpages and
2073+
* it). And of course the new relpages and
20922074
* reltuples counts are correct regardless. However, we don't want to
20932075
* change relpages (or relallvisible) if the caller isn't providing an
20942076
* updated reltuples count, because that would bollix the
@@ -2140,14 +2122,6 @@ index_update_stats(Relation rel,
21402122
rd_rel->relhasindex = hasindex;
21412123
dirty = true;
21422124
}
2143-
if (isprimary)
2144-
{
2145-
if (!rd_rel->relhaspkey)
2146-
{
2147-
rd_rel->relhaspkey = true;
2148-
dirty = true;
2149-
}
2150-
}
21512125

21522126
if (reltuples >= 0)
21532127
{
@@ -2356,11 +2330,9 @@ index_build(Relation heapRelation,
23562330
*/
23572331
index_update_stats(heapRelation,
23582332
true,
2359-
isprimary,
23602333
stats->heap_tuples);
23612334

23622335
index_update_stats(indexRelation,
2363-
false,
23642336
false,
23652337
stats->index_tuples);
23662338

src/backend/commands/vacuum.c

-10
Original file line numberDiff line numberDiff line change
@@ -909,16 +909,6 @@ vac_update_relstats(Relation relation,
909909
dirty = true;
910910
}
911911

912-
/*
913-
* If we have discovered that there are no indexes, then there's no
914-
* primary key either. This could be done more thoroughly...
915-
*/
916-
if (pgcform->relhaspkey && !hasindex)
917-
{
918-
pgcform->relhaspkey = false;
919-
dirty = true;
920-
}
921-
922912
/* We also clear relhasrules and relhastriggers if needed */
923913
if (pgcform->relhasrules && relation->rd_rules == NULL)
924914
{

src/backend/rewrite/rewriteDefine.c

-1
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,6 @@ DefineQueryRewrite(const char *rulename,
618618
classForm->relhasindex = false;
619619
classForm->relkind = RELKIND_VIEW;
620620
classForm->relhasoids = false;
621-
classForm->relhaspkey = false;
622621
classForm->relfrozenxid = InvalidTransactionId;
623622
classForm->relminmxid = InvalidMultiXactId;
624623
classForm->relreplident = REPLICA_IDENTITY_NOTHING;

src/include/catalog/catversion.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/* yyyymmddN */
56-
#define CATALOG_VERSION_NO 201803021
56+
#define CATALOG_VERSION_NO 201803141
5757

5858
#endif

src/include/catalog/pg_class.h

+18-20
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ CATALOG(pg_class,1259) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83) BKI_SCHEMA_MACRO
6161
*/
6262
int16 relchecks; /* # of CHECK constraints for class */
6363
bool relhasoids; /* T if we generate OIDs for rows of rel */
64-
bool relhaspkey; /* has (or has had) PRIMARY KEY index */
6564
bool relhasrules; /* has (or has had) any rules */
6665
bool relhastriggers; /* has (or has had) any TRIGGERs */
6766
bool relhassubclass; /* has (or has had) derived classes */
@@ -99,7 +98,7 @@ typedef FormData_pg_class *Form_pg_class;
9998
* ----------------
10099
*/
101100

102-
#define Natts_pg_class 33
101+
#define Natts_pg_class 32
103102
#define Anum_pg_class_relname 1
104103
#define Anum_pg_class_relnamespace 2
105104
#define Anum_pg_class_reltype 3
@@ -119,20 +118,19 @@ typedef FormData_pg_class *Form_pg_class;
119118
#define Anum_pg_class_relnatts 17
120119
#define Anum_pg_class_relchecks 18
121120
#define Anum_pg_class_relhasoids 19
122-
#define Anum_pg_class_relhaspkey 20
123-
#define Anum_pg_class_relhasrules 21
124-
#define Anum_pg_class_relhastriggers 22
125-
#define Anum_pg_class_relhassubclass 23
126-
#define Anum_pg_class_relrowsecurity 24
127-
#define Anum_pg_class_relforcerowsecurity 25
128-
#define Anum_pg_class_relispopulated 26
129-
#define Anum_pg_class_relreplident 27
130-
#define Anum_pg_class_relispartition 28
131-
#define Anum_pg_class_relfrozenxid 29
132-
#define Anum_pg_class_relminmxid 30
133-
#define Anum_pg_class_relacl 31
134-
#define Anum_pg_class_reloptions 32
135-
#define Anum_pg_class_relpartbound 33
121+
#define Anum_pg_class_relhasrules 20
122+
#define Anum_pg_class_relhastriggers 21
123+
#define Anum_pg_class_relhassubclass 22
124+
#define Anum_pg_class_relrowsecurity 23
125+
#define Anum_pg_class_relforcerowsecurity 24
126+
#define Anum_pg_class_relispopulated 25
127+
#define Anum_pg_class_relreplident 26
128+
#define Anum_pg_class_relispartition 27
129+
#define Anum_pg_class_relfrozenxid 28
130+
#define Anum_pg_class_relminmxid 29
131+
#define Anum_pg_class_relacl 30
132+
#define Anum_pg_class_reloptions 31
133+
#define Anum_pg_class_relpartbound 32
136134

137135
/* ----------------
138136
* initial contents of pg_class
@@ -147,13 +145,13 @@ typedef FormData_pg_class *Form_pg_class;
147145
* Note: "3" in the relfrozenxid column stands for FirstNormalTransactionId;
148146
* similarly, "1" in relminmxid stands for FirstMultiXactId
149147
*/
150-
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 f t n f 3 1 _null_ _null_ _null_));
148+
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_));
151149
DESCR("");
152-
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 f t n f 3 1 _null_ _null_ _null_));
150+
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_));
153151
DESCR("");
154-
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 f t n f 3 1 _null_ _null_ _null_));
152+
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_));
155153
DESCR("");
156-
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_));
154+
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_));
157155
DESCR("");
158156

159157

0 commit comments

Comments
 (0)