Hashed IN only applied to first encountered IN
David Geier <geidav.pg@gmail.com>
From: David Geier <geidav.pg@gmail.com>
To: pgsql-hackers@lists.postgresql.org
Date: 2025-04-01T11:51:18Z
Lists: pgsql-hackers
Attachments
- example.sql (text/plain)
- 0001-Fixed-hashed-SAOP.patch (text/plain) patch 0001
Hi hackers, The hashed IN optimization is only applied to the first encountered ScalarArrayOpExpr during the expression tree traversal in convert_saop_to_hashed_saop_walker(). Reason being that the walker returns true which aborts the traversal. This can be exhibited by running a query with two IN statements vs the same query with just a single IN statement. The IN statements are combined via OR and both statements return no rows to prevent any kind of lazy evaluation optimizations. The query with two IN statements is 6x slower than the the query with the single IN statement. See the attached example. I've also attached a patch with a fix. -- David Geier (ServiceNow)
Commits
-
Fix planner's failure to identify multiple hashable ScalarArrayOpExprs
- b68f664bb024 14.18 landed
- a7f213b11d92 15.13 landed
- 5a0840b767cd 16.9 landed
- 5672a8399779 17.5 landed
- b136db07c651 18.0 landed