From: Tom Lane
Subject: Re: Bad estimates
Date: ,
Msg-id: 12728.1511362917@sss.pgh.pa.us
(view: Whole thread, Raw)
In response to: Bad estimates  (Artur Zając)
Responses: RE: Bad estimates  (Artur Zając)
List: pgsql-performance

Tree view

Bad estimates  (Artur Zając, )
 Re: Bad estimates  (Don Seiler, )
  RE: Bad estimates  ("Alex Ignatov", )
 Re: Bad estimates (DEFAULT_UNK_SEL)  (Justin Pryzby, )
 Re: Bad estimates  (Tom Lane, )
  RE: Bad estimates  (Artur Zając, )
 Re: Bad estimates  (Laurenz Albe, )

Artur Zając <> 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:

From: "Henrik Cednert (Filmlance)"
Date:
Subject: Re: pg_dump 3 times as slow after 8.4 -> 9.5 upgrade
From: Patrick KUI-LI
Date:
Subject: Re: pg_dump 3 times as slow after 8.4 -> 9.5 upgrade