Commit 2605643
committed
Fix DEFAULT handling for multi-row INSERT rules.
When updating a relation with a rule whose action performed an INSERT
from a multi-row VALUES list, the rewriter might skip processing the
VALUES list, and therefore fail to replace any DEFAULTs in it. This
would lead to an "unrecognized node type" error.
The reason was that RewriteQuery() assumed that a query doing an
INSERT from a multi-row VALUES list would necessarily only have one
item in its fromlist, pointing to the VALUES RTE to read from. That
assumption is correct for the original query, but not for product
queries produced for rule actions. In such cases, there may be
multiple items in the fromlist, possibly including multiple VALUES
RTEs.
What is required instead is for RewriteQuery() to skip any RTEs from
the product query's originating query, which might include one or more
already-processed VALUES RTEs. What's left should then include at most
one VALUES RTE (from the rule action) to be processed.
Patch by me. Thanks to Tom Lane for reviewing.
Back-patch to all supported branches.
Discussion: https://postgr.es/m/CAEZATCV39OOW7LAR_Xq4i%2BLc1Byux%3DeK3Q%3DHD_pF1o9LBt%3DphA%40mail.gmail.com1 parent f73bd5f commit 2605643Copy full SHA for 2605643
File tree
Expand file treeCollapse file tree
3 files changed
+104
-55
lines changedOpen diff view settings
Filter options
- src
- backend/rewrite
- test/regress
- expected
- sql
Expand file treeCollapse file tree
3 files changed
+104
-55
lines changedOpen diff view settings
Collapse file
src/backend/rewrite/rewriteHandler.c
Copy file name to clipboardExpand all lines: src/backend/rewrite/rewriteHandler.c+43-10Lines changed: 43 additions & 10 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
418 | 418 | |
419 | 419 | |
420 | 420 | |
| 421 | + |
| 422 | + |
| 423 | + |
| 424 | + |
421 | 425 | |
422 | 426 | |
423 | 427 | |
| ||
3622 | 3626 | |
3623 | 3627 | |
3624 | 3628 | |
| 3629 | + |
| 3630 | + |
| 3631 | + |
| 3632 | + |
3625 | 3633 | |
3626 | 3634 | |
3627 | | - |
| 3635 | + |
3628 | 3636 | |
3629 | 3637 | |
3630 | 3638 | |
| ||
3648 | 3656 | |
3649 | 3657 | |
3650 | 3658 | |
3651 | | - |
| 3659 | + |
3652 | 3660 | |
3653 | 3661 | |
3654 | 3662 | |
| ||
3722 | 3730 | |
3723 | 3731 | |
3724 | 3732 | |
| 3733 | + |
3725 | 3734 | |
3726 | 3735 | |
3727 | 3736 | |
| ||
3743 | 3752 | |
3744 | 3753 | |
3745 | 3754 | |
| 3755 | + |
3746 | 3756 | |
3747 | 3757 | |
3748 | 3758 | |
3749 | | - |
3750 | | - |
| 3759 | + |
| 3760 | + |
| 3761 | + |
| 3762 | + |
3751 | 3763 | |
3752 | | - |
| 3764 | + |
3753 | 3765 | |
3754 | | - |
| 3766 | + |
3755 | 3767 | |
3756 | | - |
| 3768 | + |
3757 | 3769 | |
3758 | 3770 | |
3759 | 3771 | |
3760 | 3772 | |
3761 | 3773 | |
3762 | 3774 | |
| 3775 | + |
| 3776 | + |
| 3777 | + |
| 3778 | + |
3763 | 3779 | |
3764 | 3780 | |
3765 | 3781 | |
| ||
3837 | 3853 | |
3838 | 3854 | |
3839 | 3855 | |
3840 | | - |
| 3856 | + |
| 3857 | + |
| 3858 | + |
| 3859 | + |
| 3860 | + |
3841 | 3861 | |
3842 | 3862 | |
3843 | 3863 | |
| ||
3864 | 3884 | |
3865 | 3885 | |
3866 | 3886 | |
| 3887 | + |
3867 | 3888 | |
3868 | 3889 | |
3869 | 3890 | |
| ||
4020 | 4041 | |
4021 | 4042 | |
4022 | 4043 | |
4023 | | - |
| 4044 | + |
| 4045 | + |
| 4046 | + |
| 4047 | + |
| 4048 | + |
| 4049 | + |
| 4050 | + |
| 4051 | + |
| 4052 | + |
| 4053 | + |
| 4054 | + |
| 4055 | + |
| 4056 | + |
4024 | 4057 | |
4025 | 4058 | |
4026 | 4059 | |
| ||
4172 | 4205 | |
4173 | 4206 | |
4174 | 4207 | |
4175 | | - |
| 4208 | + |
4176 | 4209 | |
4177 | 4210 | |
4178 | 4211 | |
|
Collapse file
src/test/regress/expected/rules.out
Copy file name to clipboardExpand all lines: src/test/regress/expected/rules.out+52-39Lines changed: 52 additions & 39 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
2913 | 2913 | |
2914 | 2914 | |
2915 | 2915 | |
2916 | | - |
2917 | | - |
| 2916 | + |
| 2917 | + |
2918 | 2918 | |
2919 | 2919 | |
2920 | | - |
| 2920 | + |
2921 | 2921 | |
2922 | 2922 | |
2923 | 2923 | |
| ||
2928 | 2928 | |
2929 | 2929 | |
2930 | 2930 | |
2931 | | - |
2932 | | - |
2933 | | - |
2934 | | - |
2935 | | - |
2936 | | - |
2937 | | - |
2938 | | - |
2939 | | - |
2940 | | - |
| 2931 | + |
| 2932 | + |
| 2933 | + |
| 2934 | + |
| 2935 | + |
| 2936 | + |
| 2937 | + |
| 2938 | + |
| 2939 | + |
| 2940 | + |
2941 | 2941 | |
2942 | 2942 | |
2943 | 2943 | |
| ||
2951 | 2951 | |
2952 | 2952 | |
2953 | 2953 | |
| 2954 | + |
| 2955 | + |
| 2956 | + |
2954 | 2957 | |
2955 | 2958 | |
2956 | 2959 | |
2957 | 2960 | |
2958 | 2961 | |
2959 | | - |
| 2962 | + |
| 2963 | + |
| 2964 | + |
2960 | 2965 | |
2961 | 2966 | |
2962 | | - |
2963 | | - |
2964 | | - |
2965 | | - |
2966 | | - |
2967 | | - |
2968 | | - |
2969 | | - |
2970 | | - |
2971 | | - |
2972 | | - |
2973 | | - |
2974 | | - |
2975 | | - |
2976 | | - |
2977 | | - |
2978 | | - |
| 2967 | + |
| 2968 | + |
| 2969 | + |
| 2970 | + |
| 2971 | + |
| 2972 | + |
| 2973 | + |
| 2974 | + |
| 2975 | + |
| 2976 | + |
| 2977 | + |
| 2978 | + |
| 2979 | + |
| 2980 | + |
| 2981 | + |
| 2982 | + |
| 2983 | + |
| 2984 | + |
| 2985 | + |
| 2986 | + |
| 2987 | + |
2979 | 2988 | |
2980 | 2989 | |
2981 | 2990 | |
2982 | 2991 | |
2983 | 2992 | |
2984 | | - |
| 2993 | + |
2985 | 2994 | |
2986 | 2995 | |
2987 | | - |
| 2996 | + |
2988 | 2997 | |
2989 | 2998 | |
2990 | 2999 | |
| 3000 | + |
| 3001 | + |
2991 | 3002 | |
2992 | 3003 | |
2993 | 3004 | |
2994 | 3005 | |
2995 | 3006 | |
2996 | 3007 | |
2997 | | - |
2998 | | - |
| 3008 | + |
| 3009 | + |
2999 | 3010 | |
3000 | 3011 | |
3001 | 3012 | |
3002 | 3013 | |
3003 | 3014 | |
3004 | | - |
| 3015 | + |
3005 | 3016 | |
3006 | 3017 | |
3007 | | - |
| 3018 | + |
3008 | 3019 | |
3009 | 3020 | |
3010 | 3021 | |
| 3022 | + |
| 3023 | + |
3011 | 3024 | |
3012 | 3025 | |
3013 | | - |
| 3026 | + |
3014 | 3027 | |
3015 | 3028 | |
3016 | 3029 | |
3017 | 3030 | |
3018 | | - |
| 3031 | + |
3019 | 3032 | |
3020 | 3033 | |
3021 | 3034 | |
|
Collapse file
src/test/regress/sql/rules.sql
Copy file name to clipboardExpand all lines: src/test/regress/sql/rules.sql+9-6Lines changed: 9 additions & 6 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
997 | 997 | |
998 | 998 | |
999 | 999 | |
1000 | | - |
1001 | | - |
| 1000 | + |
| 1001 | + |
1002 | 1002 | |
1003 | 1003 | |
1004 | | - |
| 1004 | + |
1005 | 1005 | |
1006 | 1006 | |
1007 | 1007 | |
1008 | 1008 | |
1009 | 1009 | |
1010 | 1010 | |
1011 | 1011 | |
| 1012 | + |
| 1013 | + |
| 1014 | + |
1012 | 1015 | |
1013 | 1016 | |
1014 | | - |
| 1017 | + |
1015 | 1018 | |
1016 | 1019 | |
1017 | 1020 | |
1018 | 1021 | |
1019 | 1022 | |
1020 | | - |
1021 | | - |
| 1023 | + |
| 1024 | + |
1022 | 1025 | |
1023 | 1026 | |
1024 | 1027 | |
|
0 commit comments