Re: Tricking the optimizer - Mailing list pgsql-general

From Tom Lane
Subject Re: Tricking the optimizer
Date
Msg-id 28215.1524059471@sss.pgh.pa.us
Whole thread Raw
In response to Tricking the optimizer  (Vitaliy Garnashevich <vgarnashevich@gmail.com>)
Responses Re: Tricking the optimizer  (Vitaliy Garnashevich <vgarnashevich@gmail.com>)
List pgsql-general
Vitaliy Garnashevich <vgarnashevich@gmail.com> writes:
> Is there any trick to craft the query in such a way, so that to make the 
> optimizer believe that the filters would not remove any rows, and all 
> rows will likely be returned by the query?

If you don't mind writing some C code, you could create a dummy operator
that just returns its boolean argument, and attach a selectivity estimator
to it that returns 1.0.  Then you'd write the query as, perhaps,

WHERE ~~~(securityFilter1) AND ...

where ~~~ could be read as "likely()".  I wouldn't recommend using such a
wrapper for any WHERE clause that the optimizer had any intelligence about
at all, because it would defeat all of that.  But in this case you're
not getting any wins anyhow, so burying an opaque subselect in another
layer of opacity won't hurt.

            regards, tom lane


pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: How to fetch data from tables in PostgreSQL
Next
From: Melvin Davidson
Date:
Subject: Re: How to fetch data from tables in PostgreSQL