@@ -2428,10 +2428,10 @@ RelationDestroyRelation(Relation relation, bool remember_tupdesc)
24282428 list_free_deep (relation -> rd_fkeylist );
24292429 list_free (relation -> rd_indexlist );
24302430 list_free (relation -> rd_statlist );
2431- bms_free (relation -> rd_indexattr );
24322431 bms_free (relation -> rd_keyattr );
24332432 bms_free (relation -> rd_pkattr );
24342433 bms_free (relation -> rd_idattr );
2434+ bms_free (relation -> rd_hotblockingattr );
24352435 if (relation -> rd_pubactions )
24362436 pfree (relation -> rd_pubactions );
24372437 if (relation -> rd_options )
@@ -5105,10 +5105,10 @@ RelationGetIndexPredicate(Relation relation)
51055105Bitmapset *
51065106RelationGetIndexAttrBitmap (Relation relation , IndexAttrBitmapKind attrKind )
51075107{
5108- Bitmapset * indexattrs ; /* indexed columns */
51095108 Bitmapset * uindexattrs ; /* columns in unique indexes */
51105109 Bitmapset * pkindexattrs ; /* columns in the primary index */
51115110 Bitmapset * idindexattrs ; /* columns in the replica identity */
5111+ Bitmapset * hotblockingattrs ; /* columns with HOT blocking indexes */
51125112 List * indexoidlist ;
51135113 List * newindexoidlist ;
51145114 Oid relpkindex ;
@@ -5117,18 +5117,18 @@ RelationGetIndexAttrBitmap(Relation relation, IndexAttrBitmapKind attrKind)
51175117 MemoryContext oldcxt ;
51185118
51195119 /* Quick exit if we already computed the result. */
5120- if (relation -> rd_indexattr != NULL )
5120+ if (relation -> rd_attrsvalid )
51215121 {
51225122 switch (attrKind )
51235123 {
5124- case INDEX_ATTR_BITMAP_ALL :
5125- return bms_copy (relation -> rd_indexattr );
51265124 case INDEX_ATTR_BITMAP_KEY :
51275125 return bms_copy (relation -> rd_keyattr );
51285126 case INDEX_ATTR_BITMAP_PRIMARY_KEY :
51295127 return bms_copy (relation -> rd_pkattr );
51305128 case INDEX_ATTR_BITMAP_IDENTITY_KEY :
51315129 return bms_copy (relation -> rd_idattr );
5130+ case INDEX_ATTR_BITMAP_HOT_BLOCKING :
5131+ return bms_copy (relation -> rd_hotblockingattr );
51325132 default :
51335133 elog (ERROR , "unknown attrKind %u" , attrKind );
51345134 }
@@ -5159,7 +5159,7 @@ RelationGetIndexAttrBitmap(Relation relation, IndexAttrBitmapKind attrKind)
51595159 relreplindex = relation -> rd_replidindex ;
51605160
51615161 /*
5162- * For each index, add referenced attributes to indexattrs .
5162+ * For each index, add referenced attributes to appropriate bitmaps .
51635163 *
51645164 * Note: we consider all indexes returned by RelationGetIndexList, even if
51655165 * they are not indisready or indisvalid. This is important because an
@@ -5168,10 +5168,10 @@ RelationGetIndexAttrBitmap(Relation relation, IndexAttrBitmapKind attrKind)
51685168 * CONCURRENTLY is far enough along that we should ignore the index, it
51695169 * won't be returned at all by RelationGetIndexList.
51705170 */
5171- indexattrs = NULL ;
51725171 uindexattrs = NULL ;
51735172 pkindexattrs = NULL ;
51745173 idindexattrs = NULL ;
5174+ hotblockingattrs = NULL ;
51755175 foreach (l , indexoidlist )
51765176 {
51775177 Oid indexOid = lfirst_oid (l );
@@ -5236,8 +5236,9 @@ RelationGetIndexAttrBitmap(Relation relation, IndexAttrBitmapKind attrKind)
52365236 */
52375237 if (attrnum != 0 )
52385238 {
5239- indexattrs = bms_add_member (indexattrs ,
5240- attrnum - FirstLowInvalidHeapAttributeNumber );
5239+ if (indexDesc -> rd_indam -> amhotblocking )
5240+ hotblockingattrs = bms_add_member (hotblockingattrs ,
5241+ attrnum - FirstLowInvalidHeapAttributeNumber );
52415242
52425243 if (isKey && i < indexDesc -> rd_index -> indnkeyatts )
52435244 uindexattrs = bms_add_member (uindexattrs ,
@@ -5254,10 +5255,15 @@ RelationGetIndexAttrBitmap(Relation relation, IndexAttrBitmapKind attrKind)
52545255 }
52555256
52565257 /* 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 );
52585260
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 );
52615267
52625268 index_close (indexDesc , AccessShareLock );
52635269 }
@@ -5285,46 +5291,47 @@ RelationGetIndexAttrBitmap(Relation relation, IndexAttrBitmapKind attrKind)
52855291 bms_free (uindexattrs );
52865292 bms_free (pkindexattrs );
52875293 bms_free (idindexattrs );
5288- bms_free (indexattrs );
5294+ bms_free (hotblockingattrs );
52895295
52905296 goto restart ;
52915297 }
52925298
52935299 /* Don't leak the old values of these bitmaps, if any */
5294- bms_free (relation -> rd_indexattr );
5295- relation -> rd_indexattr = NULL ;
52965300 bms_free (relation -> rd_keyattr );
52975301 relation -> rd_keyattr = NULL ;
52985302 bms_free (relation -> rd_pkattr );
52995303 relation -> rd_pkattr = NULL ;
53005304 bms_free (relation -> rd_idattr );
53015305 relation -> rd_idattr = NULL ;
5306+ bms_free (relation -> rd_hotblockingattr );
5307+ relation -> rd_hotblockingattr = NULL ;
53025308
53035309 /*
53045310 * 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
53075313 * leave the relcache entry looking like the other ones are valid but
53085314 * empty.
53095315 */
53105316 oldcxt = MemoryContextSwitchTo (CacheMemoryContext );
53115317 relation -> rd_keyattr = bms_copy (uindexattrs );
53125318 relation -> rd_pkattr = bms_copy (pkindexattrs );
53135319 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;
53155322 MemoryContextSwitchTo (oldcxt );
53165323
53175324 /* We return our original working copy for caller to play with */
53185325 switch (attrKind )
53195326 {
5320- case INDEX_ATTR_BITMAP_ALL :
5321- return indexattrs ;
53225327 case INDEX_ATTR_BITMAP_KEY :
53235328 return uindexattrs ;
53245329 case INDEX_ATTR_BITMAP_PRIMARY_KEY :
53255330 return pkindexattrs ;
53265331 case INDEX_ATTR_BITMAP_IDENTITY_KEY :
53275332 return idindexattrs ;
5333+ case INDEX_ATTR_BITMAP_HOT_BLOCKING :
5334+ return hotblockingattrs ;
53285335 default :
53295336 elog (ERROR , "unknown attrKind %u" , attrKind );
53305337 return NULL ;
@@ -6180,10 +6187,11 @@ load_relcache_init_file(bool shared)
61806187 rel -> rd_indexlist = NIL ;
61816188 rel -> rd_pkindex = InvalidOid ;
61826189 rel -> rd_replidindex = InvalidOid ;
6183- rel -> rd_indexattr = NULL ;
6190+ rel -> rd_attrsvalid = false ;
61846191 rel -> rd_keyattr = NULL ;
61856192 rel -> rd_pkattr = NULL ;
61866193 rel -> rd_idattr = NULL ;
6194+ rel -> rd_hotblockingattr = NULL ;
61876195 rel -> rd_pubactions = NULL ;
61886196 rel -> rd_statvalid = false;
61896197 rel -> rd_statlist = NIL ;
0 commit comments