Re: Reversing NULLS in ORDER causes index not to be used? - Mailing list pgsql-performance

From Tom Lane
Subject Re: Reversing NULLS in ORDER causes index not to be used?
Date
Msg-id 226299.1608343379@sss.pgh.pa.us
Whole thread Raw
In response to Reversing NULLS in ORDER causes index not to be used?  (Ken Tanzer <ken.tanzer@gmail.com>)
Responses Re: Reversing NULLS in ORDER causes index not to be used?  (Ken Tanzer <ken.tanzer@gmail.com>)
List pgsql-performance
Ken Tanzer <ken.tanzer@gmail.com> writes:
> Hi.  I'm wondering if this is normal or at least known behavior?
> Basically, if I'm specifying a LIMIT and also  NULLS FIRST (or NULLS LAST
> with a descending sort), I get a sequence scan and a couple of orders of
> magnitude slower query.  Perhaps not relevantly, but definitely ironically,
> the sort field in question is defined to be NOT NULL.

The index won't get credit for matching the requested ordering if it's
got the wrong null-ordering polarity.  There's not an exception for
NOT NULL columns.  If you know the column hasn't got nulls, why are
you bothering with a nondefault null-ordering request?

            regards, tom lane



pgsql-performance by date:

Previous
From: Ken Tanzer
Date:
Subject: Reversing NULLS in ORDER causes index not to be used?
Next
From: Ken Tanzer
Date:
Subject: Re: Reversing NULLS in ORDER causes index not to be used?