forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit044c99b
committed
Use query collation, not column's collation, while examining statistics.
Commit5e09280 changed the planner so that, instead of blindly usingDEFAULT_COLLATION_OID when invoking operators for selectivity estimation,it would use the collation of the column whose statistics we'reconsidering. This was recognized as still being not quite the rightthing, but it seemed like a good incremental improvement. However,shortly thereafter we introduced nondeterministic collations, and thatcreates cases where operators can fail if they're passed the wrongcollation. We don't want planning to fail in cases where the query itselfwould work, so this means that we *must* use the query's collation wheninvoking operators for estimation purposes.The only real problem this creates is in ineq_histogram_selectivity, wherethe binary search might produce a garbage answer if we perform comparisonsusing a different collation than the column's histogram is ordered with.However, when the query's collation is significantly different from thecolumn's default collation, the estimate we previously generated would bepretty irrelevant anyway; so it's not clear that this will result innoticeably worse estimates in practice. (A follow-on patch will improvethis situation in HEAD, but it seems too invasive for back-patch.)The patch requires changing the signatures of mcv_selectivity and alliedfunctions, which are exported and very possibly are used by extensions.In HEAD, I just did that, but an API/ABI break of this sort isn'tacceptable in stable branches. Therefore, in v12 the patch introduces"mcv_selectivity_ext" and so on, with signatures matching HEAD, and makesthe old functions into wrappers that assume DEFAULT_COLLATION_OID shouldbe used. That does not match the prior behavior, but it should avoid riskof failure in most cases. (In practice, I think most extension datatypesaren't collation-aware, so the change probably doesn't matter to them.)Per report from James Lucas. Back-patch to v12 where the problem wasintroduced.Discussion:https://postgr.es/m/CAAFmbbOvfi=wMM=3qRsPunBSLb8BFREno2oOzSBS=mzfLPKABw@mail.gmail.com1 parentf0d2c65 commit044c99b
File tree
5 files changed
+100
-85
lines changed- contrib/ltree
- src
- backend/utils/adt
- include/utils
5 files changed
+100
-85
lines changedLines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
582 | 582 |
| |
583 | 583 |
| |
584 | 584 |
| |
585 |
| - | |
| 585 | + | |
586 | 586 |
| |
587 | 587 |
| |
588 | 588 |
| |
|
Lines changed: 15 additions & 25 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
92 | 92 |
| |
93 | 93 |
| |
94 | 94 |
| |
| 95 | + | |
95 | 96 |
| |
96 | 97 |
| |
97 | 98 |
| |
| |||
534 | 535 |
| |
535 | 536 |
| |
536 | 537 |
| |
537 |
| - | |
538 |
| - | |
539 |
| - | |
540 |
| - | |
541 |
| - | |
542 |
| - | |
543 | 538 |
| |
544 | 539 |
| |
545 | 540 |
| |
| |||
622 | 617 |
| |
623 | 618 |
| |
624 | 619 |
| |
625 |
| - | |
| 620 | + | |
626 | 621 |
| |
627 | 622 |
| |
628 | 623 |
| |
| |||
654 | 649 |
| |
655 | 650 |
| |
656 | 651 |
| |
657 |
| - | |
| 652 | + | |
| 653 | + | |
658 | 654 |
| |
659 | 655 |
| |
660 | 656 |
| |
| |||
666 | 662 |
| |
667 | 663 |
| |
668 | 664 |
| |
| 665 | + | |
669 | 666 |
| |
670 | 667 |
| |
671 | 668 |
| |
| |||
698 | 695 |
| |
699 | 696 |
| |
700 | 697 |
| |
701 |
| - | |
| 698 | + | |
| 699 | + | |
702 | 700 |
| |
703 | 701 |
| |
704 | 702 |
| |
| |||
1196 | 1194 |
| |
1197 | 1195 |
| |
1198 | 1196 |
| |
1199 |
| - | |
| 1197 | + | |
1200 | 1198 |
| |
1201 | 1199 |
| |
1202 | 1200 |
| |
| |||
1207 | 1205 |
| |
1208 | 1206 |
| |
1209 | 1207 |
| |
| 1208 | + | |
1210 | 1209 |
| |
1211 | 1210 |
| |
1212 | 1211 |
| |
1213 | 1212 |
| |
1214 |
| - | |
1215 | 1213 |
| |
1216 | 1214 |
| |
1217 | 1215 |
| |
| |||
1220 | 1218 |
| |
1221 | 1219 |
| |
1222 | 1220 |
| |
| 1221 | + | |
1223 | 1222 |
| |
1224 | 1223 |
| |
1225 | 1224 |
| |
| |||
1229 | 1228 |
| |
1230 | 1229 |
| |
1231 | 1230 |
| |
1232 |
| - | |
1233 |
| - | |
1234 |
| - | |
1235 |
| - | |
1236 |
| - | |
1237 |
| - | |
| 1231 | + | |
| 1232 | + | |
1238 | 1233 |
| |
1239 |
| - | |
1240 |
| - | |
1241 |
| - | |
1242 |
| - | |
1243 |
| - | |
1244 |
| - | |
1245 | 1234 |
| |
1246 |
| - | |
| 1235 | + | |
1247 | 1236 |
| |
1248 | 1237 |
| |
1249 | 1238 |
| |
1250 | 1239 |
| |
1251 | 1240 |
| |
1252 | 1241 |
| |
| 1242 | + | |
1253 | 1243 |
| |
1254 | 1244 |
| |
1255 | 1245 |
| |
| |||
1278 | 1268 |
| |
1279 | 1269 |
| |
1280 | 1270 |
| |
1281 |
| - | |
| 1271 | + | |
1282 | 1272 |
| |
1283 | 1273 |
| |
1284 | 1274 |
| |
|
Lines changed: 2 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
137 | 137 |
| |
138 | 138 |
| |
139 | 139 |
| |
140 |
| - | |
| 140 | + | |
| 141 | + | |
141 | 142 |
| |
142 | 143 |
| |
143 | 144 |
| |
|
0 commit comments
Comments
(0)