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

Commit8b38a53

Browse files
committed
Add Asserts to verify that catalog cache keys are unique and not null.
The catcache code is effectively assuming this already, so let's insistthat the catalog and index are actually declared that way.Having done that, the comments in indexing.h about non-unique indexesnot being used for catcaches are completely redundant not just mostly so;and we didn't have such a comment for every such index anyway. So let'sget rid of them.Per discussion of whether we should identify primary keys for catalogs.We might or might not take that further step, but this change in itselfwill allow quicker detection of misdeclared catcaches, so it seems worthdoing in any case.
1 parent1dde578 commit8b38a53

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

‎src/backend/utils/cache/catcache.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,13 @@ CatalogCacheInitializeCache(CatCache *cache)
931931
CatalogCacheInitializeCache_DEBUG2;
932932

933933
if (cache->cc_key[i]>0)
934-
keytype=tupdesc->attrs[cache->cc_key[i]-1]->atttypid;
934+
{
935+
Form_pg_attributeattr=tupdesc->attrs[cache->cc_key[i]-1];
936+
937+
keytype=attr->atttypid;
938+
/* cache key columns should always be NOT NULL */
939+
Assert(attr->attnotnull);
940+
}
935941
else
936942
{
937943
if (cache->cc_key[i]!=ObjectIdAttributeNumber)
@@ -1003,6 +1009,16 @@ InitCatCachePhase2(CatCache *cache, bool touch_index)
10031009
*/
10041010
LockRelationOid(cache->cc_reloid,AccessShareLock);
10051011
idesc=index_open(cache->cc_indexoid,AccessShareLock);
1012+
1013+
/*
1014+
* While we've got the index open, let's check that it's unique (and
1015+
* not just deferrable-unique, thank you very much). This is just to
1016+
* catch thinkos in definitions of new catcaches, so we don't worry
1017+
* about the pg_am indexes not getting tested.
1018+
*/
1019+
Assert(idesc->rd_index->indisunique&&
1020+
idesc->rd_index->indimmediate);
1021+
10061022
index_close(idesc,AccessShareLock);
10071023
UnlockRelationOid(cache->cc_reloid,AccessShareLock);
10081024
}

‎src/include/catalog/indexing.h

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ extern void CatalogUpdateIndexes(Relation heapRel, HeapTuple heapTuple);
4646

4747
/*
4848
* What follows are lines processed by genbki.pl to create the statements
49-
* the bootstrap parser will turn into DefineIndexcommands.
49+
* the bootstrap parser will turn into DefineIndexcalls.
5050
*
5151
* The keyword is DECLARE_INDEX or DECLARE_UNIQUE_INDEX. The first two
5252
* arguments are the index name and OID, the rest is much like a standard
@@ -114,13 +114,10 @@ DECLARE_UNIQUE_INDEX(pg_collation_name_enc_nsp_index, 3164, on pg_collation usin
114114
DECLARE_UNIQUE_INDEX(pg_collation_oid_index,3085,onpg_collationusingbtree(oidoid_ops));
115115
#defineCollationOidIndexId 3085
116116

117-
/* This following index is not used for a cache and is not unique */
118117
DECLARE_INDEX(pg_constraint_conname_nsp_index,2664,onpg_constraintusingbtree(connamename_ops,connamespaceoid_ops));
119118
#defineConstraintNameNspIndexId 2664
120-
/* This following index is not used for a cache and is not unique */
121119
DECLARE_INDEX(pg_constraint_conrelid_index,2665,onpg_constraintusingbtree(conrelidoid_ops));
122120
#defineConstraintRelidIndexId2665
123-
/* This following index is not used for a cache and is not unique */
124121
DECLARE_INDEX(pg_constraint_contypid_index,2666,onpg_constraintusingbtree(contypidoid_ops));
125122
#defineConstraintTypidIndexId2666
126123
DECLARE_UNIQUE_INDEX(pg_constraint_oid_index,2667,onpg_constraintusingbtree(oidoid_ops));
@@ -138,10 +135,8 @@ DECLARE_UNIQUE_INDEX(pg_database_datname_index, 2671, on pg_database using btree
138135
DECLARE_UNIQUE_INDEX(pg_database_oid_index,2672,onpg_databaseusingbtree(oidoid_ops));
139136
#defineDatabaseOidIndexId2672
140137

141-
/* This following index is not used for a cache and is not unique */
142138
DECLARE_INDEX(pg_depend_depender_index,2673,onpg_dependusingbtree(classidoid_ops,objidoid_ops,objsubidint4_ops));
143139
#defineDependDependerIndexId 2673
144-
/* This following index is not used for a cache and is not unique */
145140
DECLARE_INDEX(pg_depend_reference_index,2674,onpg_dependusingbtree(refclassidoid_ops,refobjidoid_ops,refobjsubidint4_ops));
146141
#defineDependReferenceIndexId2674
147142

@@ -157,15 +152,13 @@ DECLARE_UNIQUE_INDEX(pg_enum_typid_label_index, 3503, on pg_enum using btree(enu
157152
DECLARE_UNIQUE_INDEX(pg_enum_typid_sortorder_index,3534,onpg_enumusingbtree(enumtypidoid_ops,enumsortorderfloat4_ops));
158153
#defineEnumTypIdSortOrderIndexId 3534
159154

160-
/* This following index is not used for a cache and is not unique */
161155
DECLARE_INDEX(pg_index_indrelid_index,2678,onpg_indexusingbtree(indrelidoid_ops));
162156
#defineIndexIndrelidIndexId 2678
163157
DECLARE_UNIQUE_INDEX(pg_index_indexrelid_index,2679,onpg_indexusingbtree(indexrelidoid_ops));
164158
#defineIndexRelidIndexId 2679
165159

166160
DECLARE_UNIQUE_INDEX(pg_inherits_relid_seqno_index,2680,onpg_inheritsusingbtree(inhrelidoid_ops,inhseqnoint4_ops));
167161
#defineInheritsRelidSeqnoIndexId 2680
168-
/* This following index is not used for a cache and is not unique */
169162
DECLARE_INDEX(pg_inherits_parent_index,2187,onpg_inheritsusingbtree(inhparentoid_ops));
170163
#defineInheritsParentIndexId 2187
171164

@@ -213,10 +206,8 @@ DECLARE_UNIQUE_INDEX(pg_rewrite_oid_index, 2692, on pg_rewrite using btree(oid o
213206
DECLARE_UNIQUE_INDEX(pg_rewrite_rel_rulename_index,2693,onpg_rewriteusingbtree(ev_classoid_ops,rulenamename_ops));
214207
#defineRewriteRelRulenameIndexId 2693
215208

216-
/* This following index is not used for a cache and is not unique */
217209
DECLARE_INDEX(pg_shdepend_depender_index,1232,onpg_shdependusingbtree(dbidoid_ops,classidoid_ops,objidoid_ops,objsubidint4_ops));
218210
#defineSharedDependDependerIndexId1232
219-
/* This following index is not used for a cache and is not unique */
220211
DECLARE_INDEX(pg_shdepend_reference_index,1233,onpg_shdependusingbtree(refclassidoid_ops,refobjidoid_ops));
221212
#defineSharedDependReferenceIndexId1233
222213

@@ -228,7 +219,6 @@ DECLARE_UNIQUE_INDEX(pg_tablespace_oid_index, 2697, on pg_tablespace using btree
228219
DECLARE_UNIQUE_INDEX(pg_tablespace_spcname_index,2698,onpg_tablespaceusingbtree(spcnamename_ops));
229220
#defineTablespaceNameIndexId 2698
230221

231-
/* This following index is not used for a cache and is not unique */
232222
DECLARE_INDEX(pg_trigger_tgconstraint_index,2699,onpg_triggerusingbtree(tgconstraintoid_ops));
233223
#defineTriggerConstraintIndexId 2699
234224
DECLARE_UNIQUE_INDEX(pg_trigger_tgrelid_tgname_index,2701,onpg_triggerusingbtree(tgrelidoid_ops,tgnamename_ops));
@@ -271,19 +261,16 @@ DECLARE_UNIQUE_INDEX(pg_type_typname_nsp_index, 2704, on pg_type using btree(typ
271261

272262
DECLARE_UNIQUE_INDEX(pg_foreign_data_wrapper_oid_index,112,onpg_foreign_data_wrapperusingbtree(oidoid_ops));
273263
#defineForeignDataWrapperOidIndexId112
274-
275264
DECLARE_UNIQUE_INDEX(pg_foreign_data_wrapper_name_index,548,onpg_foreign_data_wrapperusingbtree(fdwnamename_ops));
276265
#defineForeignDataWrapperNameIndexId548
277266

278267
DECLARE_UNIQUE_INDEX(pg_foreign_server_oid_index,113,onpg_foreign_serverusingbtree(oidoid_ops));
279268
#defineForeignServerOidIndexId 113
280-
281269
DECLARE_UNIQUE_INDEX(pg_foreign_server_name_index,549,onpg_foreign_serverusingbtree(srvnamename_ops));
282270
#defineForeignServerNameIndexId549
283271

284272
DECLARE_UNIQUE_INDEX(pg_user_mapping_oid_index,174,onpg_user_mappingusingbtree(oidoid_ops));
285273
#defineUserMappingOidIndexId174
286-
287274
DECLARE_UNIQUE_INDEX(pg_user_mapping_user_server_index,175,onpg_user_mappingusingbtree(umuseroid_ops,umserveroid_ops));
288275
#defineUserMappingUserServerIndexId175
289276

@@ -306,7 +293,6 @@ DECLARE_UNIQUE_INDEX(pg_shseclabel_object_index, 3593, on pg_shseclabel using bt
306293

307294
DECLARE_UNIQUE_INDEX(pg_extension_oid_index,3080,onpg_extensionusingbtree(oidoid_ops));
308295
#defineExtensionOidIndexId 3080
309-
310296
DECLARE_UNIQUE_INDEX(pg_extension_name_index,3081,onpg_extensionusingbtree(extnamename_ops));
311297
#defineExtensionNameIndexId 3081
312298

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp