Index ordering after IS NULL - Mailing list pgsql-hackers

From Jeff Janes
Subject Index ordering after IS NULL
Date
Msg-id CAMkU=1xSOGCwyJ9d+g9B7WA9qv5k_wKskhihB6uNi3TG65Pyog@mail.gmail.com
Whole thread Raw
Responses Re: Index ordering after IS NULL
Re: Index ordering after IS NULL
List pgsql-hackers
On a two-column btree index, we can constrain the first column with equality and read the rows in order by the 2nd column.  But we can't constrain the first column by IS NULL and still read the rows in order by the 2nd column.  But why not?  Surely the structure of the btree index would allow for this to work.

Example:

create table if not exists j as select case when random()<0.9 then floor(random()*10)::int end b, random() c from generate_series(1,1000000);
create index if not exists j_b_c_idx on j (b,c);
set enable_sort TO off;
explain analyze select * from j where b is null order by c limit 10;
explain analyze select * from j where b =8 order by c limit 10;
 
The first uses a sort despite it being disabled.

Cheers,

Jeff

pgsql-hackers by date:

Previous
From: Nathan Bossart
Date:
Subject: Re: archive modules
Next
From: Michael Banck
Date:
Subject: Re: Support load balancing in libpq