pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andrei Lepikhov <lepihov@gmail.com>
To: Alexander Korotkov <aekorotkov@gmail.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Alena Rybakina <a.rybakina@postgrespro.ru>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Cc: Robert Haas <robertmhaas@gmail.com>
Cc: Richard Guo <guofenglinux@gmail.com>
Cc: Alexander Lakhin <exclusion@gmail.com>
Cc: Gregory Stark (as CFM) <stark.cfm@gmail.com>
Cc: Michał Kłeczek <michal@kleczek.org>
Cc: Dean Rasheed <dean.a.rasheed@gmail.com>
Subject: Re: Removing unneeded self joins
Date: Mon, 24 Feb 2025 13:22:35 +0100
Message-ID: <5b0ca934-4c61-4c29-8ad4-8988bed1ca0c@gmail.com> (raw)
In-Reply-To: <CAPpHfdsN8xSmZ+2vKK0m0--DfDJS8oOZsb-k5Qgk6Nv0v1qk9g@mail.gmail.com>
References: <64486b0b-0404-e39e-322d-0801154901f3@postgrespro.ru>
	<CAEZATCUeJ93gWCEzK1eRxyZakvv5PVG9LfF3PkSGMsNBC7h9kA@mail.gmail.com>
	<CAPpHfdsj1WdqoCg+g4oq1XQ_=KOj0U4pXqhauBc7e+0msHu66A@mail.gmail.com>
	<CAPpHfds16a7bjQHv-jCLMNzwdukJ_i3da2e0OJFB9L5rTCWEEg@mail.gmail.com>
	<ac7d7334-7ebb-4330-a894-12ba12ffa4ae@gmail.com>
	<CAPpHfdsuc524-BkXNZ+iz9dH=-KiU8qx9CSyE-Nip4Wjz5pGgg@mail.gmail.com>
	<ac34e44e-f8e1-4601-8bb8-fa5e65578832@gmail.com>
	<CAPpHfdvHzExyROoxvVQz6JR4tGVOjgNyHnu8xJmGcx-bMxWvqw@mail.gmail.com>
	<5934ce1e-be02-4640-904c-f7fec3962784@gmail.com>
	<CAPpHfdt9Z=iriS1Fj0Vyo41Z4cS+zUSZM8D3qXyw5LfHr_jVjA@mail.gmail.com>
	<CAPpHfdsFcde5VWCxSup7x_12ig6uynrFaOms62-M_c8DM-FTBQ@mail.gmail.com>
	<CAPpHfdseDr02BT+kFfW1ORWd0xnf9B=OUNmYkDxF2x-bE32UOw@mail.gmail.com>
	<914330.1740330169@sss.pgh.pa.us>
	<CAPpHfdt-F2CzQEEDZjhDB0pHMP-FdWt-jv6DVsO+5JZEGpTyTA@mail.gmail.com>
	<df21bd7e-5ec8-4e45-a339-b3a59ec48d1e@gmail.com>
	<CAPpHfdsN8xSmZ+2vKK0m0--DfDJS8oOZsb-k5Qgk6Nv0v1qk9g@mail.gmail.com>

On 24/2/2025 11:57, Alexander Korotkov wrote:
> Hi, Andrei!
> 
> Thank you for your feedback.
> 
> On Mon, Feb 24, 2025 at 12:12 AM Andrei Lepikhov <lepihov@gmail.com> wrote:
>> On 23/2/2025 22:15, Alexander Korotkov wrote:
>>> There is my attempt to implement this approach.  Getting rid of local
>>> variable (and computation of the same value other way) required to
>>> change arguments of remove_rel_from_eclass() as well.  I'm going to
>>> further polish this tomorrow.
>> I passed through the patch. It works correctly.
>>
>> Multiple ifs in a single routine is not ideal.
> 
> I would say there is a brachcing anyway.  Even if it is inside
> adjust_relid_set().  Patch makes it more explicit.  Ideal or not, I
> don't think it gets worse.
> 
>> I have thought about it
>> already, and it seems the remove_rel_from_query needs refactoring: when
>> I first reused it for self-join removal, we didn't have the 'ojrelid'
>> machinery, and it was implemented smoothly.
>> Right now, this code contains multiple places where we need to remove
>> the outer join relid and separating the removal code for the baserel and
>> outer join may simplify the logic and make it safer.
>> But the way to do it is not apparent now. May be if we implement a new
>> technique of query tree reduction, the approach will become more evident.
> 
> Could you, please, elaborate more on what you mean by "new technique
> of query tree reduction"?
I mean any transformations and optimisations that reduce search space 
for optimisation. Right now, I see the features reduce_unique_semijoins, 
remove_useless_joins, and remove_useless_self_joins.
In practice, I see at least a join on a foreign key, where some cases 
potentially allow the removal of the JOIN operator.

-- 
regards, Andrei Lepikhov





view thread (247+ messages)  latest in thread

Message-ID: <5b0ca934-4c61-4c29-8ad4-8988bed1ca0c@gmail.com>
Permalink:  ../5b0ca934-4c61-4c29-8ad4-8988bed1ca0c@gmail.com/
Also on:    postgresql.org/message-id/5b0ca934-4c61-4c29-8ad4-8988bed1ca0c@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 using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: lepihov@gmail.com, aekorotkov@gmail.com, tgl@sss.pgh.pa.us, a.rybakina@postgrespro.ru, pgsql-hackers@lists.postgresql.org, robertmhaas@gmail.com, guofenglinux@gmail.com, exclusion@gmail.com, stark.cfm@gmail.com, michal@kleczek.org, dean.a.rasheed@gmail.com
  Subject: Re: Removing unneeded self joins
  In-Reply-To: <5b0ca934-4c61-4c29-8ad4-8988bed1ca0c@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