- Notifications
You must be signed in to change notification settings - Fork5
Commitb557226
committed
Improve planner's cost estimation in the presence of semijoins.
If we have a semijoin, saySELECT * FROM x WHERE x1 IN (SELECT y1 FROM y)and we're estimating the cost of a parameterized indexscan on x, the numberof repetitions of the indexscan should not be taken as the size of y; it'llreally only be the number of distinct values of y1, because the only validplan with y on the outside of a nestloop would require y to be unique-ifiedbefore joining it to x. Most of the time this doesn't make that muchdifference, but sometimes it can lead to drastically underestimating thecost of the indexscan and hence choosing a bad plan, as pointed out byDavid Kubečka.Fixing this is a bit difficult because parameterized indexscans are costedout quite early in the planning process, before we have the informationthat would be needed to call estimate_num_groups() and thereby estimate thenumber of distinct values of the join column(s). However we can move thecode that extracts a semijoin RHS's unique-ification columns, so that it'sdone in initsplan.c rather than on-the-fly in create_unique_path(). Thatshouldn't make any difference speed-wise and it's really a bit cleaner too.The other bit of information we need is the size of the semijoin RHS,which is easy if it's a single relation (we make those estimates beforeconsidering indexscan costs) but problematic if it's a join relation.The solution adopted here is just to use the product of the sizes of thejoin component rels. That will generally be an overestimate, but sinceestimate_num_groups() only uses this input as a clamp, an overestimateshouldn't hurt us too badly. In any case we don't allow this new logicto produce a value larger than we would have chosen before, so that atworst an overestimate leaves us no wiser than we were before.1 parentff2faee commitb557226
File tree
10 files changed
+385
-224
lines changed- src
- backend
- nodes
- optimizer
- path
- plan
- util
- include/nodes
10 files changed
+385
-224
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1942 | 1942 | | |
1943 | 1943 | | |
1944 | 1944 | | |
1945 | | - | |
| 1945 | + | |
| 1946 | + | |
| 1947 | + | |
| 1948 | + | |
1946 | 1949 | | |
1947 | 1950 | | |
1948 | 1951 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
798 | 798 | | |
799 | 799 | | |
800 | 800 | | |
801 | | - | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
802 | 805 | | |
803 | 806 | | |
804 | 807 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1945 | 1945 | | |
1946 | 1946 | | |
1947 | 1947 | | |
1948 | | - | |
| 1948 | + | |
| 1949 | + | |
| 1950 | + | |
| 1951 | + | |
1949 | 1952 | | |
1950 | 1953 | | |
1951 | 1954 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3294 | 3294 | | |
3295 | 3295 | | |
3296 | 3296 | | |
3297 | | - | |
| 3297 | + | |
| 3298 | + | |
| 3299 | + | |
| 3300 | + | |
3298 | 3301 | | |
3299 | 3302 | | |
3300 | 3303 | | |
| |||
3456 | 3459 | | |
3457 | 3460 | | |
3458 | 3461 | | |
3459 | | - | |
| 3462 | + | |
| 3463 | + | |
| 3464 | + | |
| 3465 | + | |
3460 | 3466 | | |
3461 | 3467 | | |
3462 | 3468 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
133 | | - | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
134 | 139 | | |
135 | 140 | | |
136 | 141 | | |
| |||
402 | 407 | | |
403 | 408 | | |
404 | 409 | | |
405 | | - | |
| 410 | + | |
406 | 411 | | |
407 | 412 | | |
408 | 413 | | |
| |||
969 | 974 | | |
970 | 975 | | |
971 | 976 | | |
972 | | - | |
| 977 | + | |
973 | 978 | | |
974 | 979 | | |
975 | 980 | | |
| |||
1553 | 1558 | | |
1554 | 1559 | | |
1555 | 1560 | | |
1556 | | - | |
| 1561 | + | |
1557 | 1562 | | |
1558 | 1563 | | |
1559 | 1564 | | |
| |||
1594 | 1599 | | |
1595 | 1600 | | |
1596 | 1601 | | |
1597 | | - | |
| 1602 | + | |
1598 | 1603 | | |
1599 | 1604 | | |
1600 | 1605 | | |
| |||
1861 | 1866 | | |
1862 | 1867 | | |
1863 | 1868 | | |
| 1869 | + | |
| 1870 | + | |
| 1871 | + | |
| 1872 | + | |
| 1873 | + | |
| 1874 | + | |
1864 | 1875 | | |
1865 | 1876 | | |
1866 | 1877 | | |
1867 | 1878 | | |
1868 | 1879 | | |
1869 | | - | |
| 1880 | + | |
1870 | 1881 | | |
1871 | | - | |
| 1882 | + | |
| 1883 | + | |
1872 | 1884 | | |
1873 | 1885 | | |
1874 | | - | |
| 1886 | + | |
| 1887 | + | |
| 1888 | + | |
| 1889 | + | |
| 1890 | + | |
| 1891 | + | |
1875 | 1892 | | |
1876 | | - | |
| 1893 | + | |
| 1894 | + | |
1877 | 1895 | | |
1878 | | - | |
1879 | | - | |
1880 | | - | |
1881 | | - | |
| 1896 | + | |
| 1897 | + | |
| 1898 | + | |
| 1899 | + | |
| 1900 | + | |
| 1901 | + | |
| 1902 | + | |
1882 | 1903 | | |
1883 | | - | |
1884 | | - | |
1885 | | - | |
1886 | | - | |
1887 | | - | |
1888 | | - | |
1889 | | - | |
| 1904 | + | |
| 1905 | + | |
| 1906 | + | |
1890 | 1907 | | |
1891 | | - | |
1892 | | - | |
1893 | | - | |
| 1908 | + | |
| 1909 | + | |
1894 | 1910 | | |
1895 | | - | |
1896 | | - | |
| 1911 | + | |
| 1912 | + | |
| 1913 | + | |
| 1914 | + | |
| 1915 | + | |
1897 | 1916 | | |
1898 | | - | |
1899 | | - | |
1900 | | - | |
1901 | | - | |
| 1917 | + | |
| 1918 | + | |
| 1919 | + | |
1902 | 1920 | | |
1903 | 1921 | | |
1904 | 1922 | | |
1905 | 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 | + | |
| 1954 | + | |
| 1955 | + | |
| 1956 | + | |
| 1957 | + | |
| 1958 | + | |
| 1959 | + | |
| 1960 | + | |
| 1961 | + | |
| 1962 | + | |
| 1963 | + | |
| 1964 | + | |
| 1965 | + | |
| 1966 | + | |
| 1967 | + | |
| 1968 | + | |
| 1969 | + | |
| 1970 | + | |
| 1971 | + | |
| 1972 | + | |
| 1973 | + | |
| 1974 | + | |
| 1975 | + | |
| 1976 | + | |
| 1977 | + | |
| 1978 | + | |
| 1979 | + | |
| 1980 | + | |
| 1981 | + | |
| 1982 | + | |
| 1983 | + | |
| 1984 | + | |
| 1985 | + | |
| 1986 | + | |
| 1987 | + | |
| 1988 | + | |
| 1989 | + | |
| 1990 | + | |
| 1991 | + | |
| 1992 | + | |
| 1993 | + | |
| 1994 | + | |
| 1995 | + | |
| 1996 | + | |
| 1997 | + | |
| 1998 | + | |
| 1999 | + | |
| 2000 | + | |
| 2001 | + | |
| 2002 | + | |
| 2003 | + | |
| 2004 | + | |
1906 | 2005 | | |
1907 | 2006 | | |
1908 | 2007 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
624 | 624 | | |
625 | 625 | | |
626 | 626 | | |
627 | | - | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
628 | 631 | | |
629 | 632 | | |
630 | 633 | | |
| |||
0 commit comments
Comments
(0)