Re: Poor row estimates from planner, stat `most_common_elems` sometimes missing for a text[] column - Mailing list pgsql-performance

From Frédéric Yhuel
Subject Re: Poor row estimates from planner, stat `most_common_elems` sometimes missing for a text[] column
Date
Msg-id 3e539c8b-c95a-4ba9-8462-04045b2da2b0@dalibo.com
Whole thread Raw
In response to Poor row estimates from planner, stat `most_common_elems` sometimes missing for a text[] column  (Mark Frost <FROSTMAR@uk.ibm.com>)
Responses RE: Poor row estimates from planner, stat `most_common_elems` sometimes missing for a text[] column
List pgsql-performance

On 6/5/25 17:42, Mark Frost wrote:
> Is there any good explanation for this behaviour? Preferably we’d like 
> some way for proper `most_common_elems` statistics to be collected in 
> our production database, in the hope that influences a good query plan 
> to always be selected.


most_common_elems has a limited size, and if all the elements have the 
same freq, there's nothing we can do.

You could do: alter table test alter column tags set statistics X;

However, X is capped at 10000, which means that the size of 
most_common_elems will be less than 100k, and it would probably be 
stupid to go beyond that anyway.

It seems that postgres lacks some kind of "n_distinct_elems" for that 
kind of case, but let's wait and see what the statistics gurus think.



pgsql-performance by date:

Previous
From: Mark Frost
Date:
Subject: Poor row estimates from planner, stat `most_common_elems` sometimes missing for a text[] column
Next
From: "Mahdi Bahrami"
Date:
Subject: Re: Database creation performance drop going from pg 14 to pg 15+