forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit72a4231
committed
Fix planning of non-strict equivalence clauses above outer joins.
If a potential equivalence clause references a variable from the nullableside of an outer join, the planner needs to take care that derived clausesare not pushed to below the outer join; else they may use the wrong valuefor the variable. (The problem arises only with non-strict clauses, sinceif an upper clause can be proven strict then the outer join will getsimplified to a plain join.) The planner attempted to prevent this typeof error by checking that potential equivalence clauses aren'touterjoin-delayed as a whole, but actually we have to check each sideseparately, since the two sides of the clause will get moved aroundseparately if it's treated as an equivalence. Bugs of this type can bedemonstrated as far back as 7.4, even though releases before 8.3 had onlya very ad-hoc notion of equivalence clauses.In addition, we neglected to account for the possibility that such clausesmight have nonempty nullable_relids even when not outerjoin-delayed; so theequivalence-class machinery lacked logic to compute correct nullable_relidsvalues for clauses it constructs. This oversight was harmless before 9.2because we were only using RestrictInfo.nullable_relids for OR clauses;but as of 9.2 it could result in pushing constructed equivalence clausesto incorrect places. (This accounts for bug #7604 from Bill MacArthur.)Fix the first problem by adding a new test check_equivalence_delay() indistribute_qual_to_rels, and fix the second one by adding code inequivclass.c and called functions to set correct nullable_relids forgenerated clauses. Although I believe the second part of this is notcurrently necessary before 9.2, I chose to back-patch it anyway, partly tokeep the logic similar across branches and partly because it seems possiblewe might find other reasons why we need valid values of nullable_relids inthe older branches.Add regression tests illustrating these problems. In 9.0 and up, alsoadd test cases checking that we can push constants through outer joins,since we've broken that optimization before and I nearly broke it againwith an overly simplistic patch for this problem.1 parent7b583b2 commit72a4231
File tree
7 files changed
+248
-36
lines changed- src
- backend
- nodes
- optimizer
- path
- plan
- include
- nodes
- optimizer
- test/regress
- expected
- sql
7 files changed
+248
-36
lines changedLines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1815 | 1815 |
| |
1816 | 1816 |
| |
1817 | 1817 |
| |
| 1818 | + | |
1818 | 1819 |
| |
1819 | 1820 |
| |
1820 | 1821 |
| |
|
Lines changed: 63 additions & 17 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
30 | 30 |
| |
31 | 31 |
| |
32 | 32 |
| |
33 |
| - | |
| 33 | + | |
34 | 34 |
| |
35 | 35 |
| |
36 | 36 |
| |
| |||
106 | 106 |
| |
107 | 107 |
| |
108 | 108 |
| |
109 |
| - | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
110 | 112 |
| |
111 | 113 |
| |
112 | 114 |
| |
| |||
163 | 165 |
| |
164 | 166 |
| |
165 | 167 |
| |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
166 | 174 |
| |
167 | 175 |
| |
168 | 176 |
| |
| |||
309 | 317 |
| |
310 | 318 |
| |
311 | 319 |
| |
312 |
| - | |
| 320 | + | |
| 321 | + | |
313 | 322 |
| |
314 | 323 |
| |
315 | 324 |
| |
| |||
322 | 331 |
| |
323 | 332 |
| |
324 | 333 |
| |
325 |
| - | |
| 334 | + | |
| 335 | + | |
326 | 336 |
| |
327 | 337 |
| |
328 | 338 |
| |
| |||
349 | 359 |
| |
350 | 360 |
| |
351 | 361 |
| |
352 |
| - | |
353 |
| - | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
354 | 366 |
| |
355 | 367 |
| |
356 | 368 |
| |
| |||
448 | 460 |
| |
449 | 461 |
| |
450 | 462 |
| |
451 |
| - | |
| 463 | + | |
452 | 464 |
| |
453 | 465 |
| |
454 | 466 |
| |
455 | 467 |
| |
456 | 468 |
| |
| 469 | + | |
457 | 470 |
| |
458 | 471 |
| |
459 | 472 |
| |
| |||
609 | 622 |
| |
610 | 623 |
| |
611 | 624 |
| |
612 |
| - | |
| 625 | + | |
613 | 626 |
| |
614 | 627 |
| |
615 | 628 |
| |
| |||
789 | 802 |
| |
790 | 803 |
| |
791 | 804 |
| |
792 |
| - | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
793 | 808 |
| |
794 | 809 |
| |
795 | 810 |
| |
| |||
844 | 859 |
| |
845 | 860 |
| |
846 | 861 |
| |
847 |
| - | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
848 | 865 |
| |
849 | 866 |
| |
850 | 867 |
| |
| |||
1312 | 1329 |
| |
1313 | 1330 |
| |
1314 | 1331 |
| |
1315 |
| - | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
1316 | 1335 |
| |
1317 | 1336 |
| |
1318 | 1337 |
| |
| |||
1534 | 1553 |
| |
1535 | 1554 |
| |
1536 | 1555 |
| |
1537 |
| - | |
| 1556 | + | |
| 1557 | + | |
1538 | 1558 |
| |
1539 | 1559 |
| |
1540 | 1560 |
| |
| |||
1561 | 1581 |
| |
1562 | 1582 |
| |
1563 | 1583 |
| |
| 1584 | + | |
| 1585 | + | |
1564 | 1586 |
| |
1565 | 1587 |
| |
1566 | 1588 |
| |
| |||
1619 | 1641 |
| |
1620 | 1642 |
| |
1621 | 1643 |
| |
1622 |
| - | |
| 1644 | + | |
| 1645 | + | |
1623 | 1646 |
| |
1624 | 1647 |
| |
1625 | 1648 |
| |
| |||
1653 | 1676 |
| |
1654 | 1677 |
| |
1655 | 1678 |
| |
1656 |
| - | |
| 1679 | + | |
| 1680 | + | |
| 1681 | + | |
1657 | 1682 |
| |
1658 | 1683 |
| |
1659 | 1684 |
| |
| |||
1669 | 1694 |
| |
1670 | 1695 |
| |
1671 | 1696 |
| |
| 1697 | + | |
| 1698 | + | |
| 1699 | + | |
| 1700 | + | |
1672 | 1701 |
| |
1673 | 1702 |
| |
1674 | 1703 |
| |
| |||
1754 | 1783 |
| |
1755 | 1784 |
| |
1756 | 1785 |
| |
1757 |
| - | |
| 1786 | + | |
| 1787 | + | |
1758 | 1788 |
| |
1759 | 1789 |
| |
1760 | 1790 |
| |
| |||
1767 | 1797 |
| |
1768 | 1798 |
| |
1769 | 1799 |
| |
1770 |
| - | |
| 1800 | + | |
| 1801 | + | |
1771 | 1802 |
| |
1772 | 1803 |
| |
1773 | 1804 |
| |
| |||
1894 | 1925 |
| |
1895 | 1926 |
| |
1896 | 1927 |
| |
| 1928 | + | |
1897 | 1929 |
| |
1898 | 1930 |
| |
1899 | 1931 |
| |
| |||
1910 | 1942 |
| |
1911 | 1943 |
| |
1912 | 1944 |
| |
1913 |
| - | |
| 1945 | + | |
| 1946 | + | |
| 1947 | + | |
| 1948 | + | |
| 1949 | + | |
| 1950 | + | |
| 1951 | + | |
| 1952 | + | |
| 1953 | + | |
| 1954 | + | |
| 1955 | + | |
| 1956 | + | |
| 1957 | + | |
| 1958 | + | |
| 1959 | + | |
1914 | 1960 |
| |
1915 | 1961 |
| |
1916 | 1962 |
| |
|
0 commit comments
Comments
(0)