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

Commit0177fc7

Browse files
committed
Lock table in DROP STATISTICS
The DROP STATISTICS code failed to properly lock the table, leading to ERROR: tuple concurrently deletedwhen executed concurrently with ANALYZE.Fixed by modifying RemoveStatisticsById() to acquire the same lock asANALYZE. This function is called only by DROP STATISTICS, as ANALYZEcalls RemoveStatisticsDataById() directly.Reported by Justin Pryzby, fix by me. Backpatch through 12. The code waslike this since it was introduced in 10, but older releases are EOL.Reported-by: Justin PryzbyReviewed-by: Tom LaneBackpatch-through: 12Discussion:https://postgr.es/m/ZUuk-8CfbYeq6g_u@pryzbyj2023
1 parent1816ecd commit0177fc7

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

‎src/backend/commands/statscmds.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -735,18 +735,11 @@ void
735735
RemoveStatisticsById(OidstatsOid)
736736
{
737737
Relationrelation;
738+
Relationrel;
738739
HeapTupletup;
739740
Form_pg_statistic_extstatext;
740741
Oidrelid;
741742

742-
/*
743-
* First delete the pg_statistic_ext_data tuples holding the actual
744-
* statistical data. There might be data with/without inheritance, so
745-
* attempt deleting both.
746-
*/
747-
RemoveStatisticsDataById(statsOid, true);
748-
RemoveStatisticsDataById(statsOid, false);
749-
750743
/*
751744
* Delete the pg_statistic_ext tuple. Also send out a cache inval on the
752745
* associated table, so that dependent plans will be rebuilt.
@@ -761,12 +754,26 @@ RemoveStatisticsById(Oid statsOid)
761754
statext= (Form_pg_statistic_ext)GETSTRUCT(tup);
762755
relid=statext->stxrelid;
763756

757+
/*
758+
* Delete the pg_statistic_ext_data tuples holding the actual statistical
759+
* data. There might be data with/without inheritance, so attempt deleting
760+
* both. We lock the user table first, to prevent other processes (e.g.
761+
* DROP STATISTICS) from removing the row concurrently.
762+
*/
763+
rel=table_open(relid,ShareUpdateExclusiveLock);
764+
765+
RemoveStatisticsDataById(statsOid, true);
766+
RemoveStatisticsDataById(statsOid, false);
767+
764768
CacheInvalidateRelcacheByRelid(relid);
765769

766770
CatalogTupleDelete(relation,&tup->t_self);
767771

768772
ReleaseSysCache(tup);
769773

774+
/* Keep lock until the end of the transaction. */
775+
table_close(rel,NoLock);
776+
770777
table_close(relation,RowExclusiveLock);
771778
}
772779

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp