aboutsummaryrefslogtreecommitdiff
path: root/src/backend/optimizer/prep/preptlist.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2008-11-15 19:43:47 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2008-11-15 19:43:47 +0000
commit0656ed3daa29b00c7c41ad44b407a7165f83d453 (patch)
tree2167bd78fa501c3ffed1d0de842ded643c32500b /src/backend/optimizer/prep/preptlist.c
parent07c179a82b39ffbc172175382717706d90c714cd (diff)
downloadpostgresql-0656ed3daa29b00c7c41ad44b407a7165f83d453.tar.gz
postgresql-0656ed3daa29b00c7c41ad44b407a7165f83d453.zip
Make SELECT FOR UPDATE/SHARE work on inheritance trees, by having the plan
return the tableoid as well as the ctid for any FOR UPDATE targets that have child tables. All child tables are listed in the ExecRowMark list, but the executor just skips the ones that didn't produce the current row. Curiously, this longstanding restriction doesn't seem to have been documented anywhere; so no doc changes.
Diffstat (limited to 'src/backend/optimizer/prep/preptlist.c')
-rw-r--r--src/backend/optimizer/prep/preptlist.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/backend/optimizer/prep/preptlist.c b/src/backend/optimizer/prep/preptlist.c
index 2861125212f..e04e7067664 100644
--- a/src/backend/optimizer/prep/preptlist.c
+++ b/src/backend/optimizer/prep/preptlist.c
@@ -16,7 +16,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/prep/preptlist.c,v 1.93 2008/11/02 01:45:28 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/prep/preptlist.c,v 1.94 2008/11/15 19:43:46 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -138,6 +138,11 @@ preprocess_targetlist(PlannerInfo *root, List *tlist)
char *resname;
TargetEntry *tle;
+ /* ignore child rels */
+ if (rc->rti != rc->prti)
+ continue;
+
+ /* always need the ctid */
var = makeVar(rc->rti,
SelfItemPointerAttributeNumber,
TIDOID,
@@ -153,6 +158,26 @@ preprocess_targetlist(PlannerInfo *root, List *tlist)
true);
tlist = lappend(tlist, tle);
+
+ /* if parent of inheritance tree, need the tableoid too */
+ if (rc->isParent)
+ {
+ var = makeVar(rc->rti,
+ TableOidAttributeNumber,
+ OIDOID,
+ -1,
+ 0);
+
+ resname = (char *) palloc(32);
+ snprintf(resname, 32, "tableoid%u", rc->rti);
+
+ tle = makeTargetEntry((Expr *) var,
+ list_length(tlist) + 1,
+ resname,
+ true);
+
+ tlist = lappend(tlist, tle);
+ }
}
}