- Notifications
You must be signed in to change notification settings - Fork4.9k
Commit3d351d9
committed
Redefine pg_class.reltuples to be -1 before the first VACUUM or ANALYZE.
Historically, we've considered the state with relpages and reltuplesboth zero as indicating that we do not know the table's tuple density.This is problematic because it's impossible to distinguish "never yetvacuumed" from "vacuumed and seen to be empty". In particular, a usercannot use VACUUM or ANALYZE to override the planner's normal heuristicthat an empty table should not be believed to be empty because it isprobably about to get populated. That heuristic is a good safetymeasure, so I don't care to abandon it, but there should be a way tooverride it if the table is indeed intended to stay empty.Hence, represent the initial state of ignorance by setting reltuplesto -1 (relpages is still set to zero), and apply the minimum-ten-pagesheuristic only when reltuples is still -1. If the table is empty,VACUUM or ANALYZE (but not CREATE INDEX) will override that toreltuples = relpages = 0, and then we'll plan on that basis.This requires a bunch of fiddly little changes, but we can get rid ofsome ugly kluges that were formerly needed to maintain the old definition.One notable point is that FDWs' GetForeignRelSize methods will seebaserel->tuples = -1 when no ANALYZE has been done on the foreign table.That seems like a net improvement, since those methods were formerlyalso in the dark about what baserel->tuples = 0 really meant. Still,it is an API change.I bumped catversion because code predating this change would get confusedby seeing reltuples = -1.Discussion:https://postgr.es/m/F02298E0-6EF4-49A1-BCB6-C484794D9ACC@thebuild.com1 parent9511fb3 commit3d351d9
File tree
20 files changed
+77
-69
lines changed- contrib
- file_fdw
- pgstattuple
- postgres_fdw
- doc/src/sgml
- src
- backend
- access
- gin
- heap
- nbtree
- table
- catalog
- commands
- optimizer
- path
- util
- postmaster
- rewrite
- utils/cache
- include
- access
- catalog
20 files changed
+77
-69
lines changedLines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
996 | 996 |
| |
997 | 997 |
| |
998 | 998 |
| |
999 |
| - | |
| 999 | + | |
1000 | 1000 |
| |
1001 | 1001 |
| |
1002 | 1002 |
| |
|
Lines changed: 3 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
195 | 195 |
| |
196 | 196 |
| |
197 | 197 |
| |
| 198 | + | |
| 199 | + | |
| 200 | + | |
198 | 201 |
| |
199 | 202 |
| |
200 | 203 |
| |
|
Lines changed: 3 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
692 | 692 |
| |
693 | 693 |
| |
694 | 694 |
| |
695 |
| - | |
696 |
| - | |
697 |
| - | |
| 695 | + | |
| 696 | + | |
698 | 697 |
| |
699 | 698 |
| |
700 | 699 |
| |
701 | 700 |
| |
702 | 701 |
| |
703 |
| - | |
| 702 | + | |
704 | 703 |
| |
705 | 704 |
| |
706 | 705 |
| |
|
Lines changed: 4 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1977 | 1977 |
| |
1978 | 1978 |
| |
1979 | 1979 |
| |
| 1980 | + | |
| 1981 | + | |
| 1982 | + | |
| 1983 | + | |
1980 | 1984 |
| |
1981 | 1985 |
| |
1982 | 1986 |
| |
|
Lines changed: 2 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
130 | 130 |
| |
131 | 131 |
| |
132 | 132 |
| |
133 |
| - | |
| 133 | + | |
| 134 | + | |
134 | 135 |
| |
135 | 136 |
| |
136 | 137 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
727 | 727 |
| |
728 | 728 |
| |
729 | 729 |
| |
730 |
| - | |
| 730 | + | |
731 | 731 |
| |
732 | 732 |
| |
733 | 733 |
| |
|
Lines changed: 15 additions & 23 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
208 | 208 |
| |
209 | 209 |
| |
210 | 210 |
| |
211 |
| - | |
| 211 | + | |
| 212 | + | |
212 | 213 |
| |
213 | 214 |
| |
214 | 215 |
| |
| |||
567 | 568 |
| |
568 | 569 |
| |
569 | 570 |
| |
570 |
| - | |
571 |
| - | |
572 |
| - | |
573 |
| - | |
574 |
| - | |
575 |
| - | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
576 | 575 |
| |
577 |
| - | |
578 |
| - | |
579 |
| - | |
580 |
| - | |
581 |
| - | |
582 |
| - | |
583 |
| - | |
| 576 | + | |
| 577 | + | |
584 | 578 |
| |
585 | 579 |
| |
586 | 580 |
| |
587 | 581 |
| |
588 | 582 |
| |
589 | 583 |
| |
590 |
| - | |
591 |
| - | |
592 |
| - | |
593 |
| - | |
594 |
| - | |
595 | 584 |
| |
596 | 585 |
| |
597 | 586 |
| |
| |||
612 | 601 |
| |
613 | 602 |
| |
614 | 603 |
| |
615 |
| - | |
| 604 | + | |
616 | 605 |
| |
617 | 606 |
| |
618 | 607 |
| |
| |||
1695 | 1684 |
| |
1696 | 1685 |
| |
1697 | 1686 |
| |
1698 |
| - | |
| 1687 | + | |
| 1688 | + | |
| 1689 | + | |
| 1690 | + | |
1699 | 1691 |
| |
1700 |
| - | |
| 1692 | + | |
1701 | 1693 |
| |
1702 | 1694 |
| |
1703 | 1695 |
| |
| |||
2434 | 2426 |
| |
2435 | 2427 |
| |
2436 | 2428 |
| |
2437 |
| - | |
| 2429 | + | |
2438 | 2430 |
| |
2439 | 2431 |
| |
2440 | 2432 |
| |
|
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
853 | 853 |
| |
854 | 854 |
| |
855 | 855 |
| |
| 856 | + | |
856 | 857 |
| |
857 | 858 |
| |
858 | 859 |
| |
|
Lines changed: 9 additions & 13 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
701 | 701 |
| |
702 | 702 |
| |
703 | 703 |
| |
704 |
| - | |
705 |
| - | |
706 |
| - | |
707 |
| - | |
708 |
| - | |
| 704 | + | |
709 | 705 |
| |
710 | 706 |
| |
711 | 707 |
| |
712 | 708 |
| |
713 | 709 |
| |
714 | 710 |
| |
715 |
| - | |
| 711 | + | |
716 | 712 |
| |
717 | 713 |
| |
718 | 714 |
| |
| |||
727 | 723 |
| |
728 | 724 |
| |
729 | 725 |
| |
730 |
| - | |
| 726 | + | |
731 | 727 |
| |
732 | 728 |
| |
733 | 729 |
| |
734 | 730 |
| |
735 |
| - | |
736 |
| - | |
737 |
| - | |
738 |
| - | |
739 |
| - | |
740 |
| - | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
741 | 737 |
| |
742 | 738 |
| |
743 | 739 |
| |
|
Lines changed: 2 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1015 | 1015 |
| |
1016 | 1016 |
| |
1017 | 1017 |
| |
1018 |
| - | |
| 1018 | + | |
1019 | 1019 |
| |
1020 | 1020 |
| |
1021 | 1021 |
| |
| |||
1027 | 1027 |
| |
1028 | 1028 |
| |
1029 | 1029 |
| |
1030 |
| - | |
| 1030 | + | |
1031 | 1031 |
| |
1032 | 1032 |
| |
1033 | 1033 |
| |
|
Lines changed: 9 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2722 | 2722 |
| |
2723 | 2723 |
| |
2724 | 2724 |
| |
| 2725 | + | |
| 2726 | + | |
| 2727 | + | |
| 2728 | + | |
| 2729 | + | |
| 2730 | + | |
| 2731 | + | |
| 2732 | + | |
| 2733 | + | |
2725 | 2734 |
| |
2726 | 2735 |
| |
2727 | 2736 |
| |
|
Lines changed: 6 additions & 8 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1128 | 1128 |
| |
1129 | 1129 |
| |
1130 | 1130 |
| |
1131 |
| - | |
1132 |
| - | |
| 1131 | + | |
| 1132 | + | |
1133 | 1133 |
| |
1134 | 1134 |
| |
1135 | 1135 |
| |
| |||
1152 | 1152 |
| |
1153 | 1153 |
| |
1154 | 1154 |
| |
1155 |
| - | |
1156 |
| - | |
1157 |
| - | |
| 1155 | + | |
1158 | 1156 |
| |
1159 | 1157 |
| |
1160 | 1158 |
| |
1161 | 1159 |
| |
1162 | 1160 |
| |
1163 |
| - | |
1164 |
| - | |
| 1161 | + | |
| 1162 | + | |
1165 | 1163 |
| |
1166 |
| - | |
| 1164 | + | |
1167 | 1165 |
| |
1168 | 1166 |
| |
1169 | 1167 |
| |
|
Lines changed: 5 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
912 | 912 |
| |
913 | 913 |
| |
914 | 914 |
| |
915 |
| - | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
916 | 920 |
| |
917 | 921 |
| |
918 | 922 |
| |
|
Lines changed: 4 additions & 7 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
974 | 974 |
| |
975 | 975 |
| |
976 | 976 |
| |
977 |
| - | |
978 |
| - | |
979 |
| - | |
980 |
| - | |
981 |
| - | |
982 | 977 |
| |
983 | 978 |
| |
984 | 979 |
| |
| |||
988 | 983 |
| |
989 | 984 |
| |
990 | 985 |
| |
| 986 | + | |
991 | 987 |
| |
992 | 988 |
| |
993 | 989 |
| |
| |||
1006 | 1002 |
| |
1007 | 1003 |
| |
1008 | 1004 |
| |
1009 |
| - | |
| 1005 | + | |
1010 | 1006 |
| |
1011 | 1007 |
| |
1012 | 1008 |
| |
1013 | 1009 |
| |
1014 |
| - | |
| 1010 | + | |
1015 | 1011 |
| |
1016 | 1012 |
| |
1017 | 1013 |
| |
| |||
1059 | 1055 |
| |
1060 | 1056 |
| |
1061 | 1057 |
| |
| 1058 | + | |
1062 | 1059 |
| |
1063 | 1060 |
| |
1064 | 1061 |
| |
|
Lines changed: 4 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
3080 | 3080 |
| |
3081 | 3081 |
| |
3082 | 3082 |
| |
| 3083 | + | |
| 3084 | + | |
| 3085 | + | |
| 3086 | + | |
3083 | 3087 |
| |
3084 | 3088 |
| |
3085 | 3089 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
621 | 621 |
| |
622 | 622 |
| |
623 | 623 |
| |
624 |
| - | |
| 624 | + | |
625 | 625 |
| |
626 | 626 |
| |
627 | 627 |
| |
|
Lines changed: 2 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1870 | 1870 |
| |
1871 | 1871 |
| |
1872 | 1872 |
| |
1873 |
| - | |
| 1873 | + | |
1874 | 1874 |
| |
1875 | 1875 |
| |
1876 | 1876 |
| |
| |||
3692 | 3692 |
| |
3693 | 3693 |
| |
3694 | 3694 |
| |
3695 |
| - | |
| 3695 | + | |
3696 | 3696 |
| |
3697 | 3697 |
| |
3698 | 3698 |
| |
|
Lines changed: 2 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
38 | 38 |
| |
39 | 39 |
| |
40 | 40 |
| |
41 |
| - | |
42 |
| - | |
| 41 | + | |
| 42 | + | |
43 | 43 |
| |
44 | 44 |
| |
45 | 45 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
53 | 53 |
| |
54 | 54 |
| |
55 | 55 |
| |
56 |
| - | |
| 56 | + | |
57 | 57 |
| |
58 | 58 |
|
Lines changed: 2 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
62 | 62 |
| |
63 | 63 |
| |
64 | 64 |
| |
65 |
| - | |
66 |
| - | |
| 65 | + | |
| 66 | + | |
67 | 67 |
| |
68 | 68 |
| |
69 | 69 |
| |
|
0 commit comments
Comments
(0)