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 1syn03-002B3Q-Bc for pgsql-bugs@arkaria.postgresql.org; Thu, 10 Oct 2024 06:50:16 +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 1syn01-00CfzH-3Z for pgsql-bugs@arkaria.postgresql.org; Thu, 10 Oct 2024 06:50:13 +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 1syn00-00Cfz8-QT for pgsql-bugs@lists.postgresql.org; Thu, 10 Oct 2024 06:50:13 +0000 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1symzu-000Inf-8F for pgsql-bugs@lists.postgresql.org; Thu, 10 Oct 2024 06:50:12 +0000 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-20bb39d97d1so5040845ad.2 for ; Wed, 09 Oct 2024 23:50:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728543005; x=1729147805; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=dy5OcL/4lfWgvx7cQaerXBv68d8ynZTAwyIS0R39cUA=; b=GMf7KvgHcLotci1TIz2DII+3blyL+6vso83IoC/1zv3V3UkxpFB/ldkbzURjv7AUGA v2qXa5ghdihOV9KSZJrP4+poL+C+j8zk8ffy24exhd0y+BXs2sTafbj8MDfKSFueo6TY bW4VX+nsciX+NwfdLLT8bd6AviFd0Ngzj/imUDFPJWJEruJ2A8ipmx0h+SJz6RK2Ikwt jSq9JLvoYqe1UL1SCVuEziUCwRa3lNbtqb5n1QoXLMhxBKFIsVqeYYZgDrxZnd12z8Qs vl+nfzegVfQROs1oXMU3tVgIRlA9dQaqYcw8UTPdMN26aZEsuv7fWUSGhdOO3NdrnRHd wC3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728543005; x=1729147805; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dy5OcL/4lfWgvx7cQaerXBv68d8ynZTAwyIS0R39cUA=; b=e3YMzKYY6FWcvpubu+zAXpa3mG3Sh4zVtl9MdYjWXBczsSyeZ+/ZmEqbRx0LbN65qN 9Edf78H8oAIAvhcI/I3cm12E5kFYYqjgyXuxCRgJW02gc+lwAJNzZezMebxqANFZoz4j 001s/Cpn1WufUBnL3q39aC41dzkLBjI/hMdWse4dRaYbwc+xCNdw+q50EFeJPnKd00uA PqLwU7mg9PkZsnb3rtnEAbR5GBtNAsb4WwFRhW7+UKrOx/O9S8Emm54dJsv2LGBwyl1V qBsW5mYr7r3VmqXV5yAwtev7vnEojqZgwOKCVTsnPtyOa5ccaABnkktvSPj/l6iup+i0 atAw== X-Forwarded-Encrypted: i=1; AJvYcCXEvCz4LiDisBApiS7dzbDWfj9Ru9+H+yz5k73Lkrocd8UCxsxqIEaoXnKgz1F+Qv0k8d+4fsbgpy2S@lists.postgresql.org X-Gm-Message-State: AOJu0Yy49pw265cdOB2RwSNF9YitEqrSbeKv4ZlW6zzR2O3w/gUdKJ+i mD0YOwIctFwFi5ehwoMRmsW8i6E2Nq6QqfhVE1P3r9gq6TxhHlkz X-Google-Smtp-Source: AGHT+IFg3wlXpMwbN9oM4BvDE4kgFrR1ivbhKkJ3FwAe9vvp58fCs4yjdDzAcfIknXNtzfWW3OsWAQ== X-Received: by 2002:a17:903:2445:b0:20c:6bff:fcc0 with SMTP id d9443c01a7336-20c7ed4c243mr35824965ad.56.1728543005067; Wed, 09 Oct 2024 23:50:05 -0700 (PDT) Received: from [10.10.20.104] (node-t06.pool-101-109.dynamic.totinternet.net. [101.109.146.214]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20c8c215ed4sm3927985ad.217.2024.10.09.23.50.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 09 Oct 2024 23:50:04 -0700 (PDT) Message-ID: Date: Thu, 10 Oct 2024 13:50:01 +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 To: Richard Guo Cc: exclusion@gmail.com, pgsql-bugs@lists.postgresql.org, Tom Lane References: <18652-deaa782ebcca85d1@postgresql.org> <2527690.1728510183@sss.pgh.pa.us> Content-Language: en-AU From: Andrei Lepikhov In-Reply-To: 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 10:52, Richard Guo wrote: > On Thu, Oct 10, 2024 at 5:43 AM Tom Lane wrote: >> It looks like we are generating a Path tree in which one of the >> inputs to a MergeAppend is a plain unsorted seqscan, which'd >> be all right except it doesn't expose the required sort value >> in its targetlist. > > Correct. In addition, find_computable_ec_member() fails to find a > computable expression from its targetlist. > For the indexscan path, find_computable_ec_member() is able to find > (t.i + 0) which can be computed from its tlist item 't.i'. > > For the seqscan path, though, find_computable_ec_member() is not able > to find ((t_1.i + 1) + 0) from its tlist item '(t_1.i + 1)'. > > 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? -- regards, Andrei Lepikhov