pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix INSERT ON CONFLICT UPDATE through a view that isn't just SEL
5+ messages / 1 participants
[nested] [flat]

* pgsql: Fix INSERT ON CONFLICT UPDATE through a view that isn't just SEL
@ 2018-08-04 23:39  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 5+ messages in thread

From: Tom Lane @ 2018-08-04 23:39 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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
------
REL9_6_STABLE

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

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(-)



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* pgsql: Fix INSERT ON CONFLICT UPDATE through a view that isn't just SEL
@ 2018-08-04 23:39  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 5+ messages in thread

From: Tom Lane @ 2018-08-04 23:39 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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
------
REL_11_STABLE

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

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(-)



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* pgsql: Fix INSERT ON CONFLICT UPDATE through a view that isn't just SEL
@ 2018-08-04 23:39  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 5+ messages in thread

From: Tom Lane @ 2018-08-04 23:39 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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(-)



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* pgsql: Fix INSERT ON CONFLICT UPDATE through a view that isn't just SEL
@ 2018-08-04 23:39  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 5+ messages in thread

From: Tom Lane @ 2018-08-04 23:39 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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
------
REL_10_STABLE

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

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(-)



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* pgsql: Fix INSERT ON CONFLICT UPDATE through a view that isn't just SEL
@ 2018-08-04 23:39  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 5+ messages in thread

From: Tom Lane @ 2018-08-04 23:39 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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
------
REL9_5_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/5ad143cda092f19760d7fb1be861ed24e724ef4d

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(-)



^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2018-08-04 23:39 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-08-04 23:39 pgsql: Fix INSERT ON CONFLICT UPDATE through a view that isn't just SEL Tom Lane <tgl@sss.pgh.pa.us>
2018-08-04 23:39 pgsql: Fix INSERT ON CONFLICT UPDATE through a view that isn't just SEL Tom Lane <tgl@sss.pgh.pa.us>
2018-08-04 23:39 pgsql: Fix INSERT ON CONFLICT UPDATE through a view that isn't just SEL Tom Lane <tgl@sss.pgh.pa.us>
2018-08-04 23:39 pgsql: Fix INSERT ON CONFLICT UPDATE through a view that isn't just SEL Tom Lane <tgl@sss.pgh.pa.us>
2018-08-04 23:39 pgsql: Fix INSERT ON CONFLICT UPDATE through a view that isn't just SEL Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox