Re: BUG #18652: Planner can not find pathkey item to sort for query with expression and expression index

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: exclusion(at)gmail(dot)com
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #18652: Planner can not find pathkey item to sort for query with expression and expression index
Date: 2024-10-09 21:43:03
Message-ID: 2527690.1728510183@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
> The following query:
> CREATE TABLE t(i int, j int);
> CREATE INDEX idx on t((i + 0));

> SELECT * FROM t,
> (SELECT i + 0 AS i FROM
> (SELECT i FROM t UNION ALL SELECT i + 1 FROM t) AS t1
> ) AS t2
> WHERE t2.i = t.j;

> fails with:
> ERROR: XX000: could not find pathkey item to sort
> LOCATION: prepare_sort_from_pathkeys, createplan.c:6350

> The error occurs only when the expression in SELECT i + 0 AS i FROM
> matches the expression in an index.

> Reproduced on REL_10_STABLE .. master.

Hm, this seems quite an old bug: I can reproduce it on 9.1 but
not 9.0. Unfortunately, that's too far back to build easily
on modern platforms, so I'm not seeing a way to "git bisect"
for more insight.

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. More later.

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Euler Taveira 2024-10-10 00:56:00 Re: BUG #18635: " $libdir/adminpack could not be loaded" error with pg_upgrade to PostgreSQL17
Previous Message PG Bug reporting form 2024-10-09 21:00:01 BUG #18652: Planner can not find pathkey item to sort for query with expression and expression index