forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitad1c36b
committed
Fix foreign-key selectivity estimation in the presence of constants.
get_foreign_key_join_selectivity() looks for join clauses that equatethe two sides of the FK constraint. However, if we have a query like"WHERE fktab.a = pktab.a and fktab.a = 1", it won't find any such joinclause, because equivclass.c replaces the given clauses with "fktab.a= 1 and pktab.a = 1", which can be enforced at the scan level, leavingnothing to be done for column "a" at the join level.We can fix that expectation without much trouble, but then a new problemarises: applying the foreign-key-based selectivity rule produces arowcount underestimate, because we're effectively double-counting theselectivity of the "fktab.a = 1" clause. So we have to cancel thatselectivity out of the estimate.To fix, refactor process_implied_equality() so that it can pass back thenew RestrictInfo to its callers in equivclass.c, allowing the generated"fktab.a = 1" clause to be saved in the EquivalenceClass's ec_deriveslist. Then it's not much trouble to dig out the relevant RestrictInfowhen we need to adjust an FK selectivity estimate. (While at it, wecan also remove the expensive use of initialize_mergeclause_eclasses()to set up the new RestrictInfo's left_ec and right_ec pointers.The equivclass.c code can set those basically for free.)This seems like clearly a bug fix, but I'm hesitant to back-patch it,first because there's some API/ABI risk for extensions and second becausewe're usually loath to destabilize plan choices in stable branches.Per report from Sigrid Ehrenreich.Discussion:https://postgr.es/m/1019549.1603770457@sss.pgh.pa.usDiscussion:https://postgr.es/m/AM6PR02MB5287A0ADD936C1FA80973E72AB190@AM6PR02MB5287.eurprd02.prod.outlook.com1 parentce7f772 commitad1c36b
File tree
10 files changed
+366
-103
lines changed- src
- backend
- nodes
- optimizer
- path
- plan
- util
- include
- nodes
- optimizer
- test/regress
- expected
- sql
10 files changed
+366
-103
lines changedLines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2352 | 2352 |
| |
2353 | 2353 |
| |
2354 | 2354 |
| |
| 2355 | + | |
2355 | 2356 |
| |
2356 | 2357 |
| |
2357 | 2358 |
| |
|
Lines changed: 52 additions & 5 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
5066 | 5066 |
| |
5067 | 5067 |
| |
5068 | 5068 |
| |
5069 |
| - | |
5070 |
| - | |
5071 |
| - | |
| 5069 | + | |
| 5070 | + | |
| 5071 | + | |
| 5072 | + | |
| 5073 | + | |
| 5074 | + | |
| 5075 | + | |
| 5076 | + | |
| 5077 | + | |
| 5078 | + | |
5072 | 5079 |
| |
5073 | 5080 |
| |
5074 | 5081 |
| |
| |||
5078 | 5085 |
| |
5079 | 5086 |
| |
5080 | 5087 |
| |
5081 |
| - | |
5082 |
| - | |
| 5088 | + | |
| 5089 | + | |
| 5090 | + | |
5083 | 5091 |
| |
5084 | 5092 |
| |
5085 | 5093 |
| |
| |||
5138 | 5146 |
| |
5139 | 5147 |
| |
5140 | 5148 |
| |
| 5149 | + | |
| 5150 | + | |
| 5151 | + | |
| 5152 | + | |
| 5153 | + | |
| 5154 | + | |
| 5155 | + | |
| 5156 | + | |
| 5157 | + | |
| 5158 | + | |
| 5159 | + | |
| 5160 | + | |
| 5161 | + | |
| 5162 | + | |
| 5163 | + | |
| 5164 | + | |
| 5165 | + | |
| 5166 | + | |
| 5167 | + | |
| 5168 | + | |
| 5169 | + | |
| 5170 | + | |
| 5171 | + | |
| 5172 | + | |
| 5173 | + | |
| 5174 | + | |
| 5175 | + | |
| 5176 | + | |
| 5177 | + | |
| 5178 | + | |
| 5179 | + | |
| 5180 | + | |
| 5181 | + | |
| 5182 | + | |
| 5183 | + | |
| 5184 | + | |
| 5185 | + | |
| 5186 | + | |
5141 | 5187 |
| |
5142 | 5188 |
| |
5143 | 5189 |
| |
| 5190 | + | |
5144 | 5191 |
| |
5145 | 5192 |
| |
5146 | 5193 |
| |
|
Lines changed: 96 additions & 25 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
840 | 840 |
| |
841 | 841 |
| |
842 | 842 |
| |
843 |
| - | |
844 |
| - | |
845 |
| - | |
846 |
| - | |
| 843 | + | |
| 844 | + | |
847 | 845 |
| |
848 | 846 |
| |
849 | 847 |
| |
| |||
969 | 967 |
| |
970 | 968 |
| |
971 | 969 |
| |
| 970 | + | |
972 | 971 |
| |
973 | 972 |
| |
974 | 973 |
| |
| |||
982 | 981 |
| |
983 | 982 |
| |
984 | 983 |
| |
985 |
| - | |
986 |
| - | |
987 |
| - | |
988 |
| - | |
989 |
| - | |
990 |
| - | |
991 |
| - | |
992 |
| - | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
993 | 1009 |
| |
994 | 1010 |
| |
995 | 1011 |
| |
| |||
1028 | 1044 |
| |
1029 | 1045 |
| |
1030 | 1046 |
| |
| 1047 | + | |
1031 | 1048 |
| |
1032 | 1049 |
| |
1033 | 1050 |
| |
| |||
1038 | 1055 |
| |
1039 | 1056 |
| |
1040 | 1057 |
| |
1041 |
| - | |
1042 |
| - | |
1043 |
| - | |
1044 |
| - | |
1045 |
| - | |
1046 |
| - | |
1047 |
| - | |
1048 |
| - | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
1049 | 1081 |
| |
1050 | 1082 |
| |
1051 | 1083 |
| |
| |||
2151 | 2183 |
| |
2152 | 2184 |
| |
2153 | 2185 |
| |
| 2186 | + | |
| 2187 | + | |
| 2188 | + | |
| 2189 | + | |
2154 | 2190 |
| |
2155 | 2191 |
| |
2156 | 2192 |
| |
| |||
2180 | 2216 |
| |
2181 | 2217 |
| |
2182 | 2218 |
| |
2183 |
| - | |
2184 |
| - | |
| 2219 | + | |
| 2220 | + | |
2185 | 2221 |
| |
2186 | 2222 |
| |
2187 | 2223 |
| |
| |||
2206 | 2242 |
| |
2207 | 2243 |
| |
2208 | 2244 |
| |
2209 |
| - | |
| 2245 | + | |
2210 | 2246 |
| |
2211 |
| - | |
| 2247 | + | |
2212 | 2248 |
| |
2213 | 2249 |
| |
2214 |
| - | |
| 2250 | + | |
2215 | 2251 |
| |
2216 | 2252 |
| |
2217 | 2253 |
| |
| |||
2221 | 2257 |
| |
2222 | 2258 |
| |
2223 | 2259 |
| |
| 2260 | + | |
| 2261 | + | |
| 2262 | + | |
2224 | 2263 |
| |
| 2264 | + | |
2225 | 2265 |
| |
2226 | 2266 |
| |
2227 | 2267 |
| |
| |||
2230 | 2270 |
| |
2231 | 2271 |
| |
2232 | 2272 |
| |
| 2273 | + | |
| 2274 | + | |
| 2275 | + | |
| 2276 | + | |
| 2277 | + | |
| 2278 | + | |
| 2279 | + | |
| 2280 | + | |
| 2281 | + | |
| 2282 | + | |
| 2283 | + | |
| 2284 | + | |
| 2285 | + | |
| 2286 | + | |
| 2287 | + | |
| 2288 | + | |
| 2289 | + | |
| 2290 | + | |
| 2291 | + | |
| 2292 | + | |
| 2293 | + | |
| 2294 | + | |
| 2295 | + | |
| 2296 | + | |
| 2297 | + | |
| 2298 | + | |
| 2299 | + | |
| 2300 | + | |
| 2301 | + | |
| 2302 | + | |
| 2303 | + | |
2233 | 2304 |
| |
2234 | 2305 |
| |
2235 | 2306 |
| |
|
0 commit comments
Comments
(0)