forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit60be3f9

Richard Guo
Avoid unnecessary wrapping for more complex expressions
When pulling up a subquery that is under an outer join, if thesubquery's target list contains a strict expression that uses asubquery variable, it's okay to pull up the expression withoutwrapping it in a PlaceHolderVar: if the subquery variable is forced toNULL by the outer join, the expression result will come out as NULLtoo.If the strict expression does not contain any subquery variables, thecurrent code always wraps it in a PlaceHolderVar. While this is notincorrect, the analysis could be tighter: if the strict expressioncontains any variables of rels that are under the same lowest nullingouter join as the subquery, we can also avoid wrapping it. This issafe because if the subquery variable is forced to NULL by the outerjoin, the variables of rels that are under the same lowest nullingouter join will also be forced to NULL, resulting in the expressionevaluating to NULL as well. Therefore, it's not necessary to forcethe expression to be evaluated below the outer join. It could bebeneficial to get rid of such PHVs because they could imply lateraldependencies, which force us to resort to nestloop joins.This patch checks if the lateral references in the strict expressioncontain any variables of rels under the same lowest nulling outer joinas the subquery, and avoids wrapping the expression in that case.This is fundamentally a generalization of the optimizations for bareVars and PHVs introduced in commitf64ec81.No backpatch as this could result in plan changes.Author: Richard GuoDiscussion:https://postgr.es/m/CAMbWs4_ENtfRdLaM_bXAxiKRYO7DmwDBDG4_2=VTDi0mJP-jAw@mail.gmail.com1 parent2364f61 commit60be3f9
File tree
3 files changed
+186
-17
lines changed- src
- backend/optimizer/prep
- test/regress
- expected
- sql
3 files changed
+186
-17
lines changedLines changed: 50 additions & 17 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2649 | 2649 |
| |
2650 | 2650 |
| |
2651 | 2651 |
| |
2652 |
| - | |
2653 |
| - | |
2654 |
| - | |
2655 |
| - | |
2656 |
| - | |
| 2652 | + | |
| 2653 | + | |
| 2654 | + | |
| 2655 | + | |
| 2656 | + | |
| 2657 | + | |
2657 | 2658 |
| |
2658 | 2659 |
| |
2659 | 2660 |
| |
2660 | 2661 |
| |
2661 | 2662 |
| |
2662 | 2663 |
| |
2663 | 2664 |
| |
2664 |
| - | |
2665 |
| - | |
2666 |
| - | |
2667 |
| - | |
2668 |
| - | |
2669 |
| - | |
2670 |
| - | |
2671 |
| - | |
| 2665 | + | |
| 2666 | + | |
| 2667 | + | |
| 2668 | + | |
| 2669 | + | |
| 2670 | + | |
| 2671 | + | |
| 2672 | + | |
| 2673 | + | |
| 2674 | + | |
2672 | 2675 |
| |
2673 | 2676 |
| |
2674 | 2677 |
| |
| |||
2679 | 2682 |
| |
2680 | 2683 |
| |
2681 | 2684 |
| |
2682 |
| - | |
2683 |
| - | |
2684 |
| - | |
2685 |
| - | |
| 2685 | + | |
| 2686 | + | |
| 2687 | + | |
| 2688 | + | |
| 2689 | + | |
| 2690 | + | |
| 2691 | + | |
| 2692 | + | |
| 2693 | + | |
| 2694 | + | |
| 2695 | + | |
| 2696 | + | |
| 2697 | + | |
| 2698 | + | |
| 2699 | + | |
| 2700 | + | |
| 2701 | + | |
| 2702 | + | |
| 2703 | + | |
| 2704 | + | |
| 2705 | + | |
| 2706 | + | |
| 2707 | + | |
| 2708 | + | |
| 2709 | + | |
| 2710 | + | |
| 2711 | + | |
| 2712 | + | |
| 2713 | + | |
| 2714 | + | |
| 2715 | + | |
| 2716 | + | |
| 2717 | + | |
| 2718 | + | |
2686 | 2719 |
| |
2687 | 2720 |
| |
2688 | 2721 |
| |
|
Lines changed: 103 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1848 | 1848 |
| |
1849 | 1849 |
| |
1850 | 1850 |
| |
| 1851 | + | |
| 1852 | + | |
| 1853 | + | |
| 1854 | + | |
| 1855 | + | |
| 1856 | + | |
| 1857 | + | |
| 1858 | + | |
| 1859 | + | |
| 1860 | + | |
| 1861 | + | |
| 1862 | + | |
| 1863 | + | |
| 1864 | + | |
| 1865 | + | |
| 1866 | + | |
| 1867 | + | |
| 1868 | + | |
| 1869 | + | |
| 1870 | + | |
| 1871 | + | |
| 1872 | + | |
| 1873 | + | |
| 1874 | + | |
| 1875 | + | |
| 1876 | + | |
| 1877 | + | |
| 1878 | + | |
| 1879 | + | |
| 1880 | + | |
| 1881 | + | |
| 1882 | + | |
| 1883 | + | |
| 1884 | + | |
| 1885 | + | |
| 1886 | + | |
| 1887 | + | |
| 1888 | + | |
| 1889 | + | |
| 1890 | + | |
| 1891 | + | |
| 1892 | + | |
| 1893 | + | |
| 1894 | + | |
| 1895 | + | |
| 1896 | + | |
| 1897 | + | |
| 1898 | + | |
| 1899 | + | |
| 1900 | + | |
| 1901 | + | |
| 1902 | + | |
| 1903 | + | |
| 1904 | + | |
| 1905 | + | |
| 1906 | + | |
| 1907 | + | |
| 1908 | + | |
| 1909 | + | |
| 1910 | + | |
| 1911 | + | |
| 1912 | + | |
| 1913 | + | |
| 1914 | + | |
| 1915 | + | |
| 1916 | + | |
| 1917 | + | |
| 1918 | + | |
| 1919 | + | |
| 1920 | + | |
| 1921 | + | |
| 1922 | + | |
| 1923 | + | |
| 1924 | + | |
| 1925 | + | |
| 1926 | + | |
| 1927 | + | |
| 1928 | + | |
| 1929 | + | |
| 1930 | + | |
| 1931 | + | |
| 1932 | + | |
| 1933 | + | |
| 1934 | + | |
| 1935 | + | |
| 1936 | + | |
| 1937 | + | |
| 1938 | + | |
| 1939 | + | |
| 1940 | + | |
| 1941 | + | |
| 1942 | + | |
| 1943 | + | |
| 1944 | + | |
| 1945 | + | |
| 1946 | + | |
| 1947 | + | |
| 1948 | + | |
| 1949 | + | |
| 1950 | + | |
| 1951 | + | |
| 1952 | + | |
| 1953 | + | |
1851 | 1954 |
| |
1852 | 1955 |
| |
1853 | 1956 |
| |
|
Lines changed: 33 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
939 | 939 |
| |
940 | 940 |
| |
941 | 941 |
| |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
942 | 975 |
| |
943 | 976 |
| |
944 | 977 |
| |
|
0 commit comments
Comments
(0)