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

Commit1e468ea

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 parentb736f06 commit1e468ea

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
@@ -538,20 +538,14 @@ AlterStatistics(AlterStatsStmt *stmt)
538538
}
539539

540540
/*
541-
* Guts of statistics object deletion.
542-
*/
543-
void
544-
RemoveStatisticsById(OidstatsOid)
541+
* Guts of statistics object deletion.
542+
*/
543+
staticvoid
544+
RemoveStatisticsDataById(OidstatsOid)
545545
{
546546
Relationrelation;
547547
HeapTupletup;
548-
Form_pg_statistic_extstatext;
549-
Oidrelid;
550548

551-
/*
552-
* First delete the pg_statistic_ext_data tuple holding the actual
553-
* statistical data.
554-
*/
555549
relation=table_open(StatisticExtDataRelationId,RowExclusiveLock);
556550

557551
tup=SearchSysCache1(STATEXTDATASTXOID,ObjectIdGetDatum(statsOid));
@@ -564,6 +558,19 @@ RemoveStatisticsById(Oid statsOid)
564558
ReleaseSysCache(tup);
565559

566560
table_close(relation,RowExclusiveLock);
561+
}
562+
563+
/*
564+
* Guts of statistics object deletion.
565+
*/
566+
void
567+
RemoveStatisticsById(OidstatsOid)
568+
{
569+
Relationrelation;
570+
Relationrel;
571+
HeapTupletup;
572+
Form_pg_statistic_extstatext;
573+
Oidrelid;
567574

568575
/*
569576
* Delete the pg_statistic_ext tuple. Also send out a cache inval on the
@@ -579,12 +586,24 @@ RemoveStatisticsById(Oid statsOid)
579586
statext= (Form_pg_statistic_ext)GETSTRUCT(tup);
580587
relid=statext->stxrelid;
581588

589+
/*
590+
* Delete the pg_statistic_ext_data tuple holding the actual statistical
591+
* data. We lock the user table first, to prevent other processes (e.g.
592+
* DROP STATISTICS) from removing the row concurrently.
593+
*/
594+
rel=table_open(relid,ShareUpdateExclusiveLock);
595+
596+
RemoveStatisticsDataById(statsOid);
597+
582598
CacheInvalidateRelcacheByRelid(relid);
583599

584600
CatalogTupleDelete(relation,&tup->t_self);
585601

586602
ReleaseSysCache(tup);
587603

604+
/* Keep lock until the end of the transaction. */
605+
table_close(rel,NoLock);
606+
588607
table_close(relation,RowExclusiveLock);
589608
}
590609

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp