Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf66e8bf

Browse files
committed
Remove pg_class.relhaspkey
It is not used for anything internally, and it cannot be relied on forexternal uses, so it can just be removed. To correct recommended way tocheck for a primary key is in pg_index.Discussion:https://www.postgresql.org/message-id/flat/b1a24c6c-6913-f89c-674e-0704f0ed69db@2ndquadrant.com
1 parent6b960aa commitf66e8bf

File tree

7 files changed

+21
-72
lines changed

7 files changed

+21
-72
lines changed

‎doc/src/sgml/catalogs.sgml

Lines changed: 0 additions & 9 deletions
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ static void UpdateIndexRelation(Oid indexoid, Oid heapoid,
125125
boolisvalid,
126126
boolisready);
127127
staticvoidindex_update_stats(Relationrel,
128-
boolhasindex,boolisprimary,
128+
boolhasindex,
129129
doublereltuples);
130130
staticvoidIndexCheckExclusion(RelationheapRelation,
131131
RelationindexRelation,
@@ -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
staticvoid
20592042
index_update_stats(Relationrel,
20602043
boolhasindex,
2061-
boolisprimary,
20622044
doublereltuples)
20632045
{
20642046
Oidrelid=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

Lines changed: 0 additions & 10 deletions
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO201803021
56+
#defineCATALOG_VERSION_NO201803141
5757

5858
#endif

‎src/include/catalog/pg_class.h

Lines changed: 18 additions & 20 deletions
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
int16relchecks;/* # of CHECK constraints for class */
6363
boolrelhasoids;/* T if we generate OIDs for rows of rel */
64-
boolrelhaspkey;/* has (or has had) PRIMARY KEY index */
6564
boolrelhasrules;/* has (or has had) any rules */
6665
boolrelhastriggers;/* has (or has had) any TRIGGERs */
6766
boolrelhassubclass;/* has (or has had) derived classes */
@@ -99,7 +98,7 @@ typedef FormData_pg_class *Form_pg_class;
9998
* ----------------
10099
*/
101100

102-
#defineNatts_pg_class33
101+
#defineNatts_pg_class32
103102
#defineAnum_pg_class_relname1
104103
#defineAnum_pg_class_relnamespace2
105104
#defineAnum_pg_class_reltype3
@@ -119,20 +118,19 @@ typedef FormData_pg_class *Form_pg_class;
119118
#defineAnum_pg_class_relnatts17
120119
#defineAnum_pg_class_relchecks18
121120
#defineAnum_pg_class_relhasoids19
122-
#defineAnum_pg_class_relhaspkey20
123-
#defineAnum_pg_class_relhasrules21
124-
#defineAnum_pg_class_relhastriggers22
125-
#defineAnum_pg_class_relhassubclass23
126-
#defineAnum_pg_class_relrowsecurity24
127-
#defineAnum_pg_class_relforcerowsecurity25
128-
#defineAnum_pg_class_relispopulated26
129-
#defineAnum_pg_class_relreplident27
130-
#defineAnum_pg_class_relispartition28
131-
#defineAnum_pg_class_relfrozenxid29
132-
#defineAnum_pg_class_relminmxid30
133-
#defineAnum_pg_class_relacl31
134-
#defineAnum_pg_class_reloptions32
135-
#defineAnum_pg_class_relpartbound33
121+
#defineAnum_pg_class_relhasrules20
122+
#defineAnum_pg_class_relhastriggers21
123+
#defineAnum_pg_class_relhassubclass22
124+
#defineAnum_pg_class_relrowsecurity23
125+
#defineAnum_pg_class_relforcerowsecurity24
126+
#defineAnum_pg_class_relispopulated25
127+
#defineAnum_pg_class_relreplident26
128+
#defineAnum_pg_class_relispartition27
129+
#defineAnum_pg_class_relfrozenxid28
130+
#defineAnum_pg_class_relminmxid29
131+
#defineAnum_pg_class_relacl30
132+
#defineAnum_pg_class_reloptions31
133+
#defineAnum_pg_class_relpartbound32
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(insertOID=1247 (pg_typePGNSP710PGUID0000000ffpr300tfffffftnf31_null__null__null_));
148+
DATA(insertOID=1247 (pg_typePGNSP710PGUID0000000ffpr300tffffftnf31_null__null__null_));
151149
DESCR("");
152-
DATA(insertOID=1249 (pg_attributePGNSP750PGUID0000000ffpr220ffffffftnf31_null__null__null_));
150+
DATA(insertOID=1249 (pg_attributePGNSP750PGUID0000000ffpr220fffffftnf31_null__null__null_));
153151
DESCR("");
154-
DATA(insertOID=1255 (pg_procPGNSP810PGUID0000000ffpr280tfffffftnf31_null__null__null_));
152+
DATA(insertOID=1255 (pg_procPGNSP810PGUID0000000ffpr280tffffftnf31_null__null__null_));
155153
DESCR("");
156-
DATA(insertOID=1259 (pg_classPGNSP830PGUID0000000ffpr330tfffffftnf31_null__null__null_));
154+
DATA(insertOID=1259 (pg_classPGNSP830PGUID0000000ffpr320tffffftnf31_null__null__null_));
157155
DESCR("");
158156

159157

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp