Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1thsg9-007zej-N4 for pgsql-hackers@arkaria.postgresql.org; Tue, 11 Feb 2025 16:00:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1thsg5-00CFzP-I7 for pgsql-hackers@arkaria.postgresql.org; Tue, 11 Feb 2025 16:00:01 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1thsg5-00CFzC-2m for pgsql-hackers@lists.postgresql.org; Tue, 11 Feb 2025 16:00:01 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1thsg1-000Fjn-1a for pgsql-hackers@lists.postgresql.org; Tue, 11 Feb 2025 16:00:00 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1739289596; bh=1jfP+LkHdol2uQewzn8ObmuCApMn7crg9vc+oqlnJeU=; h=Message-ID:Date:User-Agent:Subject:To:Cc:References:From: In-Reply-To:From; b=S7ExZ3T7JrdAzb+s0XhguhPUIAB12LpikhNG7riGiZnZVNKUkIPgKbsxrZWMIZNTK +xs50sdnTCBaYoGUJb9giX6mRJ1RLxG8uVGnwyHV6hyKat2GT0nHgx6ULYXb8yo9e8 WWuJpMk4aPMPXnvnC5VN95a4Jg4aW3xQ/b3EyBc6+mC2ZC1DiYZAVm1hmAtHqQSIoM WThuw7062WdpgAM7WMU4ihnWoJrmYdFs5DebHYyDPCKPnYC6bICurGRMOFDCW1BriE Sg2QlWH1ffOF6TJtoH4GwonPYZC1KHhnu+I+gYYmuY9/fL79cmFFSNSnmBxye7TnC3 2ynkKq92ymq9w== Received: from [172.30.49.218] (unknown [172.30.49.218]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: a.rybakina@postgrespro.ru) by mail.postgrespro.ru (Postfix/587) with ESMTPSA id 3033C601DF; Tue, 11 Feb 2025 18:59:56 +0300 (MSK) Message-ID: <300d7bb0-345c-4c0b-a0ef-4de573fcc94b@postgrespro.ru> Date: Tue, 11 Feb 2025 18:59:55 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: pull-up subquery if JOIN-ON contains refs to upper-query To: Ilia Evdokimov Cc: PostgreSQL Hackers , Ranier Vilela References: <0b1f670d-b39d-4966-bf32-f0d502ebc564@postgrespro.ru> <46bc4eaf-58c5-42ab-8041-d3380a0768de@postgrespro.ru> <9b041978-06e3-4a50-8a5d-dacbb054f23e@tantorlabs.com> <8d7cbbf6-ddc0-4696-8af2-a68d740e14f2@postgrespro.ru> <6078f7e1-4b29-4b31-bd28-b84149e404e4@postgrespro.ru> <975a3736-a8b5-49b3-8009-4d4e86867aa1@postgrespro.ru> <0adbf75a-2059-4bb7-b878-c33892dbc1f0@tantorlabs.com> Content-Language: en-US From: Alena Rybakina In-Reply-To: <0adbf75a-2059-4bb7-b878-c33892dbc1f0@tantorlabs.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-KSMG-AntiPhishing: NotDetected X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.1.0.7854, bases: 2025/02/11 08:54:00 #27149591 X-KSMG-AntiVirus-Status: NotDetected, skipped X-KSMG-LinksScanning: not scanned, disabled by settings X-KSMG-Message-Action: skipped X-KSMG-Rule-ID: 1 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 10.02.2025 23:51, Ilia Evdokimov wrote: > > On 09.02.2025 18:14, Alena Rybakina wrote: >> 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. >> > > When I run 'make -C contrib/ check', tests of postgres_fdw extension > failed. I might be wrong, but you should be careful with LIMIT. > Thank you for the review, I'm working on it. -- Regards, Alena Rybakina Postgres Professional