pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: hu_yajun@qq.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #18442: Unnecessary Sort operator in indexScan Plan
Date: Fri, 19 Apr 2024 10:03:43 -0400
Message-ID: <2135177.1713535423@sss.pgh.pa.us> (raw)
In-Reply-To: <18442-aca4c9134416990e@postgresql.org>
References: <18442-aca4c9134416990e@postgresql.org>

PG Bug reporting form <noreply@postgresql.org> writes:
> create index on t(a,b);
> postgres=# explain select * from t where a is null order by b; -- need
> sort
>                                    QUERY PLAN
> --------------------------------------------------------------------------------
>  Sort  (cost=9.54..9.80 rows=103 width=8)
>    Sort Key: b
>    ->  Index Only Scan using t_a_b_idx on t  (cost=0.29..6.10 rows=103
> width=8)
>          Index Cond: (a IS NULL)
> (4 rows)

Postgres doesn't detect that it could do this because "a IS NULL"
is not an equivalence condition.  You're not the first to suggest
that it could be treated as one, but I believe there are semantic
difficulties that would ensue.  One example is that given
"a IS NULL" and "a = b", the EquivalenceClass machinery would
think it can discard "a = b" and instead emit "b IS NULL",
which would not give the same answers.

			regards, tom lane





view thread (6+ messages)  latest in thread

Message-ID: <2135177.1713535423@sss.pgh.pa.us>
Permalink:  ../2135177.1713535423@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/2135177.1713535423@sss.pgh.pa.us

 · 

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: tgl@sss.pgh.pa.us, hu_yajun@qq.com, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #18442: Unnecessary Sort operator in indexScan Plan
  In-Reply-To: <2135177.1713535423@sss.pgh.pa.us>

* 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