Skip to content

Commit 68ea2b7

Browse files
Reduce lock level for CREATE STATISTICS
In line with other lock reductions related to planning. Simon Riggs
1 parent 2686ee1 commit 68ea2b7

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

doc/src/sgml/mvcc.sgml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,8 @@ ERROR: could not serialize access due to read/write dependencies among transact
923923

924924
<para>
925925
Acquired by <command>VACUUM</command> (without <option>FULL</option>),
926-
<command>ANALYZE</>, <command>CREATE INDEX CONCURRENTLY</>, and
926+
<command>ANALYZE</>, <command>CREATE INDEX CONCURRENTLY</>,
927+
<command>CREATE STATISTICS</> and
927928
<command>ALTER TABLE VALIDATE</command> and other
928929
<command>ALTER TABLE</command> variants (for full details see
929930
<xref linkend="SQL-ALTERTABLE">).

src/backend/commands/statscmds.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,13 @@ CreateStatistics(CreateStatsStmt *stmt)
9696
errmsg("statistics \"%s\" already exist", namestr)));
9797
}
9898

99-
rel = heap_openrv(stmt->relation, AccessExclusiveLock);
99+
/*
100+
* CREATE STATISTICS will influence future execution plans but does
101+
* not interfere with currently executing plans so it is safe to
102+
* take only ShareUpdateExclusiveLock on relation, conflicting with
103+
* ANALYZE and other DDL that sets statistical information.
104+
*/
105+
rel = heap_openrv(stmt->relation, ShareUpdateExclusiveLock);
100106
relid = RelationGetRelid(rel);
101107

102108
if (rel->rd_rel->relkind != RELKIND_RELATION &&

0 commit comments

Comments
 (0)