create_statistics_lock_reduction.v1.patch
application/octet-stream
Filename: create_statistics_lock_reduction.v1.patch
Type: application/octet-stream
Part: 0
Message:
Re: multivariate statistics (v25)
Patch
Format: unified
Series: patch v1
| File | + | − |
|---|---|---|
| doc/src/sgml/mvcc.sgml | 2 | 1 |
| src/backend/commands/statscmds.c | 7 | 1 |
diff --git a/doc/src/sgml/mvcc.sgml b/doc/src/sgml/mvcc.sgml
index 82e69fe2d2..7aa32932fa 100644
--- a/doc/src/sgml/mvcc.sgml
+++ b/doc/src/sgml/mvcc.sgml
@@ -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">).
diff --git a/src/backend/commands/statscmds.c b/src/backend/commands/statscmds.c
index 0750329961..c11a04d097 100644
--- a/src/backend/commands/statscmds.c
+++ b/src/backend/commands/statscmds.c
@@ -95,7 +95,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 &&