Re: pgsql: Convert 'x IN (VALUES ...)' to 'x = ANY ...' then appropriate

From: Melanie Plageman <melanieplageman(at)gmail(dot)com>
To: Alexander Korotkov <akorotkov(at)postgresql(dot)org>
Cc: pgsql-committers(at)lists(dot)postgresql(dot)org, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: pgsql: Convert 'x IN (VALUES ...)' to 'x = ANY ...' then appropriate
Date: 2025-04-04 15:47:10
Message-ID: CAAKRu_bFn5xis9gugrnU3N8O6NN8WYncv5NedHfv3J65m_RZ8w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers pgsql-hackers

On Fri, Apr 4, 2025 at 9:17 AM Alexander Korotkov
<akorotkov(at)postgresql(dot)org> wrote:
>
> Convert 'x IN (VALUES ...)' to 'x = ANY ...' then appropriate
>
> This commit implements the automatic conversion of 'x IN (VALUES ...)' into
> ScalarArrayOpExpr. That simplifies the query tree, eliminating the appearance
> of an unnecessary join.

I haven't looked at this patch, but it seems likely that it is related
to the recent failures I noticed in CI in the subselect test when the
regress suite is run by 002_pg_upgrade.pl

diff --strip-trailing-cr -U3
C:/cirrus/src/test/regress/expected/subselect.out
C:/cirrus/build/testrun/pg_upgrade/002_pg_upgrade/data/results/subselect.out
--- C:/cirrus/src/test/regress/expected/subselect.out 2025-04-04
14:44:17.637206600 +0000
+++ C:/cirrus/build/testrun/pg_upgrade/002_pg_upgrade/data/results/subselect.out
2025-04-04 14:47:20.358393500 +0000
@@ -2769,15 +2769,16 @@
EXPLAIN (COSTS OFF)
SELECT c.oid,c.relname FROM pg_class c JOIN pg_am a USING (oid)
WHERE c.oid IN (VALUES (1), (2));
- QUERY PLAN
----------------------------------------------------------------
- Hash Join
- Hash Cond: (a.oid = c.oid)
- -> Seq Scan on pg_am a
- -> Hash
- -> Index Scan using pg_class_oid_index on pg_class c
- Index Cond: (oid = ANY ('{1,2}'::oid[]))
-(6 rows)
+ QUERY PLAN
+---------------------------------------------------------
+ Merge Join
+ Merge Cond: (c.oid = a.oid)
+ -> Index Scan using pg_class_oid_index on pg_class c
+ Index Cond: (oid = ANY ('{1,2}'::oid[]))
+ -> Sort
+ Sort Key: a.oid
+ -> Seq Scan on pg_am a
+(7 rows)

In response to

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2025-04-04 15:57:29 pgsql: Stabilize regression test from c0962a113.
Previous Message Melanie Plageman 2025-04-04 15:35:02 pgsql: Fix autoprewarm neglect of tablespaces

Browse pgsql-hackers by date

  From Date Subject
Next Message Marcos Pegoraro 2025-04-04 15:55:08 Exponential notation bug
Previous Message Rahila Syed 2025-04-04 15:45:34 Re: Improve monitoring of shared memory allocations