Skip to content

Commit

Permalink
Reduce lock level for CREATE STATISTICS
Browse files Browse the repository at this point in the history
In line with other lock reductions related to planning.

Simon Riggs
  • Loading branch information
simonat2ndQuadrant committed Apr 5, 2017
1 parent 2686ee1 commit 68ea2b7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion doc/src/sgml/mvcc.sgml
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,8 @@ ERROR: could not serialize access due to read/write dependencies among transact

<para>
Acquired by <command>VACUUM</command> (without <option>FULL</option>),
<command>ANALYZE</>, <command>CREATE INDEX CONCURRENTLY</>, and
<command>ANALYZE</>, <command>CREATE INDEX CONCURRENTLY</>,
<command>CREATE STATISTICS</> and
<command>ALTER TABLE VALIDATE</command> and other
<command>ALTER TABLE</command> variants (for full details see
<xref linkend="SQL-ALTERTABLE">).
Expand Down
8 changes: 7 additions & 1 deletion src/backend/commands/statscmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,13 @@ CreateStatistics(CreateStatsStmt *stmt)
errmsg("statistics \"%s\" already exist", namestr)));
}

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

if (rel->rd_rel->relkind != RELKIND_RELATION &&
Expand Down

0 comments on commit 68ea2b7

Please sign in to comment.