Re: Improve rowcount estimate for UNNEST(column)

2024-01-04 Thread Tom Lane
Paul Jungwirth writes: > Here is a patch with an improved test. With the old "10" estimate we get a > Merge Join, but now that > the planner can see there are only ~4 elements per array, we get a Nested > Loop. Pushed with minor editorialization. I ended up not using the test case, because I

Re: Improve rowcount estimate for UNNEST(column)

2023-12-06 Thread Paul Jungwirth
Hello, On 11/26/23 12:22, Tom Lane wrote: > Yes, this regression test is entirely unacceptable; the numbers will > not be stable enough. Even aside from the different-settings issue, > you can't rely on ANALYZE deriving exactly the same stats every time. > Usually what we try to do is devise a

Re: Improve rowcount estimate for UNNEST(column)

2023-11-29 Thread jian he
On Mon, Nov 27, 2023 at 3:05 PM jian he wrote: > > Hi. > Since both array_op_test, arrest both are not dropped at the end of > src/test/regress/sql/arrays.sql. > I found using table array_op_test test more convincing. > > select > reltuples * 10 as original, > reltuples * (select

Re: Improve rowcount estimate for UNNEST(column)

2023-11-26 Thread jian he
Hi. Since both array_op_test, arrest both are not dropped at the end of src/test/regress/sql/arrays.sql. I found using table array_op_test test more convincing. select reltuples * 10 as original, reltuples * (select floor(elem_count_histogram[array_length(elem_count_histogram,1)])

Re: Improve rowcount estimate for UNNEST(column)

2023-11-26 Thread Tom Lane
Laurenz Albe writes: > On Sat, 2023-11-25 at 09:19 -0800, Paul A Jungwirth wrote: >> Here is a patch to improve rowcount estimates for >> `UNNEST(some_array_column)`. Today we hard code this to 10, but we >> have statistics about array size, so it's easy to use them. > The idea sounds good to

Re: Improve rowcount estimate for UNNEST(column)

2023-11-26 Thread Laurenz Albe
On Sat, 2023-11-25 at 09:19 -0800, Paul A Jungwirth wrote: > Here is a patch to improve rowcount estimates for > `UNNEST(some_array_column)`. Today we hard code this to 10, but we > have statistics about array size, so it's easy to use them. > > I've seen plans where this would make a difference.

Improve rowcount estimate for UNNEST(column)

2023-11-25 Thread Paul A Jungwirth
Hello, Here is a patch to improve rowcount estimates for `UNNEST(some_array_column)`. Today we hard code this to 10, but we have statistics about array size, so it's easy to use them. I've seen plans where this would make a difference. If the array has only 1 or 2 elements, then overestimating