pgsql: Fix INSERT ON CONFLICT UPDATE through a view that isn't justSEL

Поиск
Список
Период
Сортировка
От Tom Lane
Тема pgsql: Fix INSERT ON CONFLICT UPDATE through a view that isn't justSEL
Дата
Msg-id E1fm68p-0006wt-Lo@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Fix INSERT ON CONFLICT UPDATE through a view that isn't just SELECT *.

When expanding an updatable view that is an INSERT's target, the rewriter
failed to rewrite Vars in the ON CONFLICT UPDATE clause.  This accidentally
worked if the view was just "SELECT * FROM ...", as the transformation
would be a no-op in that case.  With more complicated view targetlists,
this omission would often lead to "attribute ... has the wrong type" errors
or even crashes, as reported by Mario De Frutos Dieguez.

Fix by adding code to rewriteTargetView to fix up the data structure
correctly.  The easiest way to update the exclRelTlist list is to rebuild
it from scratch looking at the new target relation, so factor the code
for that out of transformOnConflictClause to make it sharable.

In passing, avoid duplicate permissions checks against the EXCLUDED
pseudo-relation, and prevent useless view expansion of that relation's
dummy RTE.  The latter is only known to happen (after this patch) in cases
where the query would fail later due to not having any INSTEAD OF triggers
for the view.  But by exactly that token, it would create an unintended
and very poorly tested state of the query data structure, so it seems like
a good idea to prevent it from happening at all.

This has been broken since ON CONFLICT was introduced, so back-patch
to 9.5.

Dean Rasheed, based on an earlier patch by Amit Langote;
comment-kibitzing and back-patching by me

Discussion: https://postgr.es/m/CAFYwGJ0xfzy8jaK80hVN2eUWr6huce0RU8AgU04MGD00igqkTg@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/b8a1247a34e234be6becf7f70b9f1e8e9369db64

Modified Files
--------------
src/backend/parser/analyze.c                  | 136 ++++++++++--------
src/backend/rewrite/rewriteHandler.c          | 103 +++++++++++++-
src/include/parser/analyze.h                  |   3 +
src/test/regress/expected/updatable_views.out | 194 ++++++++++++++++++++++++++
src/test/regress/sql/updatable_views.sql      | 135 ++++++++++++++++++
5 files changed, 514 insertions(+), 57 deletions(-)


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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: pgsql: Address set of issues with errno handling
Следующее
От: Tom Lane
Дата:
Сообщение: pgsql: Update version 11 release notes.