Commit 20b9fa3
committed
Build inherited extended stats on partitioned tables
Commit 859b300 disabled building of extended stats for inheritance
trees, to prevent updating the same catalog row twice. While that
resolved the issue, it also means there are no extended stats for
declaratively partitioned tables, because there are no data in the
non-leaf relations.
That also means declaratively partitioned tables were not affected by
the issue 859b300 addressed, which means this is a regression
affecting queries that calculate estimates for the whole inheritance
tree as a whole (which includes e.g. GROUP BY queries).
But because partitioned tables are empty, we can invert the condition
and build statistics only for the case with inheritance, without losing
anything. And we can consider them when calculating estimates.
It may be necessary to run ANALYZE on partitioned tables, to collect
proper statistics. For declarative partitioning there should no prior
statistics, and it might take time before autoanalyze is triggered. For
tables partitioned by inheritance the statistics may include data from
child relations (if built 859b300), contradicting the current code.
Report and patch by Justin Pryzby, minor fixes and cleanup by me.
Backpatch all the way back to PostgreSQL 10, where extended statistics
were introduced (same as 859b300).
Author: Justin Pryzby
Reported-by: Justin Pryzby
Backpatch-through: 10
Discussion: https://postgr.es/m/20210923212624.GI831%40telsasoft.com1 parent 74527c3 commit 20b9fa3
File tree
6 files changed
+77
-19
lines changed- src
- backend
- commands
- statistics
- utils/adt
- test/regress
- expected
- sql
6 files changed
+77
-19
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
549 | 549 | | |
550 | 550 | | |
551 | 551 | | |
| 552 | + | |
552 | 553 | | |
553 | 554 | | |
554 | 555 | | |
| |||
612 | 613 | | |
613 | 614 | | |
614 | 615 | | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
615 | 631 | | |
616 | 632 | | |
617 | 633 | | |
618 | 634 | | |
619 | 635 | | |
620 | 636 | | |
621 | | - | |
| 637 | + | |
622 | 638 | | |
623 | 639 | | |
624 | 640 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1418 | 1418 | | |
1419 | 1419 | | |
1420 | 1420 | | |
1421 | | - | |
1422 | | - | |
| 1421 | + | |
| 1422 | + | |
| 1423 | + | |
| 1424 | + | |
| 1425 | + | |
1423 | 1426 | | |
1424 | | - | |
| 1427 | + | |
1425 | 1428 | | |
1426 | 1429 | | |
1427 | 1430 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1698 | 1698 | | |
1699 | 1699 | | |
1700 | 1700 | | |
1701 | | - | |
1702 | | - | |
| 1701 | + | |
| 1702 | + | |
| 1703 | + | |
| 1704 | + | |
| 1705 | + | |
1703 | 1706 | | |
1704 | | - | |
| 1707 | + | |
1705 | 1708 | | |
1706 | 1709 | | |
1707 | 1710 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3913 | 3913 | | |
3914 | 3914 | | |
3915 | 3915 | | |
3916 | | - | |
3917 | | - | |
3918 | | - | |
3919 | | - | |
3920 | | - | |
3921 | | - | |
3922 | | - | |
3923 | | - | |
| 3916 | + | |
3924 | 3917 | | |
3925 | 3918 | | |
3926 | 3919 | | |
3927 | 3920 | | |
3928 | 3921 | | |
| 3922 | + | |
| 3923 | + | |
| 3924 | + | |
| 3925 | + | |
| 3926 | + | |
| 3927 | + | |
| 3928 | + | |
| 3929 | + | |
| 3930 | + | |
| 3931 | + | |
| 3932 | + | |
3929 | 3933 | | |
3930 | 3934 | | |
3931 | 3935 | | |
| |||
5242 | 5246 | | |
5243 | 5247 | | |
5244 | 5248 | | |
5245 | | - | |
5246 | | - | |
5247 | | - | |
| 5249 | + | |
| 5250 | + | |
| 5251 | + | |
| 5252 | + | |
| 5253 | + | |
| 5254 | + | |
5248 | 5255 | | |
5249 | | - | |
| 5256 | + | |
5250 | 5257 | | |
5251 | 5258 | | |
5252 | 5259 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
217 | 217 | | |
218 | 218 | | |
219 | 219 | | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
220 | 239 | | |
221 | 240 | | |
222 | 241 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
134 | 134 | | |
135 | 135 | | |
136 | 136 | | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
137 | 147 | | |
138 | 148 | | |
139 | 149 | | |
| |||
0 commit comments