pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andrei Lepikhov <lepihov@gmail.com>
To: Richard Guo <guofenglinux@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: exclusion@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #18652: Planner can not find pathkey item to sort for query with expression and expression index
Date: Fri, 11 Oct 2024 11:25:47 +0700
Message-ID: <40c8a5c2-0040-4fe6-ab11-6dca23353a07@gmail.com> (raw)
In-Reply-To: <CAMbWs49Pcnm_cX=7azYY9d8+qRrOOKDjJDCa0KGRk9kWWMOz3A@mail.gmail.com>
References: <18652-deaa782ebcca85d1@postgresql.org>
	<2527690.1728510183@sss.pgh.pa.us>
	<CAMbWs49Pcnm_cX=7azYY9d8+qRrOOKDjJDCa0KGRk9kWWMOz3A@mail.gmail.com>

On 10/10/24 10:52, Richard Guo wrote:
> On Thu, Oct 10, 2024 at 5:43 AM Tom Lane <tgl@sss.pgh.pa.us> 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.
> I think this is because find_computable_ec_member() only tries to
> match Vars.  Maybe we should teach it to also match OpExprs?
Why not look if some entry of the TargetList contains the var? Something 
like attached?
If I understand correctly, MergeAppend will still add a resjunk column 
and Sort according to the column.

-- 
regards, Andrei Lepikhov

Attachments:

  [text/x-patch] probe.patch (727B, ../40c8a5c2-0040-4fe6-ab11-6dca23353a07@gmail.com/2-probe.patch)
  download | inline diff:
diff --git a/src/backend/optimizer/path/equivclass.c b/src/backend/optimizer/path/equivclass.c
index 8f6f005ecb..89ab29fe8e 100644
--- a/src/backend/optimizer/path/equivclass.c
+++ b/src/backend/optimizer/path/equivclass.c
@@ -899,11 +899,19 @@ is_exprlist_member(Expr *node, List *exprs)
 	foreach(lc, exprs)
 	{
 		Expr	   *expr = (Expr *) lfirst(lc);
+		List	   *tlexprs;
 
 		if (expr && IsA(expr, TargetEntry))
+		{
 			expr = ((TargetEntry *) expr)->expr;
+		}
+
+		tlexprs = pull_var_clause((Node *) expr,
+								   PVC_INCLUDE_AGGREGATES |
+								   PVC_INCLUDE_WINDOWFUNCS |
+								   PVC_INCLUDE_PLACEHOLDERS);
 
-		if (equal(node, expr))
+		if (list_member(tlexprs, node))
 			return true;
 	}
 	return false;


view thread (18+ messages)  latest in thread

Message-ID: <40c8a5c2-0040-4fe6-ab11-6dca23353a07@gmail.com>
Permalink:  ../40c8a5c2-0040-4fe6-ab11-6dca23353a07@gmail.com/
Also on:    postgresql.org/message-id/40c8a5c2-0040-4fe6-ab11-6dca23353a07@gmail.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: lepihov@gmail.com, guofenglinux@gmail.com, tgl@sss.pgh.pa.us, exclusion@gmail.com, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #18652: Planner can not find pathkey item to sort for query with expression and expression index
  In-Reply-To: <40c8a5c2-0040-4fe6-ab11-6dca23353a07@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox