forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit3f44959
committed
Avoid unneeded nbtree backwards scan buffer locks.
Teach nbtree backwards scans to avoid relocking a just-read leaf page toread its current left sibling link when it isn't truly necessary. Thishappened inside _bt_readnextpage whenever _bt_readpage had alreadydetermined that there'll be no further matches to the left (or at leastnone for the current primitive index scan, for a scan with array keys).A new precheck inside _bt_readnextpage is all that we need to avoidthese useless lock acquisitions. Arguably, using a precheck like thiswas a missed opportunity for commit2ed5b87, which taught nbtree todrop leaf page pins early to avoid blocking cleanup by VACUUM. Forwardsscans already managed to avoid relocking the page like this.The optimization added by this commit is particularly helpful withbackwards scans that use array keys where the scan must perform multipleprimitive index scans. Such backwards scans will now avoid a uselessleaf page re-lock at the end of each primitive index scan.Note that this commit does not attempt to avoid needlessly re-locking aleaf page that was just read when the scan must follow the leaf page'sleft link. That more ambitious optimization could work by stashing theleft link when the page is first read by a backwards scan, allowing thesubsequent _bt_readnextpage call to optimistically skip re-reading theoriginal page just to get a new copy of its left link. For now we onlyaddress cases where we don't care about our original page's left link.Author: Peter Geoghegan <pg@bowt.ie>Reviewed-By: Matthias van de Meent <boekewurm+postgres@gmail.com>Discussion:https://postgr.es/m/CAH2-Wz=xgs7PojG=EUvhgadwENzu_mY_riNh-w9wFPsaS717ew@mail.gmail.com1 parentf011e82 commit3f44959
1 file changed
+18
-5
lines changedOriginal file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1916 | 1916 |
| |
1917 | 1917 |
| |
1918 | 1918 |
| |
| 1919 | + | |
1919 | 1920 |
| |
1920 |
| - | |
1921 |
| - | |
1922 |
| - | |
1923 | 1921 |
| |
1924 |
| - | |
1925 | 1922 |
| |
1926 | 1923 |
| |
1927 | 1924 |
| |
1928 | 1925 |
| |
| 1926 | + | |
| 1927 | + | |
| 1928 | + | |
| 1929 | + | |
| 1930 | + | |
| 1931 | + | |
| 1932 | + | |
1929 | 1933 |
| |
1930 | 1934 |
| |
1931 | 1935 |
| |
| |||
2240 | 2244 |
| |
2241 | 2245 |
| |
2242 | 2246 |
| |
| 2247 | + | |
| 2248 | + | |
| 2249 | + | |
| 2250 | + | |
| 2251 | + | |
| 2252 | + | |
| 2253 | + | |
| 2254 | + | |
| 2255 | + | |
2243 | 2256 |
| |
2244 | 2257 |
| |
2245 | 2258 |
| |
| |||
2260 | 2273 |
| |
2261 | 2274 |
| |
2262 | 2275 |
| |
2263 |
| - | |
| 2276 | + | |
2264 | 2277 |
| |
2265 | 2278 |
| |
2266 | 2279 |
| |
|
0 commit comments
Comments
(0)