forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit75c7376
committed
Fix multi-row DEFAULT handling for INSERT ... SELECT rules.
Given an updatable view with a DO ALSO INSERT ... SELECT rule, amulti-row INSERT ... VALUES query on the view fails if the VALUES listcontains any DEFAULTs that are not replaced by view defaults. Thismanifests as an "unrecognized node type" error, or an Assert failure,in an assert-enabled build.The reason is that when RewriteQuery() attempts to replace theremaining DEFAULT items with NULLs in any product queries, usingrewriteValuesRTEToNulls(), it assumes that the VALUES RTE is locatedat the same rangetable index in each product query. However, if theproduct query is an INSERT ... SELECT, then the VALUES RTE is actuallyin the SELECT part of that query (at the same index), rather than thetop-level product query itself.Fix, by descending to the SELECT in such cases. Note that we can'tsimply use getInsertSelectQuery() for this, since that expects to begiven a raw rule action with OLD and NEW placeholder entries, so weduplicate its logic instead.While at it, beef up the checks in getInsertSelectQuery() by checkingthat the jointree->fromlist node is indeed a RangeTblRef, and that theRTE it points to has rtekind == RTE_SUBQUERY.Per bug #17803, from Alexander Lakhin. Back-patch to all supportedbranches.Dean Rasheed, reviewed by Tom Lane.Discussion:https://postgr.es/m/17803-53c63ed4ecb4eac6%40postgresql.org1 parent337903a commit75c7376
File tree
4 files changed
+65
-7
lines changed- src
- backend/rewrite
- test/regress
- expected
- sql
4 files changed
+65
-7
lines changedLines changed: 29 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1604 | 1604 |
| |
1605 | 1605 |
| |
1606 | 1606 |
| |
1607 |
| - | |
1608 | 1607 |
| |
1609 | 1608 |
| |
1610 | 1609 |
| |
| |||
3861 | 3860 |
| |
3862 | 3861 |
| |
3863 | 3862 |
| |
| 3863 | + | |
| 3864 | + | |
| 3865 | + | |
| 3866 | + | |
| 3867 | + | |
3864 | 3868 |
| |
3865 | 3869 |
| |
3866 | 3870 |
| |
3867 | 3871 |
| |
3868 |
| - | |
3869 |
| - | |
| 3872 | + | |
| 3873 | + | |
| 3874 | + | |
| 3875 | + | |
| 3876 | + | |
| 3877 | + | |
| 3878 | + | |
| 3879 | + | |
| 3880 | + | |
| 3881 | + | |
| 3882 | + | |
| 3883 | + | |
| 3884 | + | |
| 3885 | + | |
| 3886 | + | |
| 3887 | + | |
| 3888 | + | |
| 3889 | + | |
| 3890 | + | |
| 3891 | + | |
| 3892 | + | |
| 3893 | + | |
| 3894 | + | |
| 3895 | + | |
3870 | 3896 |
| |
3871 | 3897 |
| |
3872 | 3898 |
| |
|
Lines changed: 7 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1012 | 1012 |
| |
1013 | 1013 |
| |
1014 | 1014 |
| |
1015 |
| - | |
| 1015 | + | |
| 1016 | + | |
1016 | 1017 |
| |
1017 |
| - | |
1018 |
| - | |
1019 |
| - | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
1020 | 1022 |
| |
| 1023 | + | |
1021 | 1024 |
| |
1022 | 1025 |
| |
1023 | 1026 |
| |
|
Lines changed: 19 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
3296 | 3296 |
| |
3297 | 3297 |
| |
3298 | 3298 |
| |
| 3299 | + | |
| 3300 | + | |
| 3301 | + | |
| 3302 | + | |
| 3303 | + | |
| 3304 | + | |
| 3305 | + | |
| 3306 | + | |
| 3307 | + | |
| 3308 | + | |
| 3309 | + | |
| 3310 | + | |
| 3311 | + | |
| 3312 | + | |
| 3313 | + | |
| 3314 | + | |
| 3315 | + | |
| 3316 | + | |
| 3317 | + | |
3299 | 3318 |
| |
3300 | 3319 |
| |
3301 | 3320 |
| |
|
Lines changed: 10 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1717 | 1717 |
| |
1718 | 1718 |
| |
1719 | 1719 |
| |
| 1720 | + | |
| 1721 | + | |
| 1722 | + | |
| 1723 | + | |
| 1724 | + | |
| 1725 | + | |
| 1726 | + | |
| 1727 | + | |
| 1728 | + | |
| 1729 | + | |
1720 | 1730 |
| |
1721 | 1731 |
| |
1722 | 1732 |
| |
|
0 commit comments
Comments
(0)