diff options
author | Simon Riggs <simon@2ndQuadrant.com> | 2014-04-06 11:13:43 -0400 |
---|---|---|
committer | Simon Riggs <simon@2ndQuadrant.com> | 2014-04-06 11:13:43 -0400 |
commit | e5550d5fec66aa74caad1f79b79826ec64898688 (patch) | |
tree | 046444c974bf3aa9833545c0b9bbc183c37dbfa1 /src/backend/utils/adt/ruleutils.c | |
parent | 80a5cf643adb496abe577a1ca6dc0c476d849c19 (diff) | |
download | postgresql-e5550d5fec66aa74caad1f79b79826ec64898688.tar.gz postgresql-e5550d5fec66aa74caad1f79b79826ec64898688.zip |
Reduce lock levels of some ALTER TABLE cmds
VALIDATE CONSTRAINT
CLUSTER ON
SET WITHOUT CLUSTER
ALTER COLUMN SET STATISTICS
ALTER COLUMN SET ()
ALTER COLUMN RESET ()
All other sub-commands use AccessExclusiveLock
Simon Riggs and Noah Misch
Reviews by Robert Haas and Andres Freund
Diffstat (limited to 'src/backend/utils/adt/ruleutils.c')
-rw-r--r-- | src/backend/utils/adt/ruleutils.c | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index b1bac866aa1..ea7b8c59429 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -54,6 +54,7 @@ #include "utils/fmgroids.h" #include "utils/lsyscache.h" #include "utils/rel.h" +#include "utils/snapmgr.h" #include "utils/syscache.h" #include "utils/tqual.h" #include "utils/typcache.h" @@ -1284,6 +1285,9 @@ pg_get_constraintdef_string(Oid constraintId) return pg_get_constraintdef_worker(constraintId, true, 0); } +/* + * As of 9.4, we now use an MVCC snapshot for this. + */ static char * pg_get_constraintdef_worker(Oid constraintId, bool fullCommand, int prettyFlags) @@ -1291,10 +1295,34 @@ pg_get_constraintdef_worker(Oid constraintId, bool fullCommand, HeapTuple tup; Form_pg_constraint conForm; StringInfoData buf; + SysScanDesc scandesc; + ScanKeyData scankey[1]; + Snapshot snapshot = RegisterSnapshot(GetTransactionSnapshot()); + Relation relation = heap_open(ConstraintRelationId, AccessShareLock); + + ScanKeyInit(&scankey[0], + ObjectIdAttributeNumber, + BTEqualStrategyNumber, F_OIDEQ, + ObjectIdGetDatum(constraintId)); + + scandesc = systable_beginscan(relation, + ConstraintOidIndexId, + true, + snapshot, + 1, + scankey); + + /* + * We later use the tuple with SysCacheGetAttr() as if we + * had obtained it via SearchSysCache, which works fine. + */ + tup = systable_getnext(scandesc); + + UnregisterSnapshot(snapshot); - tup = SearchSysCache1(CONSTROID, ObjectIdGetDatum(constraintId)); if (!HeapTupleIsValid(tup)) /* should not happen */ elog(ERROR, "cache lookup failed for constraint %u", constraintId); + conForm = (Form_pg_constraint) GETSTRUCT(tup); initStringInfo(&buf); @@ -1575,7 +1603,8 @@ pg_get_constraintdef_worker(Oid constraintId, bool fullCommand, appendStringInfoString(&buf, " NOT VALID"); /* Cleanup */ - ReleaseSysCache(tup); + systable_endscan(scandesc); + heap_close(relation, AccessShareLock); return buf.data; } |