- Notifications
You must be signed in to change notification settings - Fork4.9k
Commit976e584
committed
Fix improper uses of canonicalize_qual().
One of the things canonicalize_qual() does is to remove constant-NULLsubexpressions of top-level AND/OR clauses. It does that on the assumptionthat what it's given is a top-level WHERE clause, so that NULL can betreated like FALSE. Although this is documented down inside a subroutineof canonicalize_qual(), it wasn't mentioned in the documentation of thatfunction itself, and some callers hadn't gotten that memo.Notably, commitd007a95 caused get_relation_constraints() to applycanonicalize_qual() to CHECK constraints. That allowed constraintexclusion to misoptimize situations in which a CHECK constraint had aprovably-NULL subclause, as seen in the regression test case added here,in which a child table that should be scanned is not. (Although thisthinko is ancient, the test case doesn't fail before 9.2, for reasonsI've not bothered to track down in detail. There may be related casesthat do fail before that.)More recently, commitf0e4475 added an independent bug by applyingcanonicalize_qual() to index expressions, which is even sillier sincethose might not even be boolean. If they are, though, I think thiscould lead to making incorrect index entries for affected indexexpressions in v10. I haven't attempted to prove that though.To fix, add an "is_check" parameter to canonicalize_qual() to specifywhether it should assume WHERE or CHECK semantics, and make it performNULL-elimination accordingly. Adjust the callers to apply the rightsemantics, or remove the call entirely in cases where it's not knownthat the expression has one or the other semantics. I also removedthe call in some cases involving partition expressions, where it shouldbe a no-op because such expressions should be canonical already ...and was a no-op, independently of whether it could in principle havedone something, because it was being handed the qual in implicit-ANDformat which isn't what it expects. In HEAD, add an Assert to catchthat type of mistake in future.This represents an API break for external callers of canonicalize_qual().While that's intentional in HEAD to make such callers think about whichcase applies to them, it seems like something we probably wouldn't bethanked for in released branches. Hence, in released branches, theextra parameter is added to a new function canonicalize_qual_ext(),and canonicalize_qual() is a wrapper that retains its old behavior.Patch by me with suggestions from Dean Rasheed. Back-patch to allsupported branches.Discussion:https://postgr.es/m/24475.1520635069@sss.pgh.pa.us1 parent2f09dc1 commit976e584
File tree
8 files changed
+105
-26
lines changed- src
- backend
- optimizer
- plan
- prep
- util
- utils/cache
- include/optimizer
- test/regress
- expected
- sql
8 files changed
+105
-26
lines changedLines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
836 | 836 |
| |
837 | 837 |
| |
838 | 838 |
| |
839 |
| - | |
| 839 | + | |
840 | 840 |
| |
841 | 841 |
| |
842 | 842 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1721 | 1721 |
| |
1722 | 1722 |
| |
1723 | 1723 |
| |
1724 |
| - | |
| 1724 | + | |
1725 | 1725 |
| |
1726 | 1726 |
| |
1727 | 1727 |
| |
|
Lines changed: 62 additions & 21 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
39 | 39 |
| |
40 | 40 |
| |
41 | 41 |
| |
42 |
| - | |
| 42 | + | |
43 | 43 |
| |
44 | 44 |
| |
45 | 45 |
| |
| |||
269 | 269 |
| |
270 | 270 |
| |
271 | 271 |
| |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
272 | 290 |
| |
273 | 291 |
| |
274 | 292 |
| |
| |||
283 | 301 |
| |
284 | 302 |
| |
285 | 303 |
| |
286 |
| - | |
| 304 | + | |
287 | 305 |
| |
288 | 306 |
| |
289 | 307 |
| |
| |||
296 | 314 |
| |
297 | 315 |
| |
298 | 316 |
| |
299 |
| - | |
| 317 | + | |
300 | 318 |
| |
301 | 319 |
| |
302 | 320 |
| |
| |||
395 | 413 |
| |
396 | 414 |
| |
397 | 415 |
| |
398 |
| - | |
399 |
| - | |
400 |
| - | |
401 |
| - | |
402 |
| - | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
403 | 422 |
| |
404 | 423 |
| |
405 | 424 |
| |
406 | 425 |
| |
407 |
| - | |
| 426 | + | |
408 | 427 |
| |
409 | 428 |
| |
410 | 429 |
| |
| |||
416 | 435 |
| |
417 | 436 |
| |
418 | 437 |
| |
419 |
| - | |
| 438 | + | |
420 | 439 |
| |
421 | 440 |
| |
422 | 441 |
| |
423 | 442 |
| |
424 | 443 |
| |
425 | 444 |
| |
426 |
| - | |
427 |
| - | |
428 |
| - | |
429 |
| - | |
430 |
| - | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
431 | 461 |
| |
432 | 462 |
| |
433 | 463 |
| |
| |||
449 | 479 |
| |
450 | 480 |
| |
451 | 481 |
| |
452 |
| - | |
| 482 | + | |
453 | 483 |
| |
454 | 484 |
| |
455 | 485 |
| |
456 | 486 |
| |
457 | 487 |
| |
458 | 488 |
| |
459 |
| - | |
460 |
| - | |
461 |
| - | |
462 |
| - | |
463 |
| - | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
464 | 505 |
| |
465 | 506 |
| |
466 | 507 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1177 | 1177 |
| |
1178 | 1178 |
| |
1179 | 1179 |
| |
1180 |
| - | |
| 1180 | + | |
1181 | 1181 |
| |
1182 | 1182 |
| |
1183 | 1183 |
| |
|
Lines changed: 3 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
4263 | 4263 |
| |
4264 | 4264 |
| |
4265 | 4265 |
| |
4266 |
| - | |
| 4266 | + | |
| 4267 | + | |
4267 | 4268 |
| |
4268 | 4269 |
| |
4269 | 4270 |
| |
| |||
4331 | 4332 |
| |
4332 | 4333 |
| |
4333 | 4334 |
| |
4334 |
| - | |
| 4335 | + | |
4335 | 4336 |
| |
4336 | 4337 |
| |
4337 | 4338 |
| |
|
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
34 | 34 |
| |
35 | 35 |
| |
36 | 36 |
| |
| 37 | + | |
37 | 38 |
| |
38 | 39 |
| |
39 | 40 |
| |
|
Lines changed: 24 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1591 | 1591 |
| |
1592 | 1592 |
| |
1593 | 1593 |
| |
| 1594 | + | |
| 1595 | + | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
| 1601 | + | |
| 1602 | + | |
| 1603 | + | |
| 1604 | + | |
| 1605 | + | |
| 1606 | + | |
| 1607 | + | |
| 1608 | + | |
| 1609 | + | |
| 1610 | + | |
| 1611 | + | |
| 1612 | + | |
| 1613 | + | |
| 1614 | + | |
| 1615 | + | |
| 1616 | + | |
| 1617 | + |
Lines changed: 12 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
562 | 562 |
| |
563 | 563 |
| |
564 | 564 |
| |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + |
0 commit comments
Comments
(0)