@@ -2428,10 +2428,10 @@ RelationDestroyRelation(Relation relation, bool remember_tupdesc)
2428
2428
list_free_deep (relation -> rd_fkeylist );
2429
2429
list_free (relation -> rd_indexlist );
2430
2430
list_free (relation -> rd_statlist );
2431
- bms_free (relation -> rd_indexattr );
2432
2431
bms_free (relation -> rd_keyattr );
2433
2432
bms_free (relation -> rd_pkattr );
2434
2433
bms_free (relation -> rd_idattr );
2434
+ bms_free (relation -> rd_hotblockingattr );
2435
2435
if (relation -> rd_pubactions )
2436
2436
pfree (relation -> rd_pubactions );
2437
2437
if (relation -> rd_options )
@@ -5105,10 +5105,10 @@ RelationGetIndexPredicate(Relation relation)
5105
5105
Bitmapset *
5106
5106
RelationGetIndexAttrBitmap (Relation relation , IndexAttrBitmapKind attrKind )
5107
5107
{
5108
- Bitmapset * indexattrs ; /* indexed columns */
5109
5108
Bitmapset * uindexattrs ; /* columns in unique indexes */
5110
5109
Bitmapset * pkindexattrs ; /* columns in the primary index */
5111
5110
Bitmapset * idindexattrs ; /* columns in the replica identity */
5111
+ Bitmapset * hotblockingattrs ; /* columns with HOT blocking indexes */
5112
5112
List * indexoidlist ;
5113
5113
List * newindexoidlist ;
5114
5114
Oid relpkindex ;
@@ -5117,18 +5117,18 @@ RelationGetIndexAttrBitmap(Relation relation, IndexAttrBitmapKind attrKind)
5117
5117
MemoryContext oldcxt ;
5118
5118
5119
5119
/* Quick exit if we already computed the result. */
5120
- if (relation -> rd_indexattr != NULL )
5120
+ if (relation -> rd_attrsvalid )
5121
5121
{
5122
5122
switch (attrKind )
5123
5123
{
5124
- case INDEX_ATTR_BITMAP_ALL :
5125
- return bms_copy (relation -> rd_indexattr );
5126
5124
case INDEX_ATTR_BITMAP_KEY :
5127
5125
return bms_copy (relation -> rd_keyattr );
5128
5126
case INDEX_ATTR_BITMAP_PRIMARY_KEY :
5129
5127
return bms_copy (relation -> rd_pkattr );
5130
5128
case INDEX_ATTR_BITMAP_IDENTITY_KEY :
5131
5129
return bms_copy (relation -> rd_idattr );
5130
+ case INDEX_ATTR_BITMAP_HOT_BLOCKING :
5131
+ return bms_copy (relation -> rd_hotblockingattr );
5132
5132
default :
5133
5133
elog (ERROR , "unknown attrKind %u" , attrKind );
5134
5134
}
@@ -5159,7 +5159,7 @@ RelationGetIndexAttrBitmap(Relation relation, IndexAttrBitmapKind attrKind)
5159
5159
relreplindex = relation -> rd_replidindex ;
5160
5160
5161
5161
/*
5162
- * For each index, add referenced attributes to indexattrs .
5162
+ * For each index, add referenced attributes to appropriate bitmaps .
5163
5163
*
5164
5164
* Note: we consider all indexes returned by RelationGetIndexList, even if
5165
5165
* they are not indisready or indisvalid. This is important because an
@@ -5168,10 +5168,10 @@ RelationGetIndexAttrBitmap(Relation relation, IndexAttrBitmapKind attrKind)
5168
5168
* CONCURRENTLY is far enough along that we should ignore the index, it
5169
5169
* won't be returned at all by RelationGetIndexList.
5170
5170
*/
5171
- indexattrs = NULL ;
5172
5171
uindexattrs = NULL ;
5173
5172
pkindexattrs = NULL ;
5174
5173
idindexattrs = NULL ;
5174
+ hotblockingattrs = NULL ;
5175
5175
foreach (l , indexoidlist )
5176
5176
{
5177
5177
Oid indexOid = lfirst_oid (l );
@@ -5236,8 +5236,9 @@ RelationGetIndexAttrBitmap(Relation relation, IndexAttrBitmapKind attrKind)
5236
5236
*/
5237
5237
if (attrnum != 0 )
5238
5238
{
5239
- indexattrs = bms_add_member (indexattrs ,
5240
- attrnum - FirstLowInvalidHeapAttributeNumber );
5239
+ if (indexDesc -> rd_indam -> amhotblocking )
5240
+ hotblockingattrs = bms_add_member (hotblockingattrs ,
5241
+ attrnum - FirstLowInvalidHeapAttributeNumber );
5241
5242
5242
5243
if (isKey && i < indexDesc -> rd_index -> indnkeyatts )
5243
5244
uindexattrs = bms_add_member (uindexattrs ,
@@ -5254,10 +5255,15 @@ RelationGetIndexAttrBitmap(Relation relation, IndexAttrBitmapKind attrKind)
5254
5255
}
5255
5256
5256
5257
/* Collect all attributes used in expressions, too */
5257
- pull_varattnos (indexExpressions , 1 , & indexattrs );
5258
+ if (indexDesc -> rd_indam -> amhotblocking )
5259
+ pull_varattnos (indexExpressions , 1 , & hotblockingattrs );
5258
5260
5259
- /* Collect all attributes in the index predicate, too */
5260
- pull_varattnos (indexPredicate , 1 , & indexattrs );
5261
+ /*
5262
+ * Collect all attributes in the index predicate, too. We have to ignore
5263
+ * amhotblocking flag, because the row might become indexable, in which
5264
+ * case we have to add it to the index.
5265
+ */
5266
+ pull_varattnos (indexPredicate , 1 , & hotblockingattrs );
5261
5267
5262
5268
index_close (indexDesc , AccessShareLock );
5263
5269
}
@@ -5285,46 +5291,47 @@ RelationGetIndexAttrBitmap(Relation relation, IndexAttrBitmapKind attrKind)
5285
5291
bms_free (uindexattrs );
5286
5292
bms_free (pkindexattrs );
5287
5293
bms_free (idindexattrs );
5288
- bms_free (indexattrs );
5294
+ bms_free (hotblockingattrs );
5289
5295
5290
5296
goto restart ;
5291
5297
}
5292
5298
5293
5299
/* Don't leak the old values of these bitmaps, if any */
5294
- bms_free (relation -> rd_indexattr );
5295
- relation -> rd_indexattr = NULL ;
5296
5300
bms_free (relation -> rd_keyattr );
5297
5301
relation -> rd_keyattr = NULL ;
5298
5302
bms_free (relation -> rd_pkattr );
5299
5303
relation -> rd_pkattr = NULL ;
5300
5304
bms_free (relation -> rd_idattr );
5301
5305
relation -> rd_idattr = NULL ;
5306
+ bms_free (relation -> rd_hotblockingattr );
5307
+ relation -> rd_hotblockingattr = NULL ;
5302
5308
5303
5309
/*
5304
5310
* Now save copies of the bitmaps in the relcache entry. We intentionally
5305
- * set rd_indexattr last, because that's the one that signals validity of
5306
- * the values; if we run out of memory before making that copy, we won't
5311
+ * set rd_attrsvalid last, because that's what signals validity of the
5312
+ * values; if we run out of memory before making that copy, we won't
5307
5313
* leave the relcache entry looking like the other ones are valid but
5308
5314
* empty.
5309
5315
*/
5310
5316
oldcxt = MemoryContextSwitchTo (CacheMemoryContext );
5311
5317
relation -> rd_keyattr = bms_copy (uindexattrs );
5312
5318
relation -> rd_pkattr = bms_copy (pkindexattrs );
5313
5319
relation -> rd_idattr = bms_copy (idindexattrs );
5314
- relation -> rd_indexattr = bms_copy (indexattrs );
5320
+ relation -> rd_hotblockingattr = bms_copy (hotblockingattrs );
5321
+ relation -> rd_attrsvalid = true;
5315
5322
MemoryContextSwitchTo (oldcxt );
5316
5323
5317
5324
/* We return our original working copy for caller to play with */
5318
5325
switch (attrKind )
5319
5326
{
5320
- case INDEX_ATTR_BITMAP_ALL :
5321
- return indexattrs ;
5322
5327
case INDEX_ATTR_BITMAP_KEY :
5323
5328
return uindexattrs ;
5324
5329
case INDEX_ATTR_BITMAP_PRIMARY_KEY :
5325
5330
return pkindexattrs ;
5326
5331
case INDEX_ATTR_BITMAP_IDENTITY_KEY :
5327
5332
return idindexattrs ;
5333
+ case INDEX_ATTR_BITMAP_HOT_BLOCKING :
5334
+ return hotblockingattrs ;
5328
5335
default :
5329
5336
elog (ERROR , "unknown attrKind %u" , attrKind );
5330
5337
return NULL ;
@@ -6180,10 +6187,11 @@ load_relcache_init_file(bool shared)
6180
6187
rel -> rd_indexlist = NIL ;
6181
6188
rel -> rd_pkindex = InvalidOid ;
6182
6189
rel -> rd_replidindex = InvalidOid ;
6183
- rel -> rd_indexattr = NULL ;
6190
+ rel -> rd_attrsvalid = false ;
6184
6191
rel -> rd_keyattr = NULL ;
6185
6192
rel -> rd_pkattr = NULL ;
6186
6193
rel -> rd_idattr = NULL ;
6194
+ rel -> rd_hotblockingattr = NULL ;
6187
6195
rel -> rd_pubactions = NULL ;
6188
6196
rel -> rd_statvalid = false;
6189
6197
rel -> rd_statlist = NIL ;
0 commit comments