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 1sz5dM-0048C1-W3 for pgsql-bugs@arkaria.postgresql.org; Fri, 11 Oct 2024 02:44:04 +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 1sz5dL-00C7eV-8n for pgsql-bugs@arkaria.postgresql.org; Fri, 11 Oct 2024 02:44:03 +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 1sz5dL-00C7eN-0G for pgsql-bugs@lists.postgresql.org; Fri, 11 Oct 2024 02:44:03 +0000 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sz5dI-000RPD-0E for pgsql-bugs@lists.postgresql.org; Fri, 11 Oct 2024 02:44:02 +0000 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-71dfc1124cdso1228907b3a.1 for ; Thu, 10 Oct 2024 19:44:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728614638; x=1729219438; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id:from:to :cc:subject:date:message-id:reply-to; bh=RQKdX5Vw4B64aYvEUr0SXx97e8iucq4p9pTIbmaTA6s=; b=nmvw5UmoIi43QF+xYuAgM3A9HacBfGzAxE5tw/XmxjaMEV/hJo7DPdp9ABmgC/jGoa ki4CXocZ1UVF+tgQi5moQyB0IwRorQChOXtsUvx1F0cZervGziugc7JIQNic8z4U46tW X3MXxKQ6r1ZoJAXKpyUV4Cdb+erwiaOVJhBa7zAgXN9TazRcpBfxKGZ2uge+VkSVHy5O jhKr7z3S9VurguZDglMYPDfKD0ynpBKMEss3fH84vYU6iYJ3kq9aoB/t6lARH5nWCv7h u79WlfzMkX0SsZt1FUdjOO9SFm3A6EosIwKDBJer18NEDrK2kG+man0SuyljB9eo7/oV 3K4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728614638; x=1729219438; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=RQKdX5Vw4B64aYvEUr0SXx97e8iucq4p9pTIbmaTA6s=; b=EYS8pF/4FUPeNqTWJeGcvNzrXROBraz9EgLgKoSL93c8eryhc06ji3jCYnYEQ9asSu b/F5vJ7OVmvwUkU6d/JG2RrIFv/JzyIl4FCmEGVN/pydaSbg7jtO4eGdqWx9taUn65Me Ni5Rj6lc66Da92izCFvflUYrOhyatQs0Vp/nqJEr55N8PODyFDyTlsuKCSOMADjDviUG sMv6PL13NVyqw6+FSpJnHJA6WejjR81KOjSPqDxAgeRZu9vhNZIygGd5M2cHUpgTB028 uQadTiY9nHwyExEU02gDPc+LsNBRd1y7P5Yaw+Z3bcfN/1Jx4y25nUVbcyiGzgK6wnlm FrhQ== X-Forwarded-Encrypted: i=1; AJvYcCUrDFVdBvXYuLptlwfHx9K6vr3au/EORLXDP/58p0VH49LgI62c7HsNeoan09uAd790NHQ3wP+pjJsT@lists.postgresql.org X-Gm-Message-State: AOJu0Yz5eu1dvsFBbIjZAGHl1Cc6VWf1xsaLhI9kTpMDSvZAlxF0w30F BgE7Hw7xjUsDdoymAnM4npPcE5xXh4zqPKV9evquBSC0ZX+Yktrd X-Google-Smtp-Source: AGHT+IEjTIKAiUOC7VZbssC4g3aHbPZIBqtKSabO2/ThVTQAGRoJ/Gcz5JyNfQ8Z9oPaqXxnddD+hw== X-Received: by 2002:a05:6a00:6f44:b0:71e:190:c131 with SMTP id d2e1a72fcca58-71e26eff1d5mr8603488b3a.13.1728614638458; Thu, 10 Oct 2024 19:43:58 -0700 (PDT) Received: from [10.10.20.104] (node-sh5.pool-101-109.dynamic.totinternet.net. [101.109.144.41]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71e2aa0c8b6sm1783471b3a.92.2024.10.10.19.43.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 10 Oct 2024 19:43:57 -0700 (PDT) Message-ID: <8a09d059-8bcf-48de-8c8e-771d8221091c@gmail.com> Date: Fri, 11 Oct 2024 09:43:52 +0700 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: Andrei Lepikhov To: Tender Wang Cc: Richard Guo , exclusion@gmail.com, pgsql-bugs@lists.postgresql.org, Tom Lane References: <18652-deaa782ebcca85d1@postgresql.org> <2527690.1728510183@sss.pgh.pa.us> <8026fe90-e661-4448-b9cc-bcbb65629b7b@gmail.com> Content-Language: en-AU In-Reply-To: <8026fe90-e661-4448-b9cc-bcbb65629b7b@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 10/10/24 17:23, Andrei Lepikhov wrote: > On 10/10/24 16:02, Tender Wang wrote: >> >> >> Andrei Lepikhov > 于2024 >> 年      > I think this is because find_computable_ec_member() only >> tries to >>      > match Vars.  Maybe we should teach it to also match OpExprs? >>     Looking into that case, I don't understand only one thing: >>     generate_orderedappend_paths decided to try MergeAppend; the >>     create_append_path routine added the Sort cost,  but the Sort node >>     itself wasn't added. Maybe the origin problem is the lack of >>     feasibility >>     examinations? >> >> >> Yeah, I'm also curious why only cost Sort but not adding Sort node in >> create_merge_append_path(). >> The comments say that " We'll need to insert a Sort node, so include >> cost for that".  Does another place >> insert the Sort node? > Before inserting the Sort node, we must identify the column > corresponding to each path key. And here is the problem: IndexScan has > two elements in the target list, but SeqScan has only one. It already > looks strange to me. How do we UNION two sources with different numbers > of resulting columns? It seems to me we have a bug under the Append node.Sorry for the mess: my sentence is totally wrong: it is the MergeAppend node with two elements in the target list (the second one is resjunk). I think I should research the logic of how append arranges its pathkeys beforehand. -- regards, Andrei Lepikhov