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

Commit28f84f7

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 parentb218fbb commit28f84f7

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
@@ -734,18 +734,11 @@ void
734734
RemoveStatisticsById(OidstatsOid)
735735
{
736736
Relationrelation;
737+
Relationrel;
737738
HeapTupletup;
738739
Form_pg_statistic_extstatext;
739740
Oidrelid;
740741

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

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

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

767771
ReleaseSysCache(tup);
768772

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp