Re: Bad estimates - Mailing list pgsql-performance

From Tom Lane
Subject Re: Bad estimates
Date
Msg-id 12728.1511362917@sss.pgh.pa.us
Whole thread Raw
In response to Bad estimates  (Artur Zając <azajac@ang.com.pl>)
Responses RE: Bad estimates  (Artur Zając <azajac@ang.com.pl>)
List pgsql-performance
Artur Zając <azajac@ang.com.pl> writes:
[ poor estimates for WHERE clauses like "(gs & 1) = 1" ]

Don't hold your breath waiting for that to get better on its own.
You need to work with the planner, not expect it to perform magic.
It has no stats that would help it discover what the behavior of
that sort of WHERE clause is; nor is there a good reason for it
to think that the selectivity of such a clause is only 0.5 rather
than something more in line with the usual behavior of an equality
constraint on an integer value.

One way you could attack the problem, if you're wedded to this data
representation, is to create expression indexes on the terms "(gs & x)"
for all the values of x you use.  Not only would that result in better
estimates (after an ANALYZE) but it would also open the door to satisfying
this type of query through an index search.  A downside is that updating
all those indexes could make DML on the table pretty expensive.

If you're not wedded to this data representation, consider replacing that
integer flags column with a bunch of boolean columns.  You might or might
not want indexes on the booleans, but in any case ANALYZE would create
stats that would allow decent estimates for "WHERE boolval".
        regards, tom lane


pgsql-performance by date:

Previous
From: Justin Pryzby
Date:
Subject: Re: Bad estimates (DEFAULT_UNK_SEL)
Next
From: "Alex Ignatov"
Date:
Subject: RE: Bad estimates