Re: BUG #18442: Unnecessary Sort operator in indexScan Plan

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: hu_yajun(at)qq(dot)com
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #18442: Unnecessary Sort operator in indexScan Plan
Date: 2024-04-19 14:03:43
Message-ID: 2135177.1713535423@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:
> 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

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2024-04-19 14:09:26 BUG #18443: jsonb_agg issue. Again.
Previous Message Peter Petrov 2024-04-19 13:22:05 Re: BUG #18351: VACUUM FULL fails with error: missing chunk number 0 for toast value XXX