Re: Bad estimates

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Bad estimates
Дата
Msg-id 12728.1511362917@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Bad estimates  (Artur Zając <azajac@ang.com.pl>)
Ответы RE: Bad estimates  (Artur Zając <azajac@ang.com.pl>)
Список 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 по дате отправления:

Предыдущее
От: Justin Pryzby
Дата:
Сообщение: Re: Bad estimates (DEFAULT_UNK_SEL)
Следующее
От: "Alex Ignatov"
Дата:
Сообщение: RE: Bad estimates