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 1szAbh-004ac7-93 for pgsql-bugs@arkaria.postgresql.org; Fri, 11 Oct 2024 08:02:42 +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 1szAbf-00GlQp-Jj for pgsql-bugs@arkaria.postgresql.org; Fri, 11 Oct 2024 08:02:39 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1szAbf-00GlO0-6g for pgsql-bugs@lists.postgresql.org; Fri, 11 Oct 2024 08:02:39 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1szAbc-000Ks2-47 for pgsql-bugs@lists.postgresql.org; Fri, 11 Oct 2024 08:02:38 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1728633752; bh=UdRlAGwCtw0/Gne0+HvvciYf44KYhcK8kA1QW5AFtmc=; h=Message-ID:Date:User-Agent:Subject:To:Cc:References:From: In-Reply-To:From; b=172G/rCh65GpCMOZ/PF+TaTrrLKjVSdiOKhgAim4RuM4elbuEsNzG0hI1RTTAnhrj lQlctaBMx9yyy9FUqTqjbvptmGPWGBN8aZhxtnt2nf1uI0sT6em1j1XS4b9IA/U/S5 PG5GUa0MYOmZ5rUf/xGMJ1XCLBtv61ExCGbEjxejXspaWSiQ5AgVLBud9rNVzofoEi DHhGCagiQ96FJDNQ6HjBkLtb7NcrrC6dB2OpKeJySmAX8B0FoL6U2BASV33LX8emGV x7di3D6CUC4aAs7afcH/liGev48CNBwP52ZzCD+ecjIIb+94DjyYqhwTtgySsLD934 X77dH6tXzg/+A== Received: from [192.168.108.77] (unknown [212.233.84.142]) (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 78E8860AB1; Fri, 11 Oct 2024 11:02:32 +0300 (MSK) Message-ID: <4266190e-a11b-4f0a-b663-e9059aecdc90@postgrespro.ru> Date: Fri, 11 Oct 2024 11:02:31 +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 To: Richard Guo Cc: Tom Lane , exclusion@gmail.com, pgsql-bugs@lists.postgresql.org, Andrei Lepikhov References: <18652-deaa782ebcca85d1@postgresql.org> <2527690.1728510183@sss.pgh.pa.us> <2572174.1728534842@sss.pgh.pa.us> Content-Language: en-US From: Alena Rybakina In-Reply-To: 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 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? -- Regards, Alena Rybakina Postgres Professional