public inbox for [email protected]  
help / color / mirror / Atom feed
From: Andrei Lepikhov <[email protected]>
To: Paul George <[email protected]>
To: [email protected]
Subject: Re: inequality predicate not pushed down in JOIN?
Date: Fri, 12 Jul 2024 06:49:34 +0700
Message-ID: <[email protected]> (raw)
In-Reply-To: <CALA8mJr2zKNBMqD=f-Ts-2CYtOUyvFJ7Z2wQVe3wkOnqZL1BJw@mail.gmail.com>
References: <CALA8mJr2zKNBMqD=f-Ts-2CYtOUyvFJ7Z2wQVe3wkOnqZL1BJw@mail.gmail.com>

On 12/7/2024 06:31, Paul George wrote:
> In the example below, I noticed that the JOIN predicate "t1.a<1" is not 
> pushed down to the scan over "t2", though it superficially seems like it 
> should be.
It has already discussed at least couple of years ago, see [1].
Summarising, it is more complicated when equivalences and wastes CPU 
cycles more probably than helps.

> 
> create table t as (select 1 a);
> analyze t;
> explain (costs off) select * from t t1 join t t2 on t1.a=t2.a and t1.a<1;
>            QUERY PLAN
> -------------------------------
>   Hash Join
>     Hash Cond: (t2.a = t1.a)
>     ->  Seq Scan on t t2
>     ->  Hash
>           ->  Seq Scan on t t1
>                 Filter: (a < 1)
> (6 rows)
> 
> The same is true for the predicate "t1.a in (0, 1)". For comparison, the 
> predicate "t1.a=1" does get pushed down to both scans.
> 
> explain (costs off) select * from t t1 join t t2 on t1.a=t2.a and t1.a=1;
>         QUERY PLAN
> -------------------------
>   Nested Loop
>     ->  Seq Scan on t t1
>           Filter: (a = 1)
>     ->  Seq Scan on t t2
>           Filter: (a = 1)
> (5 rows)

[1] Condition pushdown: why (=) is pushed down into join, but BETWEEN or 
 >= is not?
https://www.postgresql.org/message-id/flat/CAFQUnFhqkWuPCwQ1NmHYrisHJhYx4DoJak-dV%2BFcjyY6scooYA%40m...

-- 
regards, Andrei Lepikhov






view thread (4+ messages)  latest in thread

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 using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: inequality predicate not pushed down in JOIN?
  In-Reply-To: <[email protected]>

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

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