提交 8e617e29 编写于 作者: T Tom Lane

Fix whole-row Var evaluation to cope with resjunk columns (again).

When a whole-row Var is reading the result of a subquery, we need it to
ignore any "resjunk" columns that the subquery might have evaluated for
GROUP BY or ORDER BY purposes.  We've hacked this area before, in commit
68e40998, but that fix only covered
whole-row Vars of named composite types, not those of RECORD type; and it
was mighty klugy anyway, since it just assumed without checking that any
extra columns in the result must be resjunk.  A proper fix requires getting
hold of the subquery's targetlist so we can actually see which columns are
resjunk (whereupon we can use a JunkFilter to get rid of them).  So bite
the bullet and add some infrastructure to make that possible.

Per report from Andrew Dunstan and additional testing by Merlin Moncure.
Back-patch to all supported branches.  In 8.3, also back-patch commit
292176a1, which for some reason I had
not done at the time, but it's a prerequisite for this change.
上级 3a0e4d36
此差异已折叠。
......@@ -524,8 +524,8 @@ ExecBuildProjectionInfo(List *targetList,
* We separate the target list elements into simple Var references and
* expressions which require the full ExecTargetList machinery. To be a
* simple Var, a Var has to be a user attribute and not mismatch the
* inputDesc. (Note: if there is a type mismatch then ExecEvalVar will
* probably throw an error at runtime, but we leave that to it.)
* inputDesc. (Note: if there is a type mismatch then ExecEvalScalarVar
* will probably throw an error at runtime, but we leave that to it.)
*/
exprlist = NIL;
numSimpleVars = 0;
......
......@@ -560,6 +560,17 @@ typedef struct GenericExprState
ExprState *arg; /* state of my child node */
} GenericExprState;
/* ----------------
* WholeRowVarExprState node
* ----------------
*/
typedef struct WholeRowVarExprState
{
ExprState xprstate;
struct PlanState *parent; /* parent PlanState, or NULL if none */
JunkFilter *wrv_junkFilter; /* JunkFilter to remove resjunk cols */
} WholeRowVarExprState;
/* ----------------
* AggrefExprState node
* ----------------
......
......@@ -180,6 +180,7 @@ typedef enum NodeTag
*/
T_ExprState = 400,
T_GenericExprState,
T_WholeRowVarExprState,
T_AggrefExprState,
T_WindowFuncExprState,
T_ArrayRefExprState,
......
......@@ -504,6 +504,31 @@ select (select (a.*)::text) from view_a a;
(42)
(1 row)
--
-- Check that whole-row Vars reading the result of a subselect don't include
-- any junk columns therein
--
select q from (select max(f1) from int4_tbl group by f1 order by f1) q;
q
---------------
(-2147483647)
(-123456)
(0)
(123456)
(2147483647)
(5 rows)
with q as (select max(f1) from int4_tbl group by f1 order by f1)
select q from q;
q
---------------
(-2147483647)
(-123456)
(0)
(123456)
(2147483647)
(5 rows)
--
-- Test case for sublinks pushed down into subselects via join alias expansion
--
......
......@@ -324,6 +324,15 @@ select (select view_a) from view_a;
select (select (select view_a)) from view_a;
select (select (a.*)::text) from view_a a;
--
-- Check that whole-row Vars reading the result of a subselect don't include
-- any junk columns therein
--
select q from (select max(f1) from int4_tbl group by f1 order by f1) q;
with q as (select max(f1) from int4_tbl group by f1 order by f1)
select q from q;
--
-- Test case for sublinks pushed down into subselects via join alias expansion
--
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册