pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Fix multi-row DEFAULT handling for INSERT ... SELECT rules. 6+ messages / 1 participants [nested] [flat]
* pgsql: Fix multi-row DEFAULT handling for INSERT ... SELECT rules. @ 2023-02-23 11:01 Dean Rasheed <dean.a.rasheed@gmail.com> 0 siblings, 0 replies; 6+ messages in thread From: Dean Rasheed @ 2023-02-23 11:01 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix multi-row DEFAULT handling for INSERT ... SELECT rules. Given an updatable view with a DO ALSO INSERT ... SELECT rule, a multi-row INSERT ... VALUES query on the view fails if the VALUES list contains any DEFAULTs that are not replaced by view defaults. This manifests as an "unrecognized node type" error, or an Assert failure, in an assert-enabled build. The reason is that when RewriteQuery() attempts to replace the remaining DEFAULT items with NULLs in any product queries, using rewriteValuesRTEToNulls(), it assumes that the VALUES RTE is located at the same rangetable index in each product query. However, if the product query is an INSERT ... SELECT, then the VALUES RTE is actually in the SELECT part of that query (at the same index), rather than the top-level product query itself. Fix, by descending to the SELECT in such cases. Note that we can't simply use getInsertSelectQuery() for this, since that expects to be given a raw rule action with OLD and NEW placeholder entries, so we duplicate its logic instead. While at it, beef up the checks in getInsertSelectQuery() by checking that the jointree->fromlist node is indeed a RangeTblRef, and that the RTE it points to has rtekind == RTE_SUBQUERY. Per bug #17803, from Alexander Lakhin. Back-patch to all supported branches. Dean Rasheed, reviewed by Tom Lane. Discussion: https://postgr.es/m/17803-53c63ed4ecb4eac6%40postgresql.org Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/75c737636b8a1e9a110e580f1caee181023447e2 Modified Files -------------- src/backend/rewrite/rewriteHandler.c | 32 ++++++++++++++++++++++++--- src/backend/rewrite/rewriteManip.c | 11 +++++---- src/test/regress/expected/updatable_views.out | 19 ++++++++++++++++ src/test/regress/sql/updatable_views.sql | 10 +++++++++ 4 files changed, 65 insertions(+), 7 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix multi-row DEFAULT handling for INSERT ... SELECT rules. @ 2023-02-23 11:01 Dean Rasheed <dean.a.rasheed@gmail.com> 0 siblings, 0 replies; 6+ messages in thread From: Dean Rasheed @ 2023-02-23 11:01 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix multi-row DEFAULT handling for INSERT ... SELECT rules. Given an updatable view with a DO ALSO INSERT ... SELECT rule, a multi-row INSERT ... VALUES query on the view fails if the VALUES list contains any DEFAULTs that are not replaced by view defaults. This manifests as an "unrecognized node type" error, or an Assert failure, in an assert-enabled build. The reason is that when RewriteQuery() attempts to replace the remaining DEFAULT items with NULLs in any product queries, using rewriteValuesRTEToNulls(), it assumes that the VALUES RTE is located at the same rangetable index in each product query. However, if the product query is an INSERT ... SELECT, then the VALUES RTE is actually in the SELECT part of that query (at the same index), rather than the top-level product query itself. Fix, by descending to the SELECT in such cases. Note that we can't simply use getInsertSelectQuery() for this, since that expects to be given a raw rule action with OLD and NEW placeholder entries, so we duplicate its logic instead. While at it, beef up the checks in getInsertSelectQuery() by checking that the jointree->fromlist node is indeed a RangeTblRef, and that the RTE it points to has rtekind == RTE_SUBQUERY. Per bug #17803, from Alexander Lakhin. Back-patch to all supported branches. Dean Rasheed, reviewed by Tom Lane. Discussion: https://postgr.es/m/17803-53c63ed4ecb4eac6%40postgresql.org Branch ------ REL_15_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/940b5474365fa87ef4aad7abeee070e8e49cc9d5 Modified Files -------------- src/backend/rewrite/rewriteHandler.c | 32 ++++++++++++++++++++++++--- src/backend/rewrite/rewriteManip.c | 11 +++++---- src/test/regress/expected/updatable_views.out | 19 ++++++++++++++++ src/test/regress/sql/updatable_views.sql | 10 +++++++++ 4 files changed, 65 insertions(+), 7 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix multi-row DEFAULT handling for INSERT ... SELECT rules. @ 2023-02-23 11:01 Dean Rasheed <dean.a.rasheed@gmail.com> 0 siblings, 0 replies; 6+ messages in thread From: Dean Rasheed @ 2023-02-23 11:01 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix multi-row DEFAULT handling for INSERT ... SELECT rules. Given an updatable view with a DO ALSO INSERT ... SELECT rule, a multi-row INSERT ... VALUES query on the view fails if the VALUES list contains any DEFAULTs that are not replaced by view defaults. This manifests as an "unrecognized node type" error, or an Assert failure, in an assert-enabled build. The reason is that when RewriteQuery() attempts to replace the remaining DEFAULT items with NULLs in any product queries, using rewriteValuesRTEToNulls(), it assumes that the VALUES RTE is located at the same rangetable index in each product query. However, if the product query is an INSERT ... SELECT, then the VALUES RTE is actually in the SELECT part of that query (at the same index), rather than the top-level product query itself. Fix, by descending to the SELECT in such cases. Note that we can't simply use getInsertSelectQuery() for this, since that expects to be given a raw rule action with OLD and NEW placeholder entries, so we duplicate its logic instead. While at it, beef up the checks in getInsertSelectQuery() by checking that the jointree->fromlist node is indeed a RangeTblRef, and that the RTE it points to has rtekind == RTE_SUBQUERY. Per bug #17803, from Alexander Lakhin. Back-patch to all supported branches. Dean Rasheed, reviewed by Tom Lane. Discussion: https://postgr.es/m/17803-53c63ed4ecb4eac6%40postgresql.org Branch ------ REL_14_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/f0423bea7f0afe6ccd830e2b729180e4355e04f6 Modified Files -------------- src/backend/rewrite/rewriteHandler.c | 32 ++++++++++++++++++++++++--- src/backend/rewrite/rewriteManip.c | 11 +++++---- src/test/regress/expected/updatable_views.out | 19 ++++++++++++++++ src/test/regress/sql/updatable_views.sql | 10 +++++++++ 4 files changed, 65 insertions(+), 7 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix multi-row DEFAULT handling for INSERT ... SELECT rules. @ 2023-02-23 11:01 Dean Rasheed <dean.a.rasheed@gmail.com> 0 siblings, 0 replies; 6+ messages in thread From: Dean Rasheed @ 2023-02-23 11:01 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix multi-row DEFAULT handling for INSERT ... SELECT rules. Given an updatable view with a DO ALSO INSERT ... SELECT rule, a multi-row INSERT ... VALUES query on the view fails if the VALUES list contains any DEFAULTs that are not replaced by view defaults. This manifests as an "unrecognized node type" error, or an Assert failure, in an assert-enabled build. The reason is that when RewriteQuery() attempts to replace the remaining DEFAULT items with NULLs in any product queries, using rewriteValuesRTEToNulls(), it assumes that the VALUES RTE is located at the same rangetable index in each product query. However, if the product query is an INSERT ... SELECT, then the VALUES RTE is actually in the SELECT part of that query (at the same index), rather than the top-level product query itself. Fix, by descending to the SELECT in such cases. Note that we can't simply use getInsertSelectQuery() for this, since that expects to be given a raw rule action with OLD and NEW placeholder entries, so we duplicate its logic instead. While at it, beef up the checks in getInsertSelectQuery() by checking that the jointree->fromlist node is indeed a RangeTblRef, and that the RTE it points to has rtekind == RTE_SUBQUERY. Per bug #17803, from Alexander Lakhin. Back-patch to all supported branches. Dean Rasheed, reviewed by Tom Lane. Discussion: https://postgr.es/m/17803-53c63ed4ecb4eac6%40postgresql.org Branch ------ REL_13_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/226da3d4767083b58b9d1acf67b1402865d359bf Modified Files -------------- src/backend/rewrite/rewriteHandler.c | 32 ++++++++++++++++++++++++--- src/backend/rewrite/rewriteManip.c | 11 +++++---- src/test/regress/expected/updatable_views.out | 19 ++++++++++++++++ src/test/regress/sql/updatable_views.sql | 10 +++++++++ 4 files changed, 65 insertions(+), 7 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix multi-row DEFAULT handling for INSERT ... SELECT rules. @ 2023-02-23 11:01 Dean Rasheed <dean.a.rasheed@gmail.com> 0 siblings, 0 replies; 6+ messages in thread From: Dean Rasheed @ 2023-02-23 11:01 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix multi-row DEFAULT handling for INSERT ... SELECT rules. Given an updatable view with a DO ALSO INSERT ... SELECT rule, a multi-row INSERT ... VALUES query on the view fails if the VALUES list contains any DEFAULTs that are not replaced by view defaults. This manifests as an "unrecognized node type" error, or an Assert failure, in an assert-enabled build. The reason is that when RewriteQuery() attempts to replace the remaining DEFAULT items with NULLs in any product queries, using rewriteValuesRTEToNulls(), it assumes that the VALUES RTE is located at the same rangetable index in each product query. However, if the product query is an INSERT ... SELECT, then the VALUES RTE is actually in the SELECT part of that query (at the same index), rather than the top-level product query itself. Fix, by descending to the SELECT in such cases. Note that we can't simply use getInsertSelectQuery() for this, since that expects to be given a raw rule action with OLD and NEW placeholder entries, so we duplicate its logic instead. While at it, beef up the checks in getInsertSelectQuery() by checking that the jointree->fromlist node is indeed a RangeTblRef, and that the RTE it points to has rtekind == RTE_SUBQUERY. Per bug #17803, from Alexander Lakhin. Back-patch to all supported branches. Dean Rasheed, reviewed by Tom Lane. Discussion: https://postgr.es/m/17803-53c63ed4ecb4eac6%40postgresql.org Branch ------ REL_12_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/98b83b7349821b05134e6f50f516ecac878cb91d Modified Files -------------- src/backend/rewrite/rewriteHandler.c | 32 ++++++++++++++++++++++++--- src/backend/rewrite/rewriteManip.c | 11 +++++---- src/test/regress/expected/updatable_views.out | 19 ++++++++++++++++ src/test/regress/sql/updatable_views.sql | 10 +++++++++ 4 files changed, 65 insertions(+), 7 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix multi-row DEFAULT handling for INSERT ... SELECT rules. @ 2023-02-23 11:01 Dean Rasheed <dean.a.rasheed@gmail.com> 0 siblings, 0 replies; 6+ messages in thread From: Dean Rasheed @ 2023-02-23 11:01 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix multi-row DEFAULT handling for INSERT ... SELECT rules. Given an updatable view with a DO ALSO INSERT ... SELECT rule, a multi-row INSERT ... VALUES query on the view fails if the VALUES list contains any DEFAULTs that are not replaced by view defaults. This manifests as an "unrecognized node type" error, or an Assert failure, in an assert-enabled build. The reason is that when RewriteQuery() attempts to replace the remaining DEFAULT items with NULLs in any product queries, using rewriteValuesRTEToNulls(), it assumes that the VALUES RTE is located at the same rangetable index in each product query. However, if the product query is an INSERT ... SELECT, then the VALUES RTE is actually in the SELECT part of that query (at the same index), rather than the top-level product query itself. Fix, by descending to the SELECT in such cases. Note that we can't simply use getInsertSelectQuery() for this, since that expects to be given a raw rule action with OLD and NEW placeholder entries, so we duplicate its logic instead. While at it, beef up the checks in getInsertSelectQuery() by checking that the jointree->fromlist node is indeed a RangeTblRef, and that the RTE it points to has rtekind == RTE_SUBQUERY. Per bug #17803, from Alexander Lakhin. Back-patch to all supported branches. Dean Rasheed, reviewed by Tom Lane. Discussion: https://postgr.es/m/17803-53c63ed4ecb4eac6%40postgresql.org Branch ------ REL_11_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/e68b133c30e2146b51c15be702f8954bc8fdb63b Modified Files -------------- src/backend/rewrite/rewriteHandler.c | 32 ++++++++++++++++++++++++--- src/backend/rewrite/rewriteManip.c | 11 +++++---- src/test/regress/expected/updatable_views.out | 19 ++++++++++++++++ src/test/regress/sql/updatable_views.sql | 10 +++++++++ 4 files changed, 65 insertions(+), 7 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2023-02-23 11:01 UTC | newest] Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2023-02-23 11:01 pgsql: Fix multi-row DEFAULT handling for INSERT ... SELECT rules. Dean Rasheed <dean.a.rasheed@gmail.com> 2023-02-23 11:01 pgsql: Fix multi-row DEFAULT handling for INSERT ... SELECT rules. Dean Rasheed <dean.a.rasheed@gmail.com> 2023-02-23 11:01 pgsql: Fix multi-row DEFAULT handling for INSERT ... SELECT rules. Dean Rasheed <dean.a.rasheed@gmail.com> 2023-02-23 11:01 pgsql: Fix multi-row DEFAULT handling for INSERT ... SELECT rules. Dean Rasheed <dean.a.rasheed@gmail.com> 2023-02-23 11:01 pgsql: Fix multi-row DEFAULT handling for INSERT ... SELECT rules. Dean Rasheed <dean.a.rasheed@gmail.com> 2023-02-23 11:01 pgsql: Fix multi-row DEFAULT handling for INSERT ... SELECT rules. Dean Rasheed <dean.a.rasheed@gmail.com>
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