Commit 9391f71
committed
Teach estimate_array_length() to use statistics where available.
If we have DECHIST statistics about the argument expression, use
the average number of distinct elements as the array length estimate.
(It'd be better to use the average total number of elements, but
that is not currently calculated by compute_array_stats(), and
it's unclear that it'd be worth extra effort to get.)
To do this, we have to change the signature of estimate_array_length
to pass the "root" pointer. While at it, also change its result
type to "double". That's probably not really necessary, but it
avoids any risk of overflow of the value extracted from DECHIST.
All existing callers are going to use the result in a "double"
calculation anyway.
Paul Jungwirth, reviewed by Jian He and myself
Discussion: https://postgr.es/m/CA+renyUnM2d+SmrxKpDuAdpiq6FOM=FByvi6aS6yi__qyf6j9A@mail.gmail.com1 parent 14dd0f2 commit 9391f71
File tree
4 files changed
+45
-16
lines changed- src
- backend
- optimizer/path
- utils/adt
- include/utils
4 files changed
+45
-16
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1256 | 1256 | | |
1257 | 1257 | | |
1258 | 1258 | | |
1259 | | - | |
| 1259 | + | |
1260 | 1260 | | |
1261 | 1261 | | |
1262 | 1262 | | |
| |||
1283 | 1283 | | |
1284 | 1284 | | |
1285 | 1285 | | |
1286 | | - | |
| 1286 | + | |
1287 | 1287 | | |
1288 | 1288 | | |
1289 | 1289 | | |
| |||
4770 | 4770 | | |
4771 | 4771 | | |
4772 | 4772 | | |
4773 | | - | |
| 4773 | + | |
4774 | 4774 | | |
4775 | 4775 | | |
4776 | 4776 | | |
| |||
4808 | 4808 | | |
4809 | 4809 | | |
4810 | 4810 | | |
4811 | | - | |
| 4811 | + | |
4812 | 4812 | | |
4813 | 4813 | | |
4814 | 4814 | | |
| |||
4859 | 4859 | | |
4860 | 4860 | | |
4861 | 4861 | | |
4862 | | - | |
| 4862 | + | |
4863 | 4863 | | |
4864 | 4864 | | |
4865 | 4865 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6340 | 6340 | | |
6341 | 6341 | | |
6342 | 6342 | | |
6343 | | - | |
| 6343 | + | |
6344 | 6344 | | |
6345 | 6345 | | |
6346 | 6346 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2128 | 2128 | | |
2129 | 2129 | | |
2130 | 2130 | | |
2131 | | - | |
| 2131 | + | |
| 2132 | + | |
2132 | 2133 | | |
2133 | | - | |
2134 | | - | |
| 2134 | + | |
| 2135 | + | |
2135 | 2136 | | |
2136 | 2137 | | |
2137 | 2138 | | |
| |||
2152 | 2153 | | |
2153 | 2154 | | |
2154 | 2155 | | |
2155 | | - | |
| 2156 | + | |
2156 | 2157 | | |
2157 | | - | |
2158 | | - | |
| 2158 | + | |
| 2159 | + | |
| 2160 | + | |
| 2161 | + | |
| 2162 | + | |
| 2163 | + | |
| 2164 | + | |
| 2165 | + | |
| 2166 | + | |
| 2167 | + | |
| 2168 | + | |
| 2169 | + | |
| 2170 | + | |
| 2171 | + | |
| 2172 | + | |
| 2173 | + | |
| 2174 | + | |
| 2175 | + | |
| 2176 | + | |
| 2177 | + | |
| 2178 | + | |
| 2179 | + | |
| 2180 | + | |
| 2181 | + | |
| 2182 | + | |
| 2183 | + | |
| 2184 | + | |
2159 | 2185 | | |
| 2186 | + | |
| 2187 | + | |
| 2188 | + | |
2160 | 2189 | | |
2161 | 2190 | | |
2162 | 2191 | | |
| |||
6540 | 6569 | | |
6541 | 6570 | | |
6542 | 6571 | | |
6543 | | - | |
| 6572 | + | |
6544 | 6573 | | |
6545 | 6574 | | |
6546 | 6575 | | |
| |||
6820 | 6849 | | |
6821 | 6850 | | |
6822 | 6851 | | |
6823 | | - | |
| 6852 | + | |
6824 | 6853 | | |
6825 | 6854 | | |
6826 | 6855 | | |
| |||
7414 | 7443 | | |
7415 | 7444 | | |
7416 | 7445 | | |
7417 | | - | |
| 7446 | + | |
7418 | 7447 | | |
7419 | 7448 | | |
7420 | 7449 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
200 | 200 | | |
201 | 201 | | |
202 | 202 | | |
203 | | - | |
| 203 | + | |
204 | 204 | | |
205 | 205 | | |
206 | 206 | | |
| |||
0 commit comments