Reduce lock level for CREATE STATISTICS
authorSimon Riggs <simon@2ndQuadrant.com>
Wed, 5 Apr 2017 22:22:32 +0000 (18:22 -0400)
committerSimon Riggs <simon@2ndQuadrant.com>
Wed, 5 Apr 2017 22:22:32 +0000 (18:22 -0400)
In line with other lock reductions related to planning.

Simon Riggs

doc/src/sgml/mvcc.sgml
src/backend/commands/statscmds.c

index 82e69fe2d277e9fb58e3347b02bf4f33a342b0ca..7aa32932fab129639f81578d9decfd9907a18ab4 100644 (file)
@@ -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">).
index 8d483dbb3a7cc3ce17631a687d0080a50261a9cc..46abadcc811f753242d0eb870c0a130dd5ff40be 100644 (file)
@@ -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 &&