Fix up ruleutils.c for CTE features. The main problem was that
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 6 Oct 2008 20:29:38 +0000 (20:29 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 6 Oct 2008 20:29:38 +0000 (20:29 +0000)
commit8e235d36386f86789d97ce51fb645a9f515e0ec6
tree94a738af6b394d88faffcab2f4ddc3c6fffa9faa
parentc0a1b283e78221a2486f3c6fc072c055b1ba53d6
Fix up ruleutils.c for CTE features.  The main problem was that
get_name_for_var_field didn't have enough context to interpret a reference to
a CTE query's output.  Fixing this requires separate hacks for the regular
deparse case (pg_get_ruledef) and for the EXPLAIN case, since the available
context information is quite different.  It's pretty nearly parallel to the
existing code for SUBQUERY RTEs, though.  Also, add code to make sure we
qualify a relation name that matches a CTE name; else the CTE will mistakenly
capture the reference when reloading the rule.

In passing, fix a pre-existing problem with get_name_for_var_field not working
on variables in targetlists of SubqueryScan plan nodes.  Although latent all
along, this wasn't a problem until we made EXPLAIN VERBOSE try to print
targetlists.  To do this, refactor the deparse_context_for_plan API so that
the special case for SubqueryScan is all on ruleutils.c's side.
src/backend/commands/explain.c
src/backend/utils/adt/ruleutils.c
src/include/utils/builtins.h