- Notifications
You must be signed in to change notification settings - Fork4.9k
Commit9a2e2a2
committed
Improve nbtree array primitive scan scheduling.
Add a new scheduling heuristic: don't end the ongoing primitive indexscan immediately (at the point where _bt_advance_array_keys notices thatthe next set of matching tuples must be on a later page) if the primscanalready managed to step right/left from its first leaf page. Schedule arecheck against the next sibling leaf page's finaltup instead.The new heuristic tends to avoid scenarios where the top-level scanrepeatedly starts and ends primitive index scans that each read only oneleaf page from a group of neighboring leaf pages. Affected top-levelscans will now tend to step forward (or backward) through the indexinstead, without wasting cycles on descending the index anew.The recheck mechanism isn't exactly new. But up until now it has onlybeen used to deal with edge cases involving high key finaltups with oneor more truncated -inf attributes that _bt_advance_array_keys deemed"provisionally satisfied" (satisfied for the purposes of allowing thescan to step onto the next page, subject to recheck once on that page).The mechanism was added by commit5bf748b, which invented the generalconcept of primitive scan scheduling. It was later enhanced by commit79fa7b3, which taught it about cases involving -inf attributes thatsatisfy inequality scan keys required in the opposite-to-scan directiononly (arguably, they should have been covered by the earliest version).Now the recheck mechanism can be applied based on scan-level heuristics,which have nothing to do with truncated high keys. Now rechecks mightbe performed by _bt_readpage when scanning in _either_ scan direction.The theory behind the new heuristic is that any primitive scan thatmakes it past its first leaf page is one that is already likely to havearrays whose key values match index tuples that are closely clusteredtogether in the index. The rules that determine whether we ever getpast the first page are still conservative (that'll still only happenwhen pstate.finaltup strongly suggests that it's the right thing to do).Surviving past the first leaf page is a strong signal in itself.Preparation for an upcoming patch that will add skip scan optimizationsto nbtree. That'll work by adding skip arrays, which behave similarlyto SAOP arrays, but generate their elements procedurally and on-demand.Note that this commit isn't specifically concerned with skip arrays; thescheduling logic doesn't (and won't) condition anything on whether thescan uses skip arrays, SAOP arrays, or some combination of the two(which seems like a good general principle for _bt_advance_array_keys).While the problems that this commit ameliorates are more likely withskip arrays (at least in practice), SAOP arrays (or those with verydense, contiguous array elements) are also affected.Author: Peter Geoghegan <pg@bowt.ie>Reviewed-By: Matthias van de Meent <boekewurm+postgres@gmail.com>Discussion:https://postgr.es/m/CAH2-Wzkz0wPe6+02kr+hC+JJNKfGtjGTzpG3CFVTQmKwWNrXNw@mail.gmail.com1 parente215166 commit9a2e2a2
File tree
3 files changed
+162
-138
lines changed- src
- backend/access/nbtree
- include/access
3 files changed
+162
-138
lines changedLines changed: 39 additions & 29 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
33 | 33 |
| |
34 | 34 |
| |
35 | 35 |
| |
36 |
| - | |
| 36 | + | |
37 | 37 |
| |
38 | 38 |
| |
39 | 39 |
| |
| |||
1500 | 1500 |
| |
1501 | 1501 |
| |
1502 | 1502 |
| |
1503 |
| - | |
| 1503 | + | |
1504 | 1504 |
| |
1505 | 1505 |
| |
1506 | 1506 |
| |
| |||
1556 | 1556 |
| |
1557 | 1557 |
| |
1558 | 1558 |
| |
| 1559 | + | |
1559 | 1560 |
| |
1560 | 1561 |
| |
1561 | 1562 |
| |
| |||
1604 | 1605 |
| |
1605 | 1606 |
| |
1606 | 1607 |
| |
1607 |
| - | |
| 1608 | + | |
1608 | 1609 |
| |
1609 | 1610 |
| |
1610 | 1611 |
| |
| |||
1621 | 1622 |
| |
1622 | 1623 |
| |
1623 | 1624 |
| |
1624 |
| - | |
| 1625 | + | |
1625 | 1626 |
| |
1626 |
| - | |
1627 |
| - | |
1628 |
| - | |
1629 |
| - | |
1630 |
| - | |
| 1627 | + | |
1631 | 1628 |
| |
1632 |
| - | |
| 1629 | + | |
1633 | 1630 |
| |
1634 |
| - | |
1635 |
| - | |
1636 |
| - | |
1637 |
| - | |
1638 |
| - | |
1639 |
| - | |
1640 |
| - | |
1641 |
| - | |
1642 |
| - | |
1643 |
| - | |
1644 |
| - | |
| 1631 | + | |
| 1632 | + | |
| 1633 | + | |
| 1634 | + | |
1645 | 1635 |
| |
1646 | 1636 |
| |
1647 | 1637 |
| |
1648 | 1638 |
| |
| 1639 | + | |
| 1640 | + | |
| 1641 | + | |
1649 | 1642 |
| |
1650 | 1643 |
| |
1651 |
| - | |
1652 |
| - | |
1653 | 1644 |
| |
| 1645 | + | |
| 1646 | + | |
1654 | 1647 |
| |
1655 | 1648 |
| |
1656 | 1649 |
| |
| |||
1746 | 1739 |
| |
1747 | 1740 |
| |
1748 | 1741 |
| |
1749 |
| - | |
| 1742 | + | |
1750 | 1743 |
| |
1751 | 1744 |
| |
1752 | 1745 |
| |
| |||
1768 | 1761 |
| |
1769 | 1762 |
| |
1770 | 1763 |
| |
1771 |
| - | |
| 1764 | + | |
1772 | 1765 |
| |
1773 |
| - | |
| 1766 | + | |
| 1767 | + | |
| 1768 | + | |
| 1769 | + | |
| 1770 | + | |
| 1771 | + | |
| 1772 | + | |
| 1773 | + | |
| 1774 | + | |
| 1775 | + | |
| 1776 | + | |
| 1777 | + | |
| 1778 | + | |
| 1779 | + | |
| 1780 | + | |
| 1781 | + | |
| 1782 | + | |
| 1783 | + | |
1774 | 1784 |
| |
1775 |
| - | |
| 1785 | + | |
1776 | 1786 |
| |
1777 | 1787 |
| |
1778 | 1788 |
| |
| |||
2276 | 2286 |
| |
2277 | 2287 |
| |
2278 | 2288 |
| |
2279 |
| - | |
| 2289 | + | |
2280 | 2290 |
| |
2281 | 2291 |
| |
2282 | 2292 |
| |
2283 | 2293 |
| |
2284 | 2294 |
| |
2285 | 2295 |
| |
2286 |
| - | |
| 2296 | + | |
2287 | 2297 |
| |
2288 | 2298 |
| |
2289 | 2299 |
| |
|
0 commit comments
Comments
(0)