Unify "In" Sublink to EXIST Sublink for better optimize opportunity

From: Andy Fan <zhihui(dot)fan1213(at)gmail(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Unify "In" Sublink to EXIST Sublink for better optimize opportunity
Date: 2022-10-06 07:24:25
Message-ID: CAKU4AWqu=fZNX9zKh_ES-xjX3Om0J_aiJ9WhBCS8MrJcKvn=0A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Due to the implementation of convert_ANY_sublink_to_join, we have
limitations below, which has been discussed at [1] [2].

if (contain_vars_of_level((Node *) subselect, 1))
return NULL;

I'm thinking if we can do the ${subject}. If so, the query like

SELECT * FROM t1 WHERE
a IN (SELECT * FROM t2 WHERE t2.b > t1.b);

can be converted to

SELECT * FROM t1 WHERE
EXISTS (SELECT * FROM t2 WHERE t2.b > t1.b AND t1.a = t2.a);

Then the sublink can be removed with existing logic (the NOT-IN format
will not be touched since they have different meanings).

Any ideas?

[1] https://www.postgresql.org/message-id/3691.1342650974%40sss.pgh.pa.us
[2]
https://www.postgresql.org/message-id/CAN_9JTx7N+CxEQLnu_uHxx+EscSgxLLuNgaZT6Sjvdpt7toy3w@mail.gmail.com

--
Best Regards
Andy Fan

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2022-10-06 07:32:36 Re: shadow variables - pg15 edition
Previous Message Amit Kapila 2022-10-06 07:14:24 Re: hash_xlog_split_allocate_page: failed to acquire cleanup lock