Preserve Var location information during flatten_join_alias_vars.

This allows us to give correct syntax error pointers when complaining
about ungrouped variables in a join query with aggregates or GROUP BY.
It's pretty much irrelevant for the planner's use of the function, though
perhaps it might aid debugging sometimes.
This commit is contained in:
Tom Lane 2011-11-01 22:13:11 -04:00
parent 08e261cbc9
commit 391af9f784
1 changed files with 10 additions and 7 deletions

View File

@ -794,16 +794,17 @@ flatten_join_alias_vars_mutator(Node *node,
/* Ignore dropped columns */ /* Ignore dropped columns */
if (IsA(newvar, Const)) if (IsA(newvar, Const))
continue; continue;
newvar = copyObject(newvar);
/* /*
* If we are expanding an alias carried down from an upper * If we are expanding an alias carried down from an upper
* query, must adjust its varlevelsup fields. * query, must adjust its varlevelsup fields.
*/ */
if (context->sublevels_up != 0) if (context->sublevels_up != 0)
{
newvar = copyObject(newvar);
IncrementVarSublevelsUp(newvar, context->sublevels_up, 0); IncrementVarSublevelsUp(newvar, context->sublevels_up, 0);
} /* Preserve original Var's location, if possible */
if (IsA(newvar, Var))
((Var *) newvar)->location = var->location;
/* Recurse in case join input is itself a join */ /* Recurse in case join input is itself a join */
/* (also takes care of setting inserted_sublink if needed) */ /* (also takes care of setting inserted_sublink if needed) */
newvar = flatten_join_alias_vars_mutator(newvar, context); newvar = flatten_join_alias_vars_mutator(newvar, context);
@ -814,7 +815,7 @@ flatten_join_alias_vars_mutator(Node *node,
rowexpr->row_typeid = var->vartype; rowexpr->row_typeid = var->vartype;
rowexpr->row_format = COERCE_IMPLICIT_CAST; rowexpr->row_format = COERCE_IMPLICIT_CAST;
rowexpr->colnames = NIL; rowexpr->colnames = NIL;
rowexpr->location = -1; rowexpr->location = var->location;
return (Node *) rowexpr; return (Node *) rowexpr;
} }
@ -822,16 +823,18 @@ flatten_join_alias_vars_mutator(Node *node,
/* Expand join alias reference */ /* Expand join alias reference */
Assert(var->varattno > 0); Assert(var->varattno > 0);
newvar = (Node *) list_nth(rte->joinaliasvars, var->varattno - 1); newvar = (Node *) list_nth(rte->joinaliasvars, var->varattno - 1);
newvar = copyObject(newvar);
/* /*
* If we are expanding an alias carried down from an upper query, must * If we are expanding an alias carried down from an upper query, must
* adjust its varlevelsup fields. * adjust its varlevelsup fields.
*/ */
if (context->sublevels_up != 0) if (context->sublevels_up != 0)
{
newvar = copyObject(newvar);
IncrementVarSublevelsUp(newvar, context->sublevels_up, 0); IncrementVarSublevelsUp(newvar, context->sublevels_up, 0);
}
/* Preserve original Var's location, if possible */
if (IsA(newvar, Var))
((Var *) newvar)->location = var->location;
/* Recurse in case join input is itself a join */ /* Recurse in case join input is itself a join */
newvar = flatten_join_alias_vars_mutator(newvar, context); newvar = flatten_join_alias_vars_mutator(newvar, context);