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

Commit9dd50e9

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 parentfc3f862 commit9dd50e9

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

‎src/backend/commands/statscmds.c

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -722,20 +722,14 @@ AlterStatistics(AlterStatsStmt *stmt)
722722
}
723723

724724
/*
725-
*Guts of statistics object deletion.
726-
*/
727-
void
728-
RemoveStatisticsById(OidstatsOid)
725+
*Delete entry in pg_statistic_ext_data catalog.
726+
*/
727+
staticvoid
728+
RemoveStatisticsDataById(OidstatsOid)
729729
{
730730
Relationrelation;
731731
HeapTupletup;
732-
Form_pg_statistic_extstatext;
733-
Oidrelid;
734732

735-
/*
736-
* First delete the pg_statistic_ext_data tuple holding the actual
737-
* statistical data.
738-
*/
739733
relation=table_open(StatisticExtDataRelationId,RowExclusiveLock);
740734

741735
tup=SearchSysCache1(STATEXTDATASTXOID,ObjectIdGetDatum(statsOid));
@@ -748,6 +742,19 @@ RemoveStatisticsById(Oid statsOid)
748742
ReleaseSysCache(tup);
749743

750744
table_close(relation,RowExclusiveLock);
745+
}
746+
747+
/*
748+
* Guts of statistics object deletion.
749+
*/
750+
void
751+
RemoveStatisticsById(OidstatsOid)
752+
{
753+
Relationrelation;
754+
Relationrel;
755+
HeapTupletup;
756+
Form_pg_statistic_extstatext;
757+
Oidrelid;
751758

752759
/*
753760
* Delete the pg_statistic_ext tuple. Also send out a cache inval on the
@@ -763,12 +770,24 @@ RemoveStatisticsById(Oid statsOid)
763770
statext= (Form_pg_statistic_ext)GETSTRUCT(tup);
764771
relid=statext->stxrelid;
765772

773+
/*
774+
* Delete the pg_statistic_ext_data tuple holding the actual statistical
775+
* data. We lock the user table first, to prevent other processes (e.g.
776+
* DROP STATISTICS) from removing the row concurrently.
777+
*/
778+
rel=table_open(relid,ShareUpdateExclusiveLock);
779+
780+
RemoveStatisticsDataById(statsOid);
781+
766782
CacheInvalidateRelcacheByRelid(relid);
767783

768784
CatalogTupleDelete(relation,&tup->t_self);
769785

770786
ReleaseSysCache(tup);
771787

788+
/* Keep lock until the end of the transaction. */
789+
table_close(rel,NoLock);
790+
772791
table_close(relation,RowExclusiveLock);
773792
}
774793

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp