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 1szD64-004qez-FX for pgsql-bugs@arkaria.postgresql.org; Fri, 11 Oct 2024 10:42:13 +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 1szD62-001YP3-LI for pgsql-bugs@arkaria.postgresql.org; Fri, 11 Oct 2024 10:42:11 +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 1szD62-001YOt-7p for pgsql-bugs@lists.postgresql.org; Fri, 11 Oct 2024 10:42:10 +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.94.2) (envelope-from ) id 1szD5y-000V62-SV for pgsql-bugs@lists.postgresql.org; Fri, 11 Oct 2024 10:42:09 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1728643326; bh=JPalidH3PzqcYqrpeBiMaYUC8g/JolguIb1gy+9hKIU=; h=Message-ID:Date:User-Agent:Subject:From:To:Cc:References: In-Reply-To:From; b=jmayYnGJjh7V9sw2bQW3xW29c36rHE1IxzCpUZ71khvUogRbBUQTNtrwjUjPtgpzh Ni2Kg8kxRFbxMO6T1FGm9KKBzbtScZ5tUb0/Lw0oIbvi5Lg0CSryjkxtrlVmN6Cziw GU7wr1aZmW99Mj+LMB0Ef95t+g1ULActFPuzqPxnagtBpNVbe/1tUY46LbXtyiT7PE rv/hkS9FolDvAa9uY8AAWcK0DBLraeK4XfJpEhzA5Kwti3uBrRLdRCvJK5UqfypuPd JspPwHV6FALMGbk7j9RArxKGPNPt7ka0K+mjgTG/TV90y4Hw4Vf3mLqU6RABfeuqcP FeGrkdokckSEg== Received: from [172.30.33.154] (unknown [172.30.33.154]) (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 6EF1460AB1; Fri, 11 Oct 2024 13:42:06 +0300 (MSK) Message-ID: Date: Fri, 11 Oct 2024 13:42:05 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: BUG #18652: Planner can not find pathkey item to sort for query with expression and expression index From: Alena Rybakina To: pgsql-bugs@lists.postgresql.org Cc: Tom Lane , exclusion@gmail.com, Andrei Lepikhov , Richard Guo References: <18652-deaa782ebcca85d1@postgresql.org> <2527690.1728510183@sss.pgh.pa.us> <2572174.1728534842@sss.pgh.pa.us> <4266190e-a11b-4f0a-b663-e9059aecdc90@postgrespro.ru> Content-Language: en-US In-Reply-To: <4266190e-a11b-4f0a-b663-e9059aecdc90@postgrespro.ru> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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: 2024/10/11 06:56:00 #26735348 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 11.10.2024 11:02, Alena Rybakina wrote: > On 10.10.2024 14:57, Richard Guo wrote: >> On Thu, Oct 10, 2024 at 12:34 PM Tom Lane wrote: >>> So it's specific to MergeAppend and it's been wrong from day zero. >>> That makes me think it's probably not find_computable_ec_member's >>> fault directly.  Fixing it there might be the most expedient answer, >>> but I feel like first we should drill down a bit further to understand >>> the root problem.  I'm too tired to do more tonight though. >> Usually a relation's targetlist should include only Vars and PHVs >> during this phase.  I think this may be the rationale behind >> find_computable_ec_member matching only Vars and quasi-Vars. However, >> for a child rel, when we copy the parent's targetlist with appropriate >> substitution, we may generate arbitrary expressions, such as an OpExpr >> for 'i + 1' in this case. >> >> We have a note in the comments in set_append_rel_size saying that >> >> * Code that might be looking at an appendrel child must cope with >> * such. >> >> It seems to me that find_computable_ec_member does not get this memo. >> >> Alternatively, can we wrap non-var expressions in a childrel's >> targetlist into PHVs, so that we do not need special handling for an >> appendrel child?  I have not tried this though. >> > To be honest, looking at the MergeAppend processing plan, it’s not > entirely clear to me what the functional difference is between > set_rel_pathlist and > > find_computable_ec_member. Both prepare pathkeys , but what the first > function doesn't do is what the other one needs to do?Could you > explain it to me? > Sorry, I meant add_child_rel_equivalences function I've just understood it. Sorry for noise -- Regards, Alena Rybakina Postgres Professional