Skip to content

Commit fe30365

Browse files
committed
Fix race condition in statext_store().
Must hold some lock on the pg_statistic_ext_data catalog *before* we look up the tuple we aim to replace. Otherwise a concurrent VACUUM FULL or similar operation could move it to a different TID, leaving us trying to replace the wrong tuple. Back-patch to v12 where this got broken. Credit goes to Dean Rasheed; I'm just doing the clerical work. Discussion: https://postgr.es/m/CAEZATCU0zHMDiQV0g8P2U+YSP9C1idUPrn79DajsbonwkN0xvQ@mail.gmail.com
1 parent 33cd0e5 commit fe30365

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/backend/statistics/extended_stats.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -493,12 +493,14 @@ statext_store(Oid statOid,
493493
MVNDistinct *ndistinct, MVDependencies *dependencies,
494494
MCVList *mcv, VacAttrStats **stats)
495495
{
496+
Relation pg_stextdata;
496497
HeapTuple stup,
497498
oldtup;
498499
Datum values[Natts_pg_statistic_ext_data];
499500
bool nulls[Natts_pg_statistic_ext_data];
500501
bool replaces[Natts_pg_statistic_ext_data];
501-
Relation pg_stextdata;
502+
503+
pg_stextdata = table_open(StatisticExtDataRelationId, RowExclusiveLock);
502504

503505
memset(nulls, true, sizeof(nulls));
504506
memset(replaces, false, sizeof(replaces));
@@ -542,8 +544,6 @@ statext_store(Oid statOid,
542544
elog(ERROR, "cache lookup failed for statistics object %u", statOid);
543545

544546
/* replace it */
545-
pg_stextdata = table_open(StatisticExtDataRelationId, RowExclusiveLock);
546-
547547
stup = heap_modify_tuple(oldtup,
548548
RelationGetDescr(pg_stextdata),
549549
values,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy