diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2020-03-31 17:06:22 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2020-03-31 17:06:22 -0400 |
commit | fe3036527a1ff715bceb22ff5cba919001262a71 (patch) | |
tree | 7212e3ea0194214b7fe802c29b53f0437085216d /src | |
parent | 33cd0e5ea65d1fad0a579fa7ef0bab337246c231 (diff) | |
download | postgresql-fe3036527a1ff715bceb22ff5cba919001262a71.tar.gz postgresql-fe3036527a1ff715bceb22ff5cba919001262a71.zip |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/statistics/extended_stats.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index 318fdb8f6dc..d1f818d49a8 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -493,12 +493,14 @@ statext_store(Oid statOid, MVNDistinct *ndistinct, MVDependencies *dependencies, MCVList *mcv, VacAttrStats **stats) { + Relation pg_stextdata; HeapTuple stup, oldtup; Datum values[Natts_pg_statistic_ext_data]; bool nulls[Natts_pg_statistic_ext_data]; bool replaces[Natts_pg_statistic_ext_data]; - Relation pg_stextdata; + + pg_stextdata = table_open(StatisticExtDataRelationId, RowExclusiveLock); memset(nulls, true, sizeof(nulls)); memset(replaces, false, sizeof(replaces)); @@ -542,8 +544,6 @@ statext_store(Oid statOid, elog(ERROR, "cache lookup failed for statistics object %u", statOid); /* replace it */ - pg_stextdata = table_open(StatisticExtDataRelationId, RowExclusiveLock); - stup = heap_modify_tuple(oldtup, RelationGetDescr(pg_stextdata), values, |