From: Irineu Ruiz [mailto:irineu@xxxxxxxxxxxxxxxx]
Sent: Thursday, June 18, 2015 3:10 PM
To: Igor Neyman
Cc: pgsql-performance@xxxxxxxxxxxxxx
Subject: Re: [PERFORM] How to calculate statistics for one column
I din't understood.
In this case, my statistics target should be approximately 349?
I already try this range but didn't work.
It's only work when I put 900 in my statistics.
There is some kind of formula to calculate a good statistics for a column like this?
2015-06-18 15:24 GMT-03:00 Igor Neyman <ineyman@xxxxxxxxxxxxxx>:
From: Irineu Ruiz [mailto:irineu@xxxxxxxxxxxxxxxx]
Sent: Thursday, June 18, 2015 2:18 PM
To: Igor Neyman
Cc: pgsql-performance@xxxxxxxxxxxxxx
Subject: Re: [PERFORM] How to calculate statistics for one column
SELECT COUNT(DISTINCT id_camada) FROM … equals
349
And it doesn't change significantly over time.
2015-06-18 15:16 GMT-03:00 Igor Neyman <ineyman@xxxxxxxxxxxxxx>:
From:
pgsql-performance-owner@xxxxxxxxxxxxxx [mailto:pgsql-performance-owner@xxxxxxxxxxxxxx]
On Behalf Of Irineu Ruiz
Sent: Thursday, June 18, 2015 1:53 PM
To: pgsql-performance@xxxxxxxxxxxxxx
Subject: [PERFORM] How to calculate statistics for one column
Hi,
I have a table with irregular distribution based in a foreign key, like you can see in the end of the e-mail.
Sometimes, in simples joins with another tables with the same id_camada (but not the table owner of the foreign key, the planner chooses a seq scan instead of use the index with
id_camada.
If I do the join using also de table owner of the foreign key, then the index is used.
In the first case, querys with seq scan tahe about 30 seconds and with the index take about 40 ms.
When I increase the statistics of the column id_camada to 900, then everything works using the index in both cases.
My doubt is: there is a way to discovery the best statistics number for this column or is a process of trial and error?
--
So what’s the result of:
SELECT COUNT(DISTINCT id_camada) FROM …
Does it change significantly over time?
Regards,
Igor Neyman
Then, I’d think that’s approximately your statistics target.
Regards,
Igor Neyman
Well, check if information in pg_stats for your table is correct:
http://www.postgresql.org/docs/9.4/static/view-pg-stats.html
Regards,
Igor Neyman
|