forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit1bd4bc8
committed
Optimize nbtree backwards scans.
Make nbtree backwards scans optimistically access the next page to beread to the left by following a prevPage block number that's now stashedin currPos when the leaf page is first read. This approach matches theone taken during forward scans, which follow a symmetric nextPage blocknumber from currPos. We stash both a prevPage and a nextPage, since thescan direction might change (when fetching from a scrollable cursor).Backwards scans will no longer need to lock the same page twice, exceptin rare cases where the scan detects a concurrent page split (or pagedeletion). Testing has shown this optimization to be particularlyeffective during parallel index-only backwards scans: ~12% reductions inquery execution time are quite possible.We're much better off being optimistic; concurrent left sibling pagesplits are rare in general. It's possible that we'll need to lock morepages than the pessimistic approach would have, but only when there are_multiple_ concurrent splits of the left sibling page we now start at.If there's just a single concurrent left sibling page split, the newapproach to scanning backwards will at least break even relative to theold one (we'll acquire the same number of leaf page locks as before).The optimization from this commit has long been contemplated by commentsadded by commit2ed5b87, which changed the rules for locking/pinningduring nbtree index scans. The approach that that commit introduced toleaf level link traversal when scanning forwards is now more or lessapplied all the time, regardless of the direction we're scanning in.Following uniform conventions around sibling link traversal is simpler.The only real remaining difference between our forward and backwardshandling is that our backwards handling must still detect and recoverfrom any concurrent left sibling splits (and concurrent page deletions),as documented in the nbtree README. That is structured as a single,isolated extra step that takes place in _bt_readnextpage.Also use this opportunity to further simplify the functions that dealwith reading pages and traversing sibling links on the leaf level, andto document their preconditions and postconditions (with respect tothings like buffer locks, buffer pins, and seizing the parallel scan).This enhancement completely supersedes the one recently added by commit3f44959.Author: Matthias van de Meent <boekewurm+postgres@gmail.com>Author: Peter Geoghegan <pg@bowt.ie>Discussion:https://postgr.es/m/CAEze2WgpBGRgTTxTWVPXc9+PB6fc1a7t+VyGXHzfnrFXcQVxnA@mail.gmail.comDiscussion:https://postgr.es/m/CAH2-WzkBTuFv7W2+84jJT8mWZLXVL0GHq2hMUTn6c9Vw=eYrCw@mail.gmail.com1 parent9e2d813 commit1bd4bc8
File tree
4 files changed
+388
-466
lines changed- src
- backend/access/nbtree
- include/access
4 files changed
+388
-466
lines changedLines changed: 49 additions & 26 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
66 | 66 |
| |
67 | 67 |
| |
68 | 68 |
| |
69 |
| - | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
70 | 72 |
| |
71 | 73 |
| |
72 | 74 |
| |
| |||
550 | 552 |
| |
551 | 553 |
| |
552 | 554 |
| |
553 |
| - | |
| 555 | + | |
| 556 | + | |
554 | 557 |
| |
555 | 558 |
| |
556 | 559 |
| |
| |||
575 | 578 |
| |
576 | 579 |
| |
577 | 580 |
| |
578 |
| - | |
| 581 | + | |
| 582 | + | |
579 | 583 |
| |
580 | 584 |
| |
581 | 585 |
| |
| |||
591 | 595 |
| |
592 | 596 |
| |
593 | 597 |
| |
594 |
| - | |
595 |
| - | |
596 |
| - | |
597 |
| - | |
598 |
| - | |
599 |
| - | |
600 |
| - | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
601 | 605 |
| |
602 |
| - | |
| 606 | + | |
| 607 | + | |
603 | 608 |
| |
604 | 609 |
| |
605 |
| - | |
| 610 | + | |
| 611 | + | |
606 | 612 |
| |
607 | 613 |
| |
608 | 614 |
| |
609 | 615 |
| |
610 | 616 |
| |
611 | 617 |
| |
612 | 618 |
| |
613 |
| - | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
614 | 630 |
| |
615 | 631 |
| |
616 | 632 |
| |
| |||
660 | 676 |
| |
661 | 677 |
| |
662 | 678 |
| |
663 |
| - | |
| 679 | + | |
664 | 680 |
| |
665 | 681 |
| |
666 | 682 |
| |
| |||
688 | 704 |
| |
689 | 705 |
| |
690 | 706 |
| |
691 |
| - | |
| 707 | + | |
| 708 | + | |
692 | 709 |
| |
693 | 710 |
| |
694 | 711 |
| |
| |||
703 | 720 |
| |
704 | 721 |
| |
705 | 722 |
| |
706 |
| - | |
| 723 | + | |
707 | 724 |
| |
708 | 725 |
| |
709 |
| - | |
| 726 | + | |
710 | 727 |
| |
711 |
| - | |
712 |
| - | |
713 |
| - | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
714 | 734 |
| |
715 | 735 |
| |
716 |
| - | |
| 736 | + | |
| 737 | + | |
717 | 738 |
| |
718 | 739 |
| |
719 | 740 |
| |
| |||
722 | 743 |
| |
723 | 744 |
| |
724 | 745 |
| |
725 |
| - | |
| 746 | + | |
| 747 | + | |
726 | 748 |
| |
727 | 749 |
| |
728 | 750 |
| |
| |||
778 | 800 |
| |
779 | 801 |
| |
780 | 802 |
| |
781 |
| - | |
| 803 | + | |
782 | 804 |
| |
783 | 805 |
| |
784 | 806 |
| |
785 | 807 |
| |
786 | 808 |
| |
787 |
| - | |
| 809 | + | |
788 | 810 |
| |
789 | 811 |
| |
790 | 812 |
| |
| |||
796 | 818 |
| |
797 | 819 |
| |
798 | 820 |
| |
799 |
| - | |
| 821 | + | |
800 | 822 |
| |
801 | 823 |
| |
802 |
| - | |
| 824 | + | |
| 825 | + | |
803 | 826 |
| |
804 | 827 |
| |
805 | 828 |
| |
|
0 commit comments
Comments
(0)