forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitf0a8515
committed
Fix planner's cost estimation for SEMI/ANTI joins with inner indexscans.
When the inner side of a nestloop SEMI or ANTI join is an indexscan thatuses all the join clauses as indexquals, it can be presumed that bothmatched and unmatched outer rows will be processed very quickly: formatched rows, we'll stop after fetching one row from the indexscan, whilefor unmatched rows we'll have an indexscan that finds no matching indexentries, which should also be quick. The planner already knew about this,but it was nonetheless charging for at least one full run of the innerindexscan, as a consequence of concerns about the behavior of materializedinner scans --- but those concerns don't apply in the fast case. If theinner side has low cardinality (many matching rows) this could make anindexscan plan look far more expensive than it actually is. To fix,rearrange the work in initial_cost_nestloop/final_cost_nestloop so that wedon't add the inner scan cost until we've inspected the indexquals, andthen we can add either the full-run cost or just the first tuple's cost asappropriate.Experimentation with this fix uncovered another problem: add_path andfriends were coded to disregard cheap startup cost when consideringparameterized paths. That's usually okay (and desirable, because it thinsthe path herd faster); but in this fast case for SEMI/ANTI joins, it couldresult in throwing away the desired plain indexscan path in favor of abitmap scan path before we ever get to the join costing logic. In themany-matching-rows cases of interest here, a bitmap scan will do a lot morework than required, so this is a problem. To fix, add a per-relation flagconsider_param_startup that works like the existing consider_startup flag,but applies to parameterized paths, and set it for relations that are theinside of a SEMI or ANTI join.To make this patch reasonably safe to back-patch, care has been taken toavoid changing the planner's behavior except in the very narrow case ofSEMI/ANTI joins with inner indexscans. There are places incompare_path_costs_fuzzily and add_path_precheck that are not terriblyconsistent with the new approach, but changing them will affect plannerdecisions at the margins in other cases, so we'll leave that for aHEAD-only fix.Back-patch to 9.3; before that, the consider_startup flag didn't exist,meaning that the second aspect of the patch would be too invasive.Per a complaint from Peter Holzer and analysis by Tomas Vondra.1 parentde17fe4 commitf0a8515
File tree
7 files changed
+175
-86
lines changed- src
- backend
- nodes
- optimizer
- path
- util
- include/nodes
7 files changed
+175
-86
lines changedLines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1745 | 1745 |
| |
1746 | 1746 |
| |
1747 | 1747 |
| |
| 1748 | + | |
1748 | 1749 |
| |
1749 | 1750 |
| |
1750 | 1751 |
| |
|
Lines changed: 8 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
795 | 795 |
| |
796 | 796 |
| |
797 | 797 |
| |
798 |
| - | |
| 798 | + | |
799 | 799 |
| |
800 | 800 |
| |
801 | 801 |
| |
| |||
804 | 804 |
| |
805 | 805 |
| |
806 | 806 |
| |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
807 | 814 |
| |
808 | 815 |
| |
809 | 816 |
| |
|
Lines changed: 47 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
56 | 56 |
| |
57 | 57 |
| |
58 | 58 |
| |
| 59 | + | |
59 | 60 |
| |
60 | 61 |
| |
61 | 62 |
| |
| |||
141 | 142 |
| |
142 | 143 |
| |
143 | 144 |
| |
| 145 | + | |
| 146 | + | |
| 147 | + | |
144 | 148 |
| |
145 | 149 |
| |
146 | 150 |
| |
| |||
160 | 164 |
| |
161 | 165 |
| |
162 | 166 |
| |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
163 | 210 |
| |
164 | 211 |
| |
165 | 212 |
| |
|
Lines changed: 77 additions & 47 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1662 | 1662 |
| |
1663 | 1663 |
| |
1664 | 1664 |
| |
1665 |
| - | |
| 1665 | + | |
| 1666 | + | |
1666 | 1667 |
| |
1667 | 1668 |
| |
1668 | 1669 |
| |
| |||
1710 | 1711 |
| |
1711 | 1712 |
| |
1712 | 1713 |
| |
1713 |
| - | |
1714 |
| - | |
1715 |
| - | |
1716 | 1714 |
| |
1717 | 1715 |
| |
1718 | 1716 |
| |
1719 |
| - | |
1720 |
| - | |
1721 |
| - | |
1722 |
| - | |
1723 |
| - | |
1724 |
| - | |
1725 |
| - | |
1726 |
| - | |
1727 |
| - | |
1728 |
| - | |
1729 |
| - | |
1730 |
| - | |
1731 |
| - | |
1732 |
| - | |
1733 |
| - | |
1734 |
| - | |
1735 |
| - | |
1736 |
| - | |
1737 |
| - | |
1738 |
| - | |
1739 |
| - | |
1740 |
| - | |
1741 |
| - | |
1742 |
| - | |
1743 |
| - | |
1744 |
| - | |
1745 |
| - | |
| 1717 | + | |
| 1718 | + | |
1746 | 1719 |
| |
1747 | 1720 |
| |
1748 | 1721 |
| |
1749 |
| - | |
1750 |
| - | |
| 1722 | + | |
| 1723 | + | |
1751 | 1724 |
| |
1752 | 1725 |
| |
1753 | 1726 |
| |
| |||
1764 | 1737 |
| |
1765 | 1738 |
| |
1766 | 1739 |
| |
1767 |
| - | |
1768 | 1740 |
| |
1769 | 1741 |
| |
1770 | 1742 |
| |
| |||
1788 | 1760 |
| |
1789 | 1761 |
| |
1790 | 1762 |
| |
1791 |
| - | |
1792 | 1763 |
| |
1793 | 1764 |
| |
1794 | 1765 |
| |
| |||
1807 | 1778 |
| |
1808 | 1779 |
| |
1809 | 1780 |
| |
1810 |
| - | |
| 1781 | + | |
1811 | 1782 |
| |
1812 | 1783 |
| |
1813 | 1784 |
| |
1814 |
| - | |
1815 |
| - | |
1816 |
| - | |
1817 | 1785 |
| |
1818 | 1786 |
| |
1819 | 1787 |
| |
| 1788 | + | |
| 1789 | + | |
| 1790 | + | |
| 1791 | + | |
1820 | 1792 |
| |
1821 |
| - | |
| 1793 | + | |
| 1794 | + | |
| 1795 | + | |
| 1796 | + | |
| 1797 | + | |
| 1798 | + | |
| 1799 | + | |
| 1800 | + | |
| 1801 | + | |
| 1802 | + | |
| 1803 | + | |
| 1804 | + | |
| 1805 | + | |
| 1806 | + | |
| 1807 | + | |
| 1808 | + | |
1822 | 1809 |
| |
1823 | 1810 |
| |
1824 | 1811 |
| |
1825 |
| - | |
1826 |
| - | |
1827 |
| - | |
1828 |
| - | |
1829 |
| - | |
1830 |
| - | |
| 1812 | + | |
| 1813 | + | |
| 1814 | + | |
| 1815 | + | |
| 1816 | + | |
| 1817 | + | |
| 1818 | + | |
1831 | 1819 |
| |
1832 | 1820 |
| |
1833 | 1821 |
| |
| 1822 | + | |
| 1823 | + | |
| 1824 | + | |
| 1825 | + | |
| 1826 | + | |
| 1827 | + | |
| 1828 | + | |
| 1829 | + | |
| 1830 | + | |
| 1831 | + | |
| 1832 | + | |
| 1833 | + | |
| 1834 | + | |
| 1835 | + | |
| 1836 | + | |
| 1837 | + | |
| 1838 | + | |
| 1839 | + | |
| 1840 | + | |
| 1841 | + | |
| 1842 | + | |
| 1843 | + | |
| 1844 | + | |
| 1845 | + | |
1834 | 1846 |
| |
1835 | 1847 |
| |
1836 | 1848 |
| |
1837 | 1849 |
| |
1838 |
| - | |
| 1850 | + | |
1839 | 1851 |
| |
1840 | 1852 |
| |
1841 | 1853 |
| |
1842 | 1854 |
| |
1843 | 1855 |
| |
| 1856 | + | |
| 1857 | + | |
| 1858 | + | |
| 1859 | + | |
| 1860 | + | |
| 1861 | + | |
| 1862 | + | |
| 1863 | + | |
| 1864 | + | |
| 1865 | + | |
| 1866 | + | |
| 1867 | + | |
| 1868 | + | |
| 1869 | + | |
| 1870 | + | |
| 1871 | + | |
1844 | 1872 |
| |
1845 | 1873 |
| |
| 1874 | + | |
| 1875 | + | |
1846 | 1876 |
| |
1847 | 1877 |
| |
1848 | 1878 |
| |
|
0 commit comments
Comments
(0)