pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andrei Lepikhov <lepihov@gmail.com>
To: Andres Freund <andres@anarazel.de>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Илья Жарков <izharkov1243@gmail.com>
Cc: pgsql-hackers@lists.postgresql.org
Cc: p.petrov@postgrespro.ru
Subject: Re: Do not scan index in right table if condition for left join evaluates to false using columns in left table
Date: Mon, 9 Dec 2024 09:35:57 +0700
Message-ID: <50b7ecd9-7512-479b-8096-2bda4e0e7ac1@gmail.com> (raw)
In-Reply-To: <texgbezbnhpeicm2cmqdv44odzqsuzrqjqh6mde4ouzect6utq@7q7utwldgbds>
References: <CAKE=rqQ-LHuh2eVsKC7ihkRJoCBZafSR72o3Xk4Xb=LcQMQfsA@mail.gmail.com>
	<tx2q6qi4hn2diocmnwfjo5xw2m56iabz3fyeimk7oeyymy3u4b@4ria2zwtz5mp>
	<3510224.1733609212@sss.pgh.pa.us>
	<lqgxfkrngt6zh6ldwiw6nkcanrcxn5sravsoum6r6s7xfc3oib@tcknx7ngik3l>
	<3517444.1733613195@sss.pgh.pa.us>
	<07d035c5-0e40-45ee-9c78-60a5dc6e9fae@gmail.com>
	<prmcdabei4jl24v7ubbd6rdwjwh4e2c3zgycq6nyxt3m5zo3qx@mz2i6l6r4jdv>
	<19969d0d-769c-42df-9ae5-3ca4ef2f44d0@gmail.com>
	<texgbezbnhpeicm2cmqdv44odzqsuzrqjqh6mde4ouzect6utq@7q7utwldgbds>

On 8/12/2024 23:37, Andres Freund wrote:
> On 2024-12-08 15:44:23 +0700, Andrei Lepikhov wrote:
>> On 8/12/2024 09:52, Andres Freund wrote:
>>>> I think avoiding touching a hash table and an index under MergeJoin can also
>>>> be beneficial.
>>>
>>> How would you get significant wins for mergejoins? You need to go through both
>>> inner and outer anyway?
> 
>> In my mind, this trick can be designed for specific cases like sales tables,
>> as illustrated before and used by well-rounded developers.
> 
> I'm not saying that the optimization isn't useful, just that i don't think it
> makes much sense for mergeoins.
> 
> Besides, at least as far as I can see, fundamentally not optimizing mergejoins
> in any substantial manner, it also just doesn't seem likely that queries where
> this optimization would come up are likely to be planned as mergejoins. If you
> have a leftjoin to a category-style table, you're very rarely going to scan
> the "main" table with an ordered index scan on the category key, which would
> be required for a merge join. And sorting the main table once for each
> to-be-joined-category-table isn't a desirable path most of the time either.
> 
> I don't know what it means that it's to be "used by well-rounded
> developers". We have to write the implementation in way it works regardless of
> what kind of developer is using postgres.
I got it, thanks. I agree that the profit for MJ & HJ cases looks 
modest. When designing the prototype, I realised that it seemed more 
"symmetrical" and logical to separate such 'one-sided' clauses during 
the planning for all types of join.
But I don't insist on this statement. It would be OK even in the case of 
NestLoop (remember, we should change the NL cost model too).

>> I'm not sure that such optimisation would be profitable in general.
> 
> Are you suggesting it would only be enabled by a GUC?
No, such a feature probably won't generate much overhead; I don't see 
any reason to cover it under a GUC.

-- 
regards, Andrei Lepikhov





view thread (23+ messages)  latest in thread

Message-ID: <50b7ecd9-7512-479b-8096-2bda4e0e7ac1@gmail.com>
Permalink:  ../50b7ecd9-7512-479b-8096-2bda4e0e7ac1@gmail.com/
Also on:    postgresql.org/message-id/50b7ecd9-7512-479b-8096-2bda4e0e7ac1@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-hackers@postgresql.org
  Cc: lepihov@gmail.com, andres@anarazel.de, tgl@sss.pgh.pa.us, izharkov1243@gmail.com, p.petrov@postgrespro.ru
  Subject: Re: Do not scan index in right table if condition for left join evaluates to false using columns in left table
  In-Reply-To: <50b7ecd9-7512-479b-8096-2bda4e0e7ac1@gmail.com>
  References: <CAKE=rqQ-LHuh2eVsKC7ihkRJoCBZafSR72o3Xk4Xb=LcQMQfsA@mail.gmail.com> <tx2q6qi4hn2diocmnwfjo5xw2m56iabz3fyeimk7oeyymy3u4b@4ria2zwtz5mp> <3510224.1733609212@sss.pgh.pa.us> <lqgxfkrngt6zh6ldwiw6nkcanrcxn5sravsoum6r6s7xfc3oib@tcknx7ngik3l> <3517444.1733613195@sss.pgh.pa.us> <07d035c5-0e40-45ee-9c78-60a5dc6e9fae@gmail.com> <prmcdabei4jl24v7ubbd6rdwjwh4e2c3zgycq6nyxt3m5zo3qx@mz2i6l6r4jdv> <19969d0d-769c-42df-9ae5-3ca4ef2f44d0@gmail.com> <texgbezbnhpeicm2cmqdv44odzqsuzrqjqh6mde4ouzect6utq@7q7utwldgbds> <50b7ecd9-7512-479b-8096-2bda4e0e7ac1@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