pgsql: Fix several bugs related to ON CONFLICT's EXCLUDED pseudo relati

Поиск
Список
Период
Сортировка
От Andres Freund
Тема pgsql: Fix several bugs related to ON CONFLICT's EXCLUDED pseudo relati
Дата
Msg-id E1ZiMdz-0001KZ-0O@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Fix several bugs related to ON CONFLICT's EXCLUDED pseudo relation.

Four related issues:

1) attnos/varnos/resnos for EXCLUDED were out of sync when a column
   after one dropped in the underlying relation was referenced.
2) References to whole-row variables (i.e. EXCLUDED.*) lead to errors.
3) It was possible to reference system columns in the EXCLUDED pseudo
   relations, even though they would not have valid contents.
4) References to EXCLUDED were rewritten by the RLS machinery, as
   EXCLUDED was treated as if it were the underlying relation.

To fix the first two issues, generate the excluded targetlist with
dropped columns in mind and add an entry for whole row
variables. Instead of unconditionally adding a wholerow entry we could
pull up the expression if needed, but doing it unconditionally seems
simpler. The wholerow entry is only really needed for ruleutils/EXPLAIN
support anyway.

The remaining two issues are addressed by changing the EXCLUDED RTE to
have relkind = composite. That fits with EXCLUDED not actually being a
real relation, and allows to treat it differently in the relevant
places. scanRTEForColumn now skips looking up system columns when the
RTE has a composite relkind; fireRIRrules() already had a corresponding
check, thereby preventing RLS expansion on EXCLUDED.

Also add tests for these issues, and improve a few comments around
excluded handling in setrefs.c.

Reported-By: Peter Geoghegan, Geoff Winkless
Author: Andres Freund, Amit Langote, Peter Geoghegan
Discussion: CAEzk6fdzJ3xYQZGbcuYM2rBd2BuDkUksmK=mY9UYYDugg_GgZg@mail.gmail.com,
   CAM3SWZS+CauzbiCEcg-GdE6K6ycHE_Bz6Ksszy8AoixcMHOmsA@mail.gmail.com
Backpatch: 9.5, where ON CONFLICT was introduced

Branch
------
REL9_5_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/7285d66494a4c588ccf743a81f93b85b6995214f

Modified Files
--------------
src/backend/optimizer/plan/setrefs.c          |   29 +++---
src/backend/parser/analyze.c                  |   76 +++++++++++++---
src/backend/parser/parse_relation.c           |    7 +-
src/test/regress/expected/insert_conflict.out |  121 +++++++++++++++++++++++++
src/test/regress/expected/rules.out           |   18 ++--
src/test/regress/sql/insert_conflict.sql      |   68 ++++++++++++++
src/test/regress/sql/rules.sql                |    2 +-
7 files changed, 283 insertions(+), 38 deletions(-)


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

Предыдущее
От: Andres Freund
Дата:
Сообщение: pgsql: Fix several bugs related to ON CONFLICT's EXCLUDED pseudo relati
Следующее
От: Andres Freund
Дата:
Сообщение: pgsql: Improve errhint() about replication slot naming restrictions.