pgsql: Flatten join alias Vars before pulling up targetlist items from
От | Tom Lane |
---|---|
Тема | pgsql: Flatten join alias Vars before pulling up targetlist items from |
Дата | |
Msg-id | E1VjwYN-00005p-Kv@gemulon.postgresql.org обсуждение исходный текст |
Список | pgsql-committers |
Flatten join alias Vars before pulling up targetlist items from a subquery. pullup_replace_vars()'s decisions about whether a pulled-up replacement expression needs to be wrapped in a PlaceHolderVar depend on the assumption that what looks like a Var behaves like a Var. However, if the Var is a join alias reference, later flattening of join aliases might replace the Var with something that's not a Var at all, and should have been wrapped. To fix, do a forcible pass of flatten_join_alias_vars() on the subquery targetlist before we start to copy items out of it. We'll re-run that processing on the pulled-up expressions later, but that's harmless. Per report from Ken Tanzer; the added regression test case is based on his example. This bug has been there since the PlaceHolderVar mechanism was invented, but has escaped detection because the circumstances that trigger it are fairly narrow. You need a flattenable query underneath an outer join, which contains another flattenable query inside a join of its own, with a dangerous expression (a constant or something else non-strict) in that one's targetlist. Having seen this, I'm wondering if it wouldn't be prudent to do all alias-variable flattening earlier, perhaps even in the rewriter. But that would probably not be a back-patchable change. Branch ------ REL9_3_STABLE Details ------- http://git.postgresql.org/pg/commitdiff/6bc68af1dc29db9afc49e77f70de0dec7653c8e5 Modified Files -------------- src/backend/optimizer/prep/prepjointree.c | 12 +++++++ src/test/regress/expected/join.out | 52 +++++++++++++++++++++++++++++ src/test/regress/sql/join.sql | 31 +++++++++++++++++ 3 files changed, 95 insertions(+)
В списке pgsql-committers по дате отправления: