Re: Tricking the optimizer

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Vitaliy Garnashevich <vgarnashevich(at)gmail(dot)com>
Cc: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Tricking the optimizer
Date: 2018-04-18 13:51:11
Message-ID: 28215.1524059471@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Vitaliy Garnashevich <vgarnashevich(at)gmail(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Melvin Davidson 2018-04-18 13:55:17 Re: How to fetch data from tables in PostgreSQL
Previous Message Adrian Klaver 2018-04-18 13:48:24 Re: How to fetch data from tables in PostgreSQL