Re: Statistics on array values

2020-02-02 Thread Marco Colli
Sorry, I don't understand your exact question about pg_stats. In any case I cannot make strict assumptions about data, because that greatly varies from project to project (it's a SaaS) and over time. To give an idea the table has some tens of millions of rows, each project has from a few thousands

Re: Statistics on array values

2020-02-02 Thread Tom Lane
Marco Colli writes: > Unfortunately I don't get actual improvements. I use PG 11 and I run the > following commands: > ALTER TABLE subscriptions ALTER tags SET STATISTICS 1000; > ANALYZE subscriptions; > However the bias remains pretty much the same (slightly worse after). Any > idea? So what hav

Re: Statistics on array values

2020-02-02 Thread Marco Colli
Thanks Tom for the clear explanation. Unfortunately I don't get actual improvements. I use PG 11 and I run the following commands: ALTER TABLE subscriptions ALTER tags SET STATISTICS 1000; ANALYZE subscriptions; However the bias remains pretty much the same (slightly worse after). Any idea? On S

Re: Statistics on array values

2020-02-02 Thread Tom Lane
Marco Colli writes: > Let's say that you have a simple query like the following on a large table > (for a multi-tenant application): > SELECT "subscribers".* FROM "subscribers" WHERE "subscribers"."project_id" > = 123 AND (tags @> ARRAY['de']::varchar[]); > If you run EXPLAIN ANALYZE you can see

Re: Statistics on array values

2020-02-02 Thread Marco Colli
> Is one of those estimates way off reality, or is it only the conjunction which is deranged? The estimate is wrong *even with a single tag*, without the conjunction (e.g. expected 3500, actual 20). Then the conjunction can make the bias even worse... On Sun, Feb 2, 2020 at 3:23 PM Justin Pryzby

Re: Statistics on array values

2020-02-02 Thread Justin Pryzby
On Sun, Feb 02, 2020 at 03:18:19PM +0100, Marco Colli wrote: > Hello! > > Let's say that you have a simple query like the following on a large table > (for a multi-tenant application): > SELECT "subscribers".* FROM "subscribers" WHERE "subscribers"."project_id" > = 123 AND (tags @> ARRAY['de']::va

Statistics on array values

2020-02-02 Thread Marco Colli
Hello! Let's say that you have a simple query like the following on a large table (for a multi-tenant application): SELECT "subscribers".* FROM "subscribers" WHERE "subscribers"."project_id" = 123 AND (tags @> ARRAY['de']::varchar[]); If you run EXPLAIN ANALYZE you can see that stats are complete