Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita195e3c

Browse files
committed
Finish disabling reduced-lock-levels-for-DDL feature.
Previous patch only covered the ALTER TABLE changes, not changes in othercommands; and it neglected to revert the documentation changes.
1 parent928408d commita195e3c

File tree

4 files changed

+24
-32
lines changed

4 files changed

+24
-32
lines changed

‎doc/src/sgml/mvcc.sgml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -878,9 +878,8 @@ ERROR: could not serialize access due to read/write dependencies among transact
878878
</para>
879879

880880
<para>
881-
Acquired by <command>CREATE TRIGGER</command>,
882-
<command>CREATE RULE</command> (except for <literal>ON SELECT</>
883-
rules) and some forms of <command>ALTER TABLE</command>.
881+
This lock mode is not automatically acquired by any
882+
<productname>PostgreSQL</productname> command.
884883
</para>
885884
</listitem>
886885
</varlistentry>
@@ -925,10 +924,10 @@ ERROR: could not serialize access due to read/write dependencies among transact
925924
</para>
926925

927926
<para>
928-
Acquired by the <command>DROP TABLE</command>,
927+
Acquired by the <command>ALTER TABLE</>, <command>DROP TABLE</>,
929928
<command>TRUNCATE</command>, <command>REINDEX</command>,
930929
<command>CLUSTER</command>, and <command>VACUUM FULL</command>
931-
commands, and some forms of <command>ALTER TABLE</>.
930+
commands.
932931
This is also the default lock mode for <command>LOCK TABLE</command>
933932
statements that do not specify a mode explicitly.
934933
</para>

‎src/backend/commands/tablecmds.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3425,14 +3425,12 @@ ATRewriteTables(List **wqueue, LOCKMODE lockmode)
34253425
Relationrefrel;
34263426

34273427
if (rel==NULL)
3428+
{
34283429
/* Long since locked, no need for another */
34293430
rel=heap_open(tab->relid,NoLock);
3431+
}
34303432

3431-
/*
3432-
* We're adding a trigger to both tables, so the lock level
3433-
* here should sensibly reflect that.
3434-
*/
3435-
refrel=heap_open(con->refrelid,ShareRowExclusiveLock);
3433+
refrel=heap_open(con->refrelid,RowShareLock);
34363434

34373435
validateForeignKeyConstraint(fkconstraint->conname,rel,refrel,
34383436
con->refindid,
@@ -5529,7 +5527,14 @@ ATAddForeignKeyConstraint(AlteredTableInfo *tab, Relation rel,
55295527
OidindexOid;
55305528
OidconstrOid;
55315529

5532-
pkrel=heap_openrv(fkconstraint->pktable,lockmode);
5530+
/*
5531+
* Grab an exclusive lock on the pk table, so that someone doesn't delete
5532+
* rows out from under us. (Although a lesser lock would do for that
5533+
* purpose, we'll need exclusive lock anyway to add triggers to the pk
5534+
* table; trying to start with a lesser lock will just create a risk of
5535+
* deadlock.)
5536+
*/
5537+
pkrel=heap_openrv(fkconstraint->pktable,AccessExclusiveLock);
55335538

55345539
/*
55355540
* Validity checks (permission checks wait till we have the column

‎src/backend/commands/trigger.c

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,7 @@ CreateTrigger(CreateTrigStmt *stmt, const char *queryString,
144144
ObjectAddressmyself,
145145
referenced;
146146

147-
/*
148-
* ShareRowExclusiveLock is sufficient to prevent concurrent write
149-
* activity to the relation, and thus to lock out any operations that
150-
* might want to fire triggers on the relation. If we had ON SELECT
151-
* triggers we would need to take an AccessExclusiveLock to add one of
152-
* those, just as we do with ON SELECT rules.
153-
*/
154-
rel=heap_openrv(stmt->relation,ShareRowExclusiveLock);
147+
rel=heap_openrv(stmt->relation,AccessExclusiveLock);
155148

156149
/*
157150
* Triggers must be on tables or views, and there are additional
@@ -481,7 +474,7 @@ CreateTrigger(CreateTrigStmt *stmt, const char *queryString,
481474
* can skip this for internally generated triggers, since the name
482475
* modification above should be sufficient.
483476
*
484-
* NOTE that this is cool only because we haveShareRowExclusiveLock on
477+
* NOTE that this is cool only because we haveAccessExclusiveLock on
485478
* the relation, so the trigger set won't be changing underneath us.
486479
*/
487480
if (!isInternal)
@@ -1085,14 +1078,11 @@ RemoveTriggerById(Oid trigOid)
10851078
elog(ERROR,"could not find tuple for trigger %u",trigOid);
10861079

10871080
/*
1088-
* Open and lock the relation the trigger belongs to. As in
1089-
* CreateTrigger, this is sufficient to lock out all operations that could
1090-
* fire or add triggers; but it would need to be revisited if we had ON
1091-
* SELECT triggers.
1081+
* Open and exclusive-lock the relation the trigger belongs to.
10921082
*/
10931083
relid= ((Form_pg_trigger)GETSTRUCT(tup))->tgrelid;
10941084

1095-
rel=heap_open(relid,ShareRowExclusiveLock);
1085+
rel=heap_open(relid,AccessExclusiveLock);
10961086

10971087
if (rel->rd_rel->relkind!=RELKIND_RELATION&&
10981088
rel->rd_rel->relkind!=RELKIND_VIEW)

‎src/backend/rewrite/rewriteDefine.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,12 @@ DefineQueryRewrite(char *rulename,
238238
/*
239239
* If we are installing an ON SELECT rule, we had better grab
240240
* AccessExclusiveLock to ensure no SELECTs are currently running on the
241-
* event relation.For other types of rules, it is sufficient to grab
242-
* ShareRowExclusiveLock to lock out insert/update/delete actions and to
243-
* ensure that we lock out current CREATE RULE statements.
241+
* event relation. For other types of rules, it would be sufficient to
242+
* grab ShareRowExclusiveLock to lock out insert/update/delete actions and
243+
* to ensure that we lock out current CREATE RULE statements; but because
244+
* of race conditions in access to catalog entries, we can't do that yet.
244245
*/
245-
if (event_type==CMD_SELECT)
246-
event_relation=heap_open(event_relid,AccessExclusiveLock);
247-
else
248-
event_relation=heap_open(event_relid,ShareRowExclusiveLock);
246+
event_relation=heap_open(event_relid,AccessExclusiveLock);
249247

250248
/*
251249
* Verify relation is of a type that rules can sensibly be applied to.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp