Re: pull-up subquery if JOIN-ON contains refs to upper-query
Alena Rybakina <a.rybakina@postgrespro.ru>
From: Alena Rybakina <a.rybakina@postgrespro.ru>
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Cc: Ranier Vilela <ranier.vf@gmail.com>,
Ilia Evdokimov <ilya.evdokimov@tantorlabs.com>
Date: 2025-02-09T15:14:09Z
Lists: pgsql-hackers
Attachments
- v3-0001-Add-appling-the-pull-up-transformation-for-expressio.patch (text/x-patch) patch v3-0001
Hi! I found another example where the transformation worked incorrectly and reconsidered the idea. As for conversion of exists_sublink_to_ANY, we need to get the flattened implicit-AND list of clauses and pull out the chunks of the WHERE clause that belong to the parent query, since we are called halfway through the parent's preprocess_expression() and earlier steps of preprocess_expression() wouldn't get applied to the pulled-up stuff unless we do them here. We also do some processing for vars depending on which side the var is on - if it's in a subquery, we only need to lower its level (varlevel) because subquery will be flatted, while for other vars that belong to the parent query, we need to do preparation to pull up the sub-select into top range table. For those expressions that we couldn't assign to either list, we define newWhere and apply both cases. -- Regards, Alena Rybakina Postgres Professional