pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Łukasz Dąbek <sznurek@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Using b-tree index for >= condition when joining
Date: Sun, 17 May 2020 20:45:33 +0100
Message-ID: <b0d75b33-2006-15e3-047c-4487520b06cd@gmail.com> (raw)
In-Reply-To: <31575.1589685738@sss.pgh.pa.us>
References: <CAE2Xe9tLfLxE_pthPLFerywyA4RxtGTwMCqKpGk6VqMYOj6Lfw@mail.gmail.com>
	<31575.1589685738@sss.pgh.pa.us>

On 17/05/2020 at 04:22, Tom Lane wrote:> Note that you're not really 
getting the same plan that way: it's not
> a left join anymore, because you put a strict constraint on the join's
> inner relation, so the planner realizes it doesn't have to produce any
> null-extended rows.  You could make it work with the desired semantics
> with something along the lines of
> 
> SELECT * FROM tbl1 t1
>    LEFT JOIN (select * from tbl2 where tbl2.date >= '2019-04-21') t2
>    USING (date)
>    WHERE t1.date >= '2019-04-21';
> 
> but of course that's even less easy :-(

Thanks, I didn't realise my version of the query was incorrect.

It seems like there isn't much hope of creating a view equivalent to the 
query which would behave reasonably with "date >= CONST" constraint, or 
am I missing something? I think I can create a workaround using 
functions but would love to know if there's something simpler I could do.

Thanks,
Lukasz





view thread (3+ messages)

Message-ID: <b0d75b33-2006-15e3-047c-4487520b06cd@gmail.com>
Permalink:  ../b0d75b33-2006-15e3-047c-4487520b06cd@gmail.com/
Also on:    postgresql.org/message-id/b0d75b33-2006-15e3-047c-4487520b06cd@gmail.com

 · 

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: sznurek@gmail.com, tgl@sss.pgh.pa.us
  Subject: Re: Using b-tree index for >= condition when joining
  In-Reply-To: <b0d75b33-2006-15e3-047c-4487520b06cd@gmail.com>
  References: <CAE2Xe9tLfLxE_pthPLFerywyA4RxtGTwMCqKpGk6VqMYOj6Lfw@mail.gmail.com> <31575.1589685738@sss.pgh.pa.us> <b0d75b33-2006-15e3-047c-4487520b06cd@gmail.com>

* 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