forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitf8abb0f
committed
postgres_fdw: suppress casts on constants in limited cases.
When deparsing an expression of the form "remote_var OP constant",we'd normally apply a cast to the constant to make sure that theremote parser thinks it's of the same type we do. However, doingso is often not necessary, and it causes problems if the user hasintentionally declared the local column as being of a differenttype than the remote column. A plausible use-case for that isusing text to represent a type that's an enum on the remote side.A comparison on such a column will get shipped as "var = 'foo'::text",which blows up on the remote side because there's no enum = textoperator. But if we simply leave off the explicit cast, thecomparison will do exactly what the user wants.It's possible to do this without major risk of semantic problems, byrelying on the longstanding parser heuristic that "if one operand ofan operator is of type unknown, while the other one has a known type,assume that the unknown operand is also of that type". Hence, thispatch leaves off the cast only if (a) the operator inputs have the sametype locally; (b) the constant will print as a string literal or NULL,both of which are initially taken as type unknown; and (c) the non-Constinput is a plain foreign Var. Rule (c) guarantees that the remoteparser will know the type of the non-Const input; moreover, it meansthat if this cast-omission does cause any semantic surprises, that canonly happen in cases where the local column has a different type thanthe remote column. That wasn't guaranteed to work anyway, and thispatch should represent a net usability gain for such cases.One point that I (tgl) remain slightly uncomfortable with is that wewill ignore an implicit RelabelType when deciding if the non-Const inputis a plain Var. That makes it a little squishy to argue that the remoteshould resolve the Const as being of the same type as its Var, becausethen our Const is not the same type as our Var. However, if we don't dothat, then this hack won't work as desired if the user chooses to usevarchar rather than text to represent some remote column. That seemsuseful, so do it like this for now. We might have to give up theRelabelType-ignoring bit if any problems surface.Dian Fay, with review and kibitzing by meDiscussion:https://postgr.es/m/C9LU294V7K4F.34LRRDU449O45@lamia1 parent1593998 commitf8abb0f
File tree
3 files changed
+212
-47
lines changed- contrib/postgres_fdw
- expected
- sql
3 files changed
+212
-47
lines changedLines changed: 108 additions & 8 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
152 | 152 |
| |
153 | 153 |
| |
154 | 154 |
| |
| 155 | + | |
155 | 156 |
| |
156 | 157 |
| |
157 | 158 |
| |
| |||
2695 | 2696 |
| |
2696 | 2697 |
| |
2697 | 2698 |
| |
2698 |
| - | |
2699 |
| - | |
2700 |
| - | |
| 2699 | + | |
| 2700 | + | |
| 2701 | + | |
| 2702 | + | |
| 2703 | + | |
| 2704 | + | |
| 2705 | + | |
| 2706 | + | |
2701 | 2707 |
| |
2702 | 2708 |
| |
2703 | 2709 |
| |
| |||
2707 | 2713 |
| |
2708 | 2714 |
| |
2709 | 2715 |
| |
| 2716 | + | |
2710 | 2717 |
| |
2711 | 2718 |
| |
2712 | 2719 |
| |
| |||
2762 | 2769 |
| |
2763 | 2770 |
| |
2764 | 2771 |
| |
| 2772 | + | |
2765 | 2773 |
| |
2766 | 2774 |
| |
2767 | 2775 |
| |
2768 | 2776 |
| |
2769 | 2777 |
| |
2770 |
| - | |
2771 |
| - | |
| 2778 | + | |
| 2779 | + | |
2772 | 2780 |
| |
2773 | 2781 |
| |
2774 | 2782 |
| |
| |||
2788 | 2796 |
| |
2789 | 2797 |
| |
2790 | 2798 |
| |
2791 |
| - | |
| 2799 | + | |
| 2800 | + | |
| 2801 | + | |
| 2802 | + | |
| 2803 | + | |
| 2804 | + | |
| 2805 | + | |
2792 | 2806 |
| |
2793 | 2807 |
| |
2794 | 2808 |
| |
| |||
2953 | 2967 |
| |
2954 | 2968 |
| |
2955 | 2969 |
| |
| 2970 | + | |
| 2971 | + | |
2956 | 2972 |
| |
2957 | 2973 |
| |
2958 | 2974 |
| |
| |||
2966 | 2982 |
| |
2967 | 2983 |
| |
2968 | 2984 |
| |
| 2985 | + | |
| 2986 | + | |
2969 | 2987 |
| |
2970 | 2988 |
| |
2971 | 2989 |
| |
2972 | 2990 |
| |
2973 | 2991 |
| |
2974 | 2992 |
| |
2975 |
| - | |
| 2993 | + | |
| 2994 | + | |
| 2995 | + | |
| 2996 | + | |
| 2997 | + | |
| 2998 | + | |
| 2999 | + | |
| 3000 | + | |
| 3001 | + | |
| 3002 | + | |
| 3003 | + | |
| 3004 | + | |
| 3005 | + | |
| 3006 | + | |
| 3007 | + | |
| 3008 | + | |
| 3009 | + | |
| 3010 | + | |
| 3011 | + | |
| 3012 | + | |
| 3013 | + | |
| 3014 | + | |
| 3015 | + | |
| 3016 | + | |
| 3017 | + | |
| 3018 | + | |
| 3019 | + | |
| 3020 | + | |
| 3021 | + | |
| 3022 | + | |
| 3023 | + | |
| 3024 | + | |
| 3025 | + | |
| 3026 | + | |
| 3027 | + | |
| 3028 | + | |
| 3029 | + | |
| 3030 | + | |
| 3031 | + | |
| 3032 | + | |
| 3033 | + | |
| 3034 | + | |
| 3035 | + | |
| 3036 | + | |
2976 | 3037 |
| |
2977 | 3038 |
| |
2978 | 3039 |
| |
| |||
2981 | 3042 |
| |
2982 | 3043 |
| |
2983 | 3044 |
| |
2984 |
| - | |
| 3045 | + | |
| 3046 | + | |
| 3047 | + | |
| 3048 | + | |
| 3049 | + | |
2985 | 3050 |
| |
2986 | 3051 |
| |
2987 | 3052 |
| |
2988 | 3053 |
| |
2989 | 3054 |
| |
2990 | 3055 |
| |
| 3056 | + | |
| 3057 | + | |
| 3058 | + | |
| 3059 | + | |
| 3060 | + | |
| 3061 | + | |
| 3062 | + | |
| 3063 | + | |
| 3064 | + | |
| 3065 | + | |
| 3066 | + | |
| 3067 | + | |
| 3068 | + | |
| 3069 | + | |
| 3070 | + | |
| 3071 | + | |
| 3072 | + | |
| 3073 | + | |
| 3074 | + | |
| 3075 | + | |
| 3076 | + | |
| 3077 | + | |
| 3078 | + | |
| 3079 | + | |
| 3080 | + | |
| 3081 | + | |
| 3082 | + | |
| 3083 | + | |
| 3084 | + | |
| 3085 | + | |
| 3086 | + | |
| 3087 | + | |
| 3088 | + | |
| 3089 | + | |
| 3090 | + | |
2991 | 3091 |
| |
2992 | 3092 |
| |
2993 | 3093 |
| |
|
0 commit comments
Comments
(0)