Re: BUG #18442: Unnecessary Sort operator in indexScan Plan - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #18442: Unnecessary Sort operator in indexScan Plan
Date
Msg-id 2135177.1713535423@sss.pgh.pa.us
Whole thread Raw
In response to BUG #18442: Unnecessary Sort operator in indexScan Plan  (PG Bug reporting form <noreply@postgresql.org>)
Responses Re: BUG #18442: Unnecessary Sort operator in indexScan Plan
List pgsql-bugs
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



pgsql-bugs by date:

Previous
From: Peter Petrov
Date:
Subject: Re: BUG #18351: VACUUM FULL fails with error: missing chunk number 0 for toast value XXX
Next
From: PG Bug reporting form
Date:
Subject: BUG #18443: jsonb_agg issue. Again.