pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Vitaliy Garnashevich <vgarnashevich@gmail.com>
Cc: Postgres General <pgsql-general@postgresql.org>
Subject: Re: Tricking the optimizer
Date: Wed, 18 Apr 2018 09:51:11 -0400
Message-ID: <28215.1524059471@sss.pgh.pa.us> (raw)
In-Reply-To: <612dae0f-16b3-e5f8-7458-1ec38aea163c@gmail.com>
References: <612dae0f-16b3-e5f8-7458-1ec38aea163c@gmail.com>

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




view thread (4+ messages)  latest in thread

Message-ID: <28215.1524059471@sss.pgh.pa.us>
Permalink:  ../28215.1524059471@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/28215.1524059471@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, vgarnashevich@gmail.com
  Subject: Re: Tricking the optimizer
  In-Reply-To: <28215.1524059471@sss.pgh.pa.us>
  References: <612dae0f-16b3-e5f8-7458-1ec38aea163c@gmail.com> <28215.1524059471@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox