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 1szTWA-006GBZ-29 for pgsql-bugs@arkaria.postgresql.org; Sat, 12 Oct 2024 04:14:14 +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 1szTW6-00HGgc-Vt for pgsql-bugs@arkaria.postgresql.org; Sat, 12 Oct 2024 04:14:11 +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 1szTW6-00HGgR-Go for pgsql-bugs@lists.postgresql.org; Sat, 12 Oct 2024 04:14:10 +0000 Received: from mail-yw1-x112e.google.com ([2607:f8b0:4864:20::112e]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1szTW0-000Sol-Eg for pgsql-bugs@lists.postgresql.org; Sat, 12 Oct 2024 04:14:09 +0000 Received: by mail-yw1-x112e.google.com with SMTP id 00721157ae682-6e2d2447181so22594827b3.1 for ; Fri, 11 Oct 2024 21:14:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728706443; x=1729311243; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=9L7+69z66RW+HKeHSF/GCpFWT1vI4OR+juMImtTQZ54=; b=AKdb+NYNeW3kEDKPoYtlmqdL4vs990mCroi/k/3YSxyOezMVyn1LK04odTF+XjZAgy sNQKZpMu4Lfe8GyJ4vM6c7q80JB7iA/nzj8Pd0+XdWdSsWjYKop3zpIxO83tqqO5SgJS ahwKYSN9eHTedOeiFr5eQ87f9zORukihU+i7TG3Vr0uEk852L3NeEtVII5wOFcqIy41y 7XC7UoXjRe+iTm/meH4UoLeKn9uQkhKGH+6cbXKOTB9gVvbK6AX7AX8YaNwm8b+bCMoQ w9bGLNOeEsRNgPHOpFAEuFivhlWh07wigCFkP67B88mNYIWxqQ9xFPFeSDBudeVjs0tZ swxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728706443; x=1729311243; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9L7+69z66RW+HKeHSF/GCpFWT1vI4OR+juMImtTQZ54=; b=d81VuwJlub6VodYUpwMnS0kn4tKr8yhLg+mYvJjs7y6oYUrJP4fJyRq3wlNoqSoD27 2F2JzHclbVj1hkLGy5NPG66XDQeAvoEXZ/53LHiURTIuJXJle++MOrzHWUVbqF+SW0m0 P/aBl6q89e3Gxm7keApfiUIqEbVYcjNmFNYaASlXmklOALuqhSiv7t1VIVeFkShVYFrl DCWc22RjPFEx2XyqC+ZZDpg//MPJHYRHdXSJtPw+Fpp8deqtGDAuXfJCTBR7ZYBGdsFU Mu4VGj9qzHTuC5L33dppQtEBAKza6phRVMAuAZQGyBdTxni52KHkXtLJy7l9FYs7Hs/u Y2Ig== X-Forwarded-Encrypted: i=1; AJvYcCXshVYrZw4iEnumP1D9DZSmjth5Y0z9fN+oPS6gGlk6PlseQi0uuVGOeLcay1BA+dH4exu0HIQPrXRW@lists.postgresql.org X-Gm-Message-State: AOJu0YxIDqFyeMuo1rrQVB1UBHhGzwBG0J2Xc9h6ClDPcpKElksg8Tkn IVoOm0LoQdr7Q2BeR9ryw7UTjW5SirQKgV8fdhFvhM8lUVkCMLiFQLvZfZY73ZoUqM/s/OqHXg4 CoZYt7y13s2L3nlUJhYUJuB1nlgg= X-Google-Smtp-Source: AGHT+IGmxS1fJrsavV3zyX3omsdqj4/VH2f0woFe7wseSPGNDPuzpUjQZKkItuNSuIumIT3YyNIbuLJfbnOXCe1BHHQ= X-Received: by 2002:a05:690c:6c88:b0:6dd:bace:572 with SMTP id 00721157ae682-6e3479d9b66mr38818237b3.19.1728706443011; Fri, 11 Oct 2024 21:14:03 -0700 (PDT) MIME-Version: 1.0 References: <18652-deaa782ebcca85d1@postgresql.org> <2527690.1728510183@sss.pgh.pa.us> <40c8a5c2-0040-4fe6-ab11-6dca23353a07@gmail.com> <3001952.1728680364@sss.pgh.pa.us> In-Reply-To: <3001952.1728680364@sss.pgh.pa.us> From: Richard Guo Date: Sat, 12 Oct 2024 12:13:51 +0800 Message-ID: Subject: Re: BUG #18652: Planner can not find pathkey item to sort for query with expression and expression index To: Tom Lane Cc: Andrei Lepikhov , exclusion@gmail.com, pgsql-bugs@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sat, Oct 12, 2024 at 4:59=E2=80=AFAM Tom Lane wrote: > This means that it will work so long as all of the Vars needed by the > EC member expression are available from the plan node's input, which > they surely are if they are referenced in the existing tlist. That > is, even if we wanted to compute "t2.i + 2" it'd be fine. > > (This would fall down perhaps if there are volatile functions in > the sort expression, but I believe we already reject using volatile > expressions for merge append, so it's not a problem.) > > So I conclude that Andrei's patch will fix it, although I don't like > the way that that requires (potentially) multiple re-executions of > pull_var_clause. I think we should refactor the code to avoid that, > which actually ends up being less code, as in the attached draft. +1. I think it's conceptually correct that if 'Var_A + 2' is computable in a plan node's targetlist, then 'Var_A + 1' must be also computable in the same targetlist. Thanks Richard