- Notifications
You must be signed in to change notification settings - Fork4.9k
Commite2108f5
committed
Fix assorted issues in convert_to_scalar().
If convert_to_scalar is passed a pair of datatypes it can't cope with,its former behavior was just to elog(ERROR). While this is OK so far asthe core code is concerned, there's extension code that would like to usescalarltsel/scalargtsel/etc as selectivity estimators for operators thatwork on non-core datatypes, and this behavior is a show-stopper for thatuse-case. If we simply allow convert_to_scalar to return FALSE instead ofoutright failing, then the main logic of scalarltsel/scalargtsel will workfine for any operator that behaves like a scalar inequality comparison.The lack of conversion capability will mean that we can't estimate tobetter than histogram-bin-width precision, since the code will effectivelyassume that the comparison constant falls at the middle of its bin. Butthat's still a lot better than nothing. (Someday we should provide a wayfor extension code to supply a custom version of convert_to_scalar, buttoday is not that day.)While poking at this issue, we noted that the existing code for handlingtype bytea in convert_to_scalar is several bricks shy of a load.It assumes without checking that if the comparison value is type bytea,the bounds values are too; in the worst case this could lead to a crash.It also fails to detoast the input values, so that the comparison result iscomplete garbage if any input is toasted out-of-line, compressed, or evenjust short-header. I'm not sure how often such cases actually occur ---the bounds values, at least, are probably safe since they are elements ofan array and hence can't be toasted. But that doesn't make this code OK.Back-patch to all supported branches, partly because author requested that,but mostly because of the bytea bugs. The change in API for the exposedroutine convert_network_to_scalar() is theoretically a back-patch hazard,but it seems pretty unlikely that any third-party code is calling thatfunction directly.Tomas Vondra, with some adjustments by meDiscussion:https://postgr.es/m/b68441b6-d18f-13ab-b43b-9a72188a4e02@2ndquadrant.com1 parent79300d0 commite2108f5
File tree
4 files changed
+90
-57
lines changed- contrib/btree_gist
- src
- backend/utils/adt
- include/utils
4 files changed
+90
-57
lines changedLines changed: 9 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
99 | 99 |
| |
100 | 100 |
| |
101 | 101 |
| |
| 102 | + | |
102 | 103 |
| |
103 | 104 |
| |
104 |
| - | |
| 105 | + | |
| 106 | + | |
105 | 107 |
| |
106 | 108 |
| |
107 | 109 |
| |
| |||
118 | 120 |
| |
119 | 121 |
| |
120 | 122 |
| |
121 |
| - | |
| 123 | + | |
122 | 124 |
| |
123 | 125 |
| |
124 | 126 |
| |
125 | 127 |
| |
126 | 128 |
| |
127 | 129 |
| |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
128 | 135 |
| |
129 | 136 |
| |
130 | 137 |
| |
|
Lines changed: 5 additions & 8 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
943 | 943 |
| |
944 | 944 |
| |
945 | 945 |
| |
| 946 | + | |
| 947 | + | |
| 948 | + | |
946 | 949 |
| |
947 | 950 |
| |
948 |
| - | |
| 951 | + | |
949 | 952 |
| |
950 | 953 |
| |
951 | 954 |
| |
| |||
972 | 975 |
| |
973 | 976 |
| |
974 | 977 |
| |
975 |
| - | |
976 |
| - | |
977 | 978 |
| |
978 | 979 |
| |
979 | 980 |
| |
| |||
987 | 988 |
| |
988 | 989 |
| |
989 | 990 |
| |
990 |
| - | |
991 |
| - | |
992 |
| - | |
993 |
| - | |
994 |
| - | |
| 991 | + | |
995 | 992 |
| |
996 | 993 |
| |
997 | 994 |
| |
|
Lines changed: 75 additions & 46 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
167 | 167 |
| |
168 | 168 |
| |
169 | 169 |
| |
170 |
| - | |
| 170 | + | |
171 | 171 |
| |
172 | 172 |
| |
173 | 173 |
| |
| |||
184 | 184 |
| |
185 | 185 |
| |
186 | 186 |
| |
187 |
| - | |
188 |
| - | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
189 | 190 |
| |
190 | 191 |
| |
191 | 192 |
| |
| |||
530 | 531 |
| |
531 | 532 |
| |
532 | 533 |
| |
533 |
| - | |
| 534 | + | |
| 535 | + | |
534 | 536 |
| |
535 | 537 |
| |
536 | 538 |
| |
| |||
3707 | 3709 |
| |
3708 | 3710 |
| |
3709 | 3711 |
| |
| 3712 | + | |
| 3713 | + | |
3710 | 3714 |
| |
3711 | 3715 |
| |
3712 |
| - | |
3713 |
| - | |
| 3716 | + | |
| 3717 | + | |
| 3718 | + | |
| 3719 | + | |
| 3720 | + | |
3714 | 3721 |
| |
3715 | 3722 |
| |
3716 | 3723 |
| |
| |||
3745 | 3752 |
| |
3746 | 3753 |
| |
3747 | 3754 |
| |
3748 |
| - | |
3749 |
| - | |
3750 |
| - | |
3751 |
| - | |
| 3755 | + | |
| 3756 | + | |
| 3757 | + | |
| 3758 | + | |
| 3759 | + | |
| 3760 | + | |
| 3761 | + | |
3752 | 3762 |
| |
3753 | 3763 |
| |
3754 | 3764 |
| |
| |||
3759 | 3769 |
| |
3760 | 3770 |
| |
3761 | 3771 |
| |
3762 |
| - | |
3763 |
| - | |
3764 |
| - | |
| 3772 | + | |
| 3773 | + | |
| 3774 | + | |
| 3775 | + | |
| 3776 | + | |
| 3777 | + | |
| 3778 | + | |
| 3779 | + | |
| 3780 | + | |
| 3781 | + | |
| 3782 | + | |
| 3783 | + | |
| 3784 | + | |
| 3785 | + | |
3765 | 3786 |
| |
3766 | 3787 |
| |
3767 | 3788 |
| |
| |||
3777 | 3798 |
| |
3778 | 3799 |
| |
3779 | 3800 |
| |
| 3801 | + | |
| 3802 | + | |
| 3803 | + | |
3780 | 3804 |
| |
3781 | 3805 |
| |
3782 | 3806 |
| |
| |||
3795 | 3819 |
| |
3796 | 3820 |
| |
3797 | 3821 |
| |
3798 |
| - | |
3799 |
| - | |
3800 |
| - | |
3801 |
| - | |
| 3822 | + | |
| 3823 | + | |
| 3824 | + | |
| 3825 | + | |
| 3826 | + | |
| 3827 | + | |
| 3828 | + | |
3802 | 3829 |
| |
3803 | 3830 |
| |
3804 | 3831 |
| |
3805 | 3832 |
| |
3806 | 3833 |
| |
3807 | 3834 |
| |
3808 | 3835 |
| |
3809 |
| - | |
3810 |
| - | |
3811 |
| - | |
3812 |
| - | |
| 3836 | + | |
| 3837 | + | |
| 3838 | + | |
| 3839 | + | |
| 3840 | + | |
| 3841 | + | |
| 3842 | + | |
3813 | 3843 |
| |
3814 | 3844 |
| |
3815 | 3845 |
| |
| |||
3818 | 3848 |
| |
3819 | 3849 |
| |
3820 | 3850 |
| |
| 3851 | + | |
| 3852 | + | |
| 3853 | + | |
3821 | 3854 |
| |
3822 | 3855 |
| |
3823 |
| - | |
| 3856 | + | |
3824 | 3857 |
| |
3825 | 3858 |
| |
3826 | 3859 |
| |
| |||
3856 | 3889 |
| |
3857 | 3890 |
| |
3858 | 3891 |
| |
3859 |
| - | |
3860 |
| - | |
3861 |
| - | |
3862 |
| - | |
3863 |
| - | |
| 3892 | + | |
3864 | 3893 |
| |
3865 | 3894 |
| |
3866 | 3895 |
| |
| |||
4009 | 4038 |
| |
4010 | 4039 |
| |
4011 | 4040 |
| |
| 4041 | + | |
| 4042 | + | |
| 4043 | + | |
4012 | 4044 |
| |
4013 | 4045 |
| |
4014 | 4046 |
| |
4015 | 4047 |
| |
4016 |
| - | |
| 4048 | + | |
4017 | 4049 |
| |
4018 | 4050 |
| |
4019 | 4051 |
| |
| |||
4037 | 4069 |
| |
4038 | 4070 |
| |
4039 | 4071 |
| |
4040 |
| - | |
4041 |
| - | |
4042 |
| - | |
4043 |
| - | |
4044 |
| - | |
4045 |
| - | |
| 4072 | + | |
4046 | 4073 |
| |
4047 | 4074 |
| |
4048 | 4075 |
| |
| |||
4119 | 4146 |
| |
4120 | 4147 |
| |
4121 | 4148 |
| |
| 4149 | + | |
| 4150 | + | |
| 4151 | + | |
4122 | 4152 |
| |
4123 | 4153 |
| |
4124 |
| - | |
4125 |
| - | |
4126 |
| - | |
| 4154 | + | |
| 4155 | + | |
| 4156 | + | |
4127 | 4157 |
| |
4128 | 4158 |
| |
4129 |
| - | |
4130 |
| - | |
4131 |
| - | |
| 4159 | + | |
| 4160 | + | |
| 4161 | + | |
4132 | 4162 |
| |
4133 | 4163 |
| |
4134 | 4164 |
| |
| |||
4195 | 4225 |
| |
4196 | 4226 |
| |
4197 | 4227 |
| |
| 4228 | + | |
| 4229 | + | |
| 4230 | + | |
4198 | 4231 |
| |
4199 | 4232 |
| |
4200 |
| - | |
| 4233 | + | |
4201 | 4234 |
| |
4202 | 4235 |
| |
4203 | 4236 |
| |
| |||
4261 | 4294 |
| |
4262 | 4295 |
| |
4263 | 4296 |
| |
4264 |
| - | |
4265 |
| - | |
4266 |
| - | |
4267 |
| - | |
4268 |
| - | |
| 4297 | + | |
4269 | 4298 |
| |
4270 | 4299 |
| |
4271 | 4300 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
982 | 982 |
| |
983 | 983 |
| |
984 | 984 |
| |
985 |
| - | |
| 985 | + | |
986 | 986 |
| |
987 | 987 |
| |
988 | 988 |
| |
|
0 commit comments
Comments
(0)