diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2005-04-28 21:47:18 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2005-04-28 21:47:18 +0000 |
commit | bedb78d386a47fd66b6cda2040e0a5fb545ee371 (patch) | |
tree | 0db0af8556ff82d94423e8e21362900afb18b7b6 /src/backend/utils/adt | |
parent | d902e7d63ba2dc9cf0a1b051b2911b96831ef227 (diff) | |
download | postgresql-bedb78d386a47fd66b6cda2040e0a5fb545ee371.tar.gz postgresql-bedb78d386a47fd66b6cda2040e0a5fb545ee371.zip |
Implement sharable row-level locks, and use them for foreign key references
to eliminate unnecessary deadlocks. This commit adds SELECT ... FOR SHARE
paralleling SELECT ... FOR UPDATE. The implementation uses a new SLRU
data structure (managed much like pg_subtrans) to represent multiple-
transaction-ID sets. When more than one transaction is holding a shared
lock on a particular row, we create a MultiXactId representing that set
of transactions and store its ID in the row's XMAX. This scheme allows
an effectively unlimited number of row locks, just as we did before,
while not costing any extra overhead except when a shared lock actually
has to be shared. Still TODO: use the regular lock manager to control
the grant order when multiple backends are waiting for a row lock.
Alvaro Herrera and Tom Lane.
Diffstat (limited to 'src/backend/utils/adt')
-rw-r--r-- | src/backend/utils/adt/ri_triggers.c | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/src/backend/utils/adt/ri_triggers.c b/src/backend/utils/adt/ri_triggers.c index 72ae3b8ddea..78a85b7edcc 100644 --- a/src/backend/utils/adt/ri_triggers.c +++ b/src/backend/utils/adt/ri_triggers.c @@ -17,7 +17,7 @@ * * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/backend/utils/adt/ri_triggers.c,v 1.76 2004/12/31 22:01:22 pgsql Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/ri_triggers.c,v 1.77 2005/04/28 21:47:15 tgl Exp $ * * ---------- */ @@ -206,7 +206,7 @@ RI_FKey_check(PG_FUNCTION_ARGS) * tuple. * * pk_rel is opened in RowShareLock mode since that's what our eventual - * SELECT FOR UPDATE will get on it. + * SELECT FOR SHARE will get on it. */ pk_rel = heap_open(trigdata->tg_trigger->tgconstrrelid, RowShareLock); fk_rel = trigdata->tg_relation; @@ -267,7 +267,7 @@ RI_FKey_check(PG_FUNCTION_ARGS) * ---------- */ quoteRelationName(pkrelname, pk_rel); - snprintf(querystr, sizeof(querystr), "SELECT 1 FROM ONLY %s x FOR UPDATE OF x", + snprintf(querystr, sizeof(querystr), "SELECT 1 FROM ONLY %s x FOR SHARE OF x", pkrelname); /* Prepare and save the plan */ @@ -428,7 +428,7 @@ RI_FKey_check(PG_FUNCTION_ARGS) queryoids[i] = SPI_gettypeid(fk_rel->rd_att, qkey.keypair[i][RI_KEYPAIR_FK_IDX]); } - strcat(querystr, " FOR UPDATE OF x"); + strcat(querystr, " FOR SHARE OF x"); /* Prepare and save the plan */ qplan = ri_PlanCheck(querystr, qkey.nkeypairs, queryoids, @@ -590,7 +590,7 @@ ri_Check_Pk_Match(Relation pk_rel, Relation fk_rel, queryoids[i] = SPI_gettypeid(pk_rel->rd_att, qkey.keypair[i][RI_KEYPAIR_PK_IDX]); } - strcat(querystr, " FOR UPDATE OF x"); + strcat(querystr, " FOR SHARE OF x"); /* Prepare and save the plan */ qplan = ri_PlanCheck(querystr, qkey.nkeypairs, queryoids, @@ -655,7 +655,7 @@ RI_FKey_noaction_del(PG_FUNCTION_ARGS) * tuple. * * fk_rel is opened in RowShareLock mode since that's what our eventual - * SELECT FOR UPDATE will get on it. + * SELECT FOR SHARE will get on it. */ fk_rel = heap_open(trigdata->tg_trigger->tgconstrrelid, RowShareLock); pk_rel = trigdata->tg_relation; @@ -748,7 +748,7 @@ RI_FKey_noaction_del(PG_FUNCTION_ARGS) queryoids[i] = SPI_gettypeid(pk_rel->rd_att, qkey.keypair[i][RI_KEYPAIR_PK_IDX]); } - strcat(querystr, " FOR UPDATE OF x"); + strcat(querystr, " FOR SHARE OF x"); /* Prepare and save the plan */ qplan = ri_PlanCheck(querystr, qkey.nkeypairs, queryoids, @@ -834,7 +834,7 @@ RI_FKey_noaction_upd(PG_FUNCTION_ARGS) * and old tuple. * * fk_rel is opened in RowShareLock mode since that's what our eventual - * SELECT FOR UPDATE will get on it. + * SELECT FOR SHARE will get on it. */ fk_rel = heap_open(trigdata->tg_trigger->tgconstrrelid, RowShareLock); pk_rel = trigdata->tg_relation; @@ -939,7 +939,7 @@ RI_FKey_noaction_upd(PG_FUNCTION_ARGS) queryoids[i] = SPI_gettypeid(pk_rel->rd_att, qkey.keypair[i][RI_KEYPAIR_PK_IDX]); } - strcat(querystr, " FOR UPDATE OF x"); + strcat(querystr, " FOR SHARE OF x"); /* Prepare and save the plan */ qplan = ri_PlanCheck(querystr, qkey.nkeypairs, queryoids, @@ -1373,7 +1373,7 @@ RI_FKey_restrict_del(PG_FUNCTION_ARGS) * tuple. * * fk_rel is opened in RowShareLock mode since that's what our eventual - * SELECT FOR UPDATE will get on it. + * SELECT FOR SHARE will get on it. */ fk_rel = heap_open(trigdata->tg_trigger->tgconstrrelid, RowShareLock); pk_rel = trigdata->tg_relation; @@ -1453,7 +1453,7 @@ RI_FKey_restrict_del(PG_FUNCTION_ARGS) queryoids[i] = SPI_gettypeid(pk_rel->rd_att, qkey.keypair[i][RI_KEYPAIR_PK_IDX]); } - strcat(querystr, " FOR UPDATE OF x"); + strcat(querystr, " FOR SHARE OF x"); /* Prepare and save the plan */ qplan = ri_PlanCheck(querystr, qkey.nkeypairs, queryoids, @@ -1543,7 +1543,7 @@ RI_FKey_restrict_upd(PG_FUNCTION_ARGS) * and old tuple. * * fk_rel is opened in RowShareLock mode since that's what our eventual - * SELECT FOR UPDATE will get on it. + * SELECT FOR SHARE will get on it. */ fk_rel = heap_open(trigdata->tg_trigger->tgconstrrelid, RowShareLock); pk_rel = trigdata->tg_relation; @@ -1634,7 +1634,7 @@ RI_FKey_restrict_upd(PG_FUNCTION_ARGS) queryoids[i] = SPI_gettypeid(pk_rel->rd_att, qkey.keypair[i][RI_KEYPAIR_PK_IDX]); } - strcat(querystr, " FOR UPDATE OF x"); + strcat(querystr, " FOR SHARE OF x"); /* Prepare and save the plan */ qplan = ri_PlanCheck(querystr, qkey.nkeypairs, queryoids, |