Commit 4ccc5bd2 authored by Stephen Frost's avatar Stephen Frost

Pull in tableoid for inheiritance with rowMarks

As noted by Etsuro Fujita [1] and Dean Rasheed[2],
cb1ca4d8 changed ExecBuildAuxRowMark()
to always look for the tableoid in the target list, but didn't also
change preprocess_targetlist() to always include the tableoid.  This
resulted in errors with soon-to-be-added RLS with inheritance tests,
and errors when using inheritance with foreign tables.

Authors: Etsuro Fujita and Dean Rasheed (independently)

Minor word-smithing on the comments by me.

[1] 552CF0B6.8010006@lab.ntt.co.jp
[2] CAEZATCVmFUfUOwwhnBTcgi6AquyjQ0-1fyKd0T3xBWJvn+xsFA@mail.gmail.com
parent 54a16df0
...@@ -3193,26 +3193,26 @@ select * from bar where f1 in (select f1 from foo) for update; ...@@ -3193,26 +3193,26 @@ select * from bar where f1 in (select f1 from foo) for update;
QUERY PLAN QUERY PLAN
---------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------
LockRows LockRows
Output: bar.f1, bar.f2, bar.ctid, bar.tableoid, bar.*, foo.ctid, foo.tableoid, foo.* Output: bar.f1, bar.f2, bar.ctid, bar.*, bar.tableoid, foo.ctid, foo.*, foo.tableoid
-> Hash Join -> Hash Join
Output: bar.f1, bar.f2, bar.ctid, bar.tableoid, bar.*, foo.ctid, foo.tableoid, foo.* Output: bar.f1, bar.f2, bar.ctid, bar.*, bar.tableoid, foo.ctid, foo.*, foo.tableoid
Hash Cond: (bar.f1 = foo.f1) Hash Cond: (bar.f1 = foo.f1)
-> Append -> Append
-> Seq Scan on public.bar -> Seq Scan on public.bar
Output: bar.f1, bar.f2, bar.ctid, bar.tableoid, bar.* Output: bar.f1, bar.f2, bar.ctid, bar.*, bar.tableoid
-> Foreign Scan on public.bar2 -> Foreign Scan on public.bar2
Output: bar2.f1, bar2.f2, bar2.ctid, bar2.tableoid, bar2.* Output: bar2.f1, bar2.f2, bar2.ctid, bar2.*, bar2.tableoid
Remote SQL: SELECT f1, f2, f3, ctid FROM public.loct2 FOR UPDATE Remote SQL: SELECT f1, f2, f3, ctid FROM public.loct2 FOR UPDATE
-> Hash -> Hash
Output: foo.ctid, foo.tableoid, foo.*, foo.f1 Output: foo.ctid, foo.*, foo.tableoid, foo.f1
-> HashAggregate -> HashAggregate
Output: foo.ctid, foo.tableoid, foo.*, foo.f1 Output: foo.ctid, foo.*, foo.tableoid, foo.f1
Group Key: foo.f1 Group Key: foo.f1
-> Append -> Append
-> Seq Scan on public.foo -> Seq Scan on public.foo
Output: foo.ctid, foo.tableoid, foo.*, foo.f1 Output: foo.ctid, foo.*, foo.tableoid, foo.f1
-> Foreign Scan on public.foo2 -> Foreign Scan on public.foo2
Output: foo2.ctid, foo2.tableoid, foo2.*, foo2.f1 Output: foo2.ctid, foo2.*, foo2.tableoid, foo2.f1
Remote SQL: SELECT f1, f2, f3, ctid FROM public.loct1 Remote SQL: SELECT f1, f2, f3, ctid FROM public.loct1
(22 rows) (22 rows)
...@@ -3230,26 +3230,26 @@ select * from bar where f1 in (select f1 from foo) for share; ...@@ -3230,26 +3230,26 @@ select * from bar where f1 in (select f1 from foo) for share;
QUERY PLAN QUERY PLAN
---------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------
LockRows LockRows
Output: bar.f1, bar.f2, bar.ctid, bar.tableoid, bar.*, foo.ctid, foo.tableoid, foo.* Output: bar.f1, bar.f2, bar.ctid, bar.*, bar.tableoid, foo.ctid, foo.*, foo.tableoid
-> Hash Join -> Hash Join
Output: bar.f1, bar.f2, bar.ctid, bar.tableoid, bar.*, foo.ctid, foo.tableoid, foo.* Output: bar.f1, bar.f2, bar.ctid, bar.*, bar.tableoid, foo.ctid, foo.*, foo.tableoid
Hash Cond: (bar.f1 = foo.f1) Hash Cond: (bar.f1 = foo.f1)
-> Append -> Append
-> Seq Scan on public.bar -> Seq Scan on public.bar
Output: bar.f1, bar.f2, bar.ctid, bar.tableoid, bar.* Output: bar.f1, bar.f2, bar.ctid, bar.*, bar.tableoid
-> Foreign Scan on public.bar2 -> Foreign Scan on public.bar2
Output: bar2.f1, bar2.f2, bar2.ctid, bar2.tableoid, bar2.* Output: bar2.f1, bar2.f2, bar2.ctid, bar2.*, bar2.tableoid
Remote SQL: SELECT f1, f2, f3, ctid FROM public.loct2 FOR SHARE Remote SQL: SELECT f1, f2, f3, ctid FROM public.loct2 FOR SHARE
-> Hash -> Hash
Output: foo.ctid, foo.tableoid, foo.*, foo.f1 Output: foo.ctid, foo.*, foo.tableoid, foo.f1
-> HashAggregate -> HashAggregate
Output: foo.ctid, foo.tableoid, foo.*, foo.f1 Output: foo.ctid, foo.*, foo.tableoid, foo.f1
Group Key: foo.f1 Group Key: foo.f1
-> Append -> Append
-> Seq Scan on public.foo -> Seq Scan on public.foo
Output: foo.ctid, foo.tableoid, foo.*, foo.f1 Output: foo.ctid, foo.*, foo.tableoid, foo.f1
-> Foreign Scan on public.foo2 -> Foreign Scan on public.foo2
Output: foo2.ctid, foo2.tableoid, foo2.*, foo2.f1 Output: foo2.ctid, foo2.*, foo2.tableoid, foo2.f1
Remote SQL: SELECT f1, f2, f3, ctid FROM public.loct1 Remote SQL: SELECT f1, f2, f3, ctid FROM public.loct1
(22 rows) (22 rows)
...@@ -3272,37 +3272,37 @@ update bar set f2 = f2 + 100 where f1 in (select f1 from foo); ...@@ -3272,37 +3272,37 @@ update bar set f2 = f2 + 100 where f1 in (select f1 from foo);
Foreign Update on public.bar2 Foreign Update on public.bar2
Remote SQL: UPDATE public.loct2 SET f2 = $2 WHERE ctid = $1 Remote SQL: UPDATE public.loct2 SET f2 = $2 WHERE ctid = $1
-> Hash Join -> Hash Join
Output: bar.f1, (bar.f2 + 100), bar.ctid, foo.ctid, foo.tableoid, foo.* Output: bar.f1, (bar.f2 + 100), bar.ctid, foo.ctid, foo.*, foo.tableoid
Hash Cond: (bar.f1 = foo.f1) Hash Cond: (bar.f1 = foo.f1)
-> Seq Scan on public.bar -> Seq Scan on public.bar
Output: bar.f1, bar.f2, bar.ctid Output: bar.f1, bar.f2, bar.ctid
-> Hash -> Hash
Output: foo.ctid, foo.tableoid, foo.*, foo.f1 Output: foo.ctid, foo.*, foo.tableoid, foo.f1
-> HashAggregate -> HashAggregate
Output: foo.ctid, foo.tableoid, foo.*, foo.f1 Output: foo.ctid, foo.*, foo.tableoid, foo.f1
Group Key: foo.f1 Group Key: foo.f1
-> Append -> Append
-> Seq Scan on public.foo -> Seq Scan on public.foo
Output: foo.ctid, foo.tableoid, foo.*, foo.f1 Output: foo.ctid, foo.*, foo.tableoid, foo.f1
-> Foreign Scan on public.foo2 -> Foreign Scan on public.foo2
Output: foo2.ctid, foo2.tableoid, foo2.*, foo2.f1 Output: foo2.ctid, foo2.*, foo2.tableoid, foo2.f1
Remote SQL: SELECT f1, f2, f3, ctid FROM public.loct1 Remote SQL: SELECT f1, f2, f3, ctid FROM public.loct1
-> Hash Join -> Hash Join
Output: bar2.f1, (bar2.f2 + 100), bar2.f3, bar2.ctid, foo.ctid, foo.tableoid, foo.* Output: bar2.f1, (bar2.f2 + 100), bar2.f3, bar2.ctid, foo.ctid, foo.*, foo.tableoid
Hash Cond: (bar2.f1 = foo.f1) Hash Cond: (bar2.f1 = foo.f1)
-> Foreign Scan on public.bar2 -> Foreign Scan on public.bar2
Output: bar2.f1, bar2.f2, bar2.f3, bar2.ctid Output: bar2.f1, bar2.f2, bar2.f3, bar2.ctid
Remote SQL: SELECT f1, f2, f3, ctid FROM public.loct2 FOR UPDATE Remote SQL: SELECT f1, f2, f3, ctid FROM public.loct2 FOR UPDATE
-> Hash -> Hash
Output: foo.ctid, foo.tableoid, foo.*, foo.f1 Output: foo.ctid, foo.*, foo.tableoid, foo.f1
-> HashAggregate -> HashAggregate
Output: foo.ctid, foo.tableoid, foo.*, foo.f1 Output: foo.ctid, foo.*, foo.tableoid, foo.f1
Group Key: foo.f1 Group Key: foo.f1
-> Append -> Append
-> Seq Scan on public.foo -> Seq Scan on public.foo
Output: foo.ctid, foo.tableoid, foo.*, foo.f1 Output: foo.ctid, foo.*, foo.tableoid, foo.f1
-> Foreign Scan on public.foo2 -> Foreign Scan on public.foo2
Output: foo2.ctid, foo2.tableoid, foo2.*, foo2.f1 Output: foo2.ctid, foo2.*, foo2.tableoid, foo2.f1
Remote SQL: SELECT f1, f2, f3, ctid FROM public.loct1 Remote SQL: SELECT f1, f2, f3, ctid FROM public.loct1
(37 rows) (37 rows)
......
...@@ -107,8 +107,23 @@ preprocess_targetlist(PlannerInfo *root, List *tlist) ...@@ -107,8 +107,23 @@ preprocess_targetlist(PlannerInfo *root, List *tlist)
pstrdup(resname), pstrdup(resname),
true); true);
tlist = lappend(tlist, tle); tlist = lappend(tlist, tle);
}
if (rc->allMarkTypes & (1 << ROW_MARK_COPY))
{
/* Need the whole row as a junk var */
var = makeWholeRowVar(rt_fetch(rc->rti, range_table),
rc->rti,
0,
false);
snprintf(resname, sizeof(resname), "wholerow%u", rc->rowmarkId);
tle = makeTargetEntry((Expr *) var,
list_length(tlist) + 1,
pstrdup(resname),
true);
tlist = lappend(tlist, tle);
}
/* if parent of inheritance tree, need the tableoid too */ /* If parent of inheritance tree, always fetch the tableoid too. */
if (rc->isParent) if (rc->isParent)
{ {
var = makeVar(rc->rti, var = makeVar(rc->rti,
...@@ -125,21 +140,6 @@ preprocess_targetlist(PlannerInfo *root, List *tlist) ...@@ -125,21 +140,6 @@ preprocess_targetlist(PlannerInfo *root, List *tlist)
tlist = lappend(tlist, tle); tlist = lappend(tlist, tle);
} }
} }
if (rc->allMarkTypes & (1 << ROW_MARK_COPY))
{
/* Need the whole row as a junk var */
var = makeWholeRowVar(rt_fetch(rc->rti, range_table),
rc->rti,
0,
false);
snprintf(resname, sizeof(resname), "wholerow%u", rc->rowmarkId);
tle = makeTargetEntry((Expr *) var,
list_length(tlist) + 1,
pstrdup(resname),
true);
tlist = lappend(tlist, tle);
}
}
/* /*
* If the query has a RETURNING list, add resjunk entries for any Vars * If the query has a RETURNING list, add resjunk entries for any Vars
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment