forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit0d861bb
committed
Add deduplication to nbtree.
Deduplication reduces the storage overhead of duplicates in indexes thatuse the standard nbtree index access method. The deduplication processis applied lazily, after the point where opportunistic deletion ofLP_DEAD-marked index tuples occurs. Deduplication is only applied atthe point where a leaf page split would otherwise be required. Newposting list tuples are formed by merging together existing duplicatetuples. The physical representation of the items on an nbtree leaf pageis made more space efficient by deduplication, but the logical contentsof the page are not changed. Even unique indexes make use ofdeduplication as a way of controlling bloat from duplicates whose TIDspoint to different versions of the same logical table row.The lazy approach taken by nbtree has significant advantages over a GINstyle eager approach. Most individual inserts of index tuples haveexactly the same overhead as before. The extra overhead ofdeduplication is amortized across insertions, just like the overhead ofpage splits. The key space of indexes works in the same way as it hassince commitdd299df (the commit that made heap TID a tiebreakercolumn).Testing has shown that nbtree deduplication can generally make indexeswith about 10 or 15 tuples for each distinct key value about 2.5X - 4Xsmaller, even with single column integer indexes (e.g., an index on areferencing column that accompanies a foreign key). The final size ofsingle column nbtree indexes comes close to the final size of a similarcontrib/btree_gin index, at least in cases where GIN's posting listcompression isn't very effective. This can significantly improvetransaction throughput, and significantly reduce the cost of vacuumingindexes.A new index storage parameter (deduplicate_items) controls the use ofdeduplication. The default setting is 'on', so all new B-Tree indexesautomatically use deduplication where possible. This decision will bereviewed at the end of the Postgres 13 beta period.There is a regression of approximately 2% of transaction throughput withsynthetic workloads that consist of append-only inserts into a tablewith several non-unique indexes, where all indexes have few or norepeated values. The underlying issue is that cycles are wasted onunsuccessful attempts at deduplicating items in non-unique indexes.There doesn't seem to be a way around it short of disablingdeduplication entirely. Note that deduplication of items in uniqueindexes is fairly well targeted in general, which avoids the problemthere (we can use a special heuristic to trigger deduplication passes inunique indexes, since we're specifically targeting "version bloat").Bump XLOG_PAGE_MAGIC because xl_btree_vacuum changed.No bump in BTREE_VERSION, since the representation of posting listtuples works in a way that's backwards compatible with version 4 indexes(i.e. indexes built on PostgreSQL 12). However, users must stillREINDEX a pg_upgrade'd index to use deduplication, regardless of thePostgres version they've upgraded from. This is the only way to set thenew nbtree metapage flag indicating that deduplication is generallysafe.Author: Anastasia Lubennikova, Peter GeogheganReviewed-By: Peter Geoghegan, Heikki LinnakangasDiscussion:https://postgr.es/m/55E4051B.7020209@postgrespro.ruhttps://postgr.es/m/4ab6e2db-bcee-f4cf-0916-3a06e6ccbb55@postgrespro.ru1 parent612a1ab commit0d861bb
File tree
28 files changed
+3553
-332
lines changed- contrib/amcheck
- doc/src/sgml
- ref
- src
- backend
- access
- common
- index
- nbtree
- rmgrdesc
- storage/page
- bin/psql
- include/access
- test/regress
- expected
- sql
28 files changed
+3553
-332
lines changedLines changed: 188 additions & 43 deletions
Large diffs are not rendered by default.
Lines changed: 199 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
557 | 557 |
| |
558 | 558 |
| |
559 | 559 |
| |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
560 | 751 |
| |
561 |
| - | |
562 |
| - | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
563 | 759 |
| |
564 | 760 |
| |
| 761 | + | |
565 | 762 |
| |
566 | 763 |
| |
567 | 764 |
|
Lines changed: 5 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
928 | 928 |
| |
929 | 929 |
| |
930 | 930 |
| |
931 |
| - | |
932 |
| - | |
933 |
| - | |
934 |
| - | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
935 | 936 |
| |
936 | 937 |
| |
937 | 938 |
| |
|
Lines changed: 4 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
233 | 233 |
| |
234 | 234 |
| |
235 | 235 |
| |
236 |
| - | |
237 |
| - | |
238 |
| - | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
239 | 240 |
| |
240 | 241 |
| |
241 | 242 |
| |
|
Lines changed: 5 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
16561 | 16561 |
| |
16562 | 16562 |
| |
16563 | 16563 |
| |
16564 |
| - | |
16565 |
| - | |
16566 |
| - | |
16567 |
| - | |
| 16564 | + | |
| 16565 | + | |
| 16566 | + | |
| 16567 | + | |
| 16568 | + | |
16568 | 16569 |
| |
16569 | 16570 |
| |
16570 | 16571 |
| |
|
Lines changed: 40 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
171 | 171 |
| |
172 | 172 |
| |
173 | 173 |
| |
| 174 | + | |
| 175 | + | |
174 | 176 |
| |
175 | 177 |
| |
176 | 178 |
| |
| |||
393 | 395 |
| |
394 | 396 |
| |
395 | 397 |
| |
396 |
| - | |
| 398 | + | |
397 | 399 |
| |
398 | 400 |
| |
399 | 401 |
| |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
400 | 431 |
| |
401 | 432 |
| |
402 | 433 |
| |
| |||
451 | 482 |
| |
452 | 483 |
| |
453 | 484 |
| |
454 |
| - | |
455 |
| - | |
456 |
| - | |
| 485 | + | |
457 | 486 |
| |
458 | 487 |
| |
459 | 488 |
| |
| |||
805 | 834 |
| |
806 | 835 |
| |
807 | 836 |
| |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
808 | 844 |
| |
809 | 845 |
| |
810 | 846 |
| |
|
Lines changed: 10 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
158 | 158 |
| |
159 | 159 |
| |
160 | 160 |
| |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
161 | 171 |
| |
162 | 172 |
| |
163 | 173 |
| |
|
Lines changed: 4 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
276 | 276 |
| |
277 | 277 |
| |
278 | 278 |
| |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
279 | 283 |
| |
280 | 284 |
| |
281 | 285 |
| |
|
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
14 | 14 |
| |
15 | 15 |
| |
16 | 16 |
| |
| 17 | + | |
17 | 18 |
| |
18 | 19 |
| |
19 | 20 |
| |
|
0 commit comments
Comments
(0)