pgsql: Fix rewriter to cope (more or less) with CTEs in the query being

Поиск
Список
Период
Сортировка
От Tom Lane
Тема pgsql: Fix rewriter to cope (more or less) with CTEs in the query being
Дата
Msg-id E1QTnbL-0005Wz-TN@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Fix rewriter to cope (more or less) with CTEs in the query being rewritten.

Since the original implementation of CTEs only allowed them in SELECT
queries, the rule rewriter did not expect to find any CTEs in statements
being rewritten by ON INSERT/UPDATE/DELETE rules.  We had dealt with this
to some extent but the code was still several bricks shy of a load, as
illustrated in bug #6051 from Jehan-Guillaume de Rorthais.

In particular, we have to be able to copy CTEs from the original query's
cteList into that of a rule action, in case the rule action references the
CTE (which it pretty much always will).  This also implies we were doing
things in the wrong order in RewriteQuery: we have to recursively rewrite
the CTE queries before expanding the main query, so that we have the
rewritten queries available to copy.

There are unpleasant limitations yet to resolve here, but at least we now
throw understandable FEATURE_NOT_SUPPORTED errors for them instead of just
failing with bizarre implementation-dependent errors.  In particular, we
can't handle propagating the same CTE into multiple post-rewrite queries
(because then the CTE would be evaluated multiple times), and we can't cope
with conflicts between CTE names in the original query and in the rule
actions.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/fc1286d3cb92adad2eae69924bead12cfeea5cc6

Modified Files
--------------
src/backend/rewrite/rewriteHandler.c |  187 +++++++++++++++++++++++-----------
src/test/regress/expected/with.out   |   40 +++++++
src/test/regress/sql/with.sql        |   23 ++++
3 files changed, 189 insertions(+), 61 deletions(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: pgsql: Make decompilation of optimized CASE constructs more robust.
Следующее
От: Heikki Linnakangas
Дата:
Сообщение: pgsql: Make ascii-art in comments pgindent-safe, and some other formatt