Re: Why is there a Sort after an Index Only Scan? - Mailing list pgsql-performance

From Jeff Janes
Subject Re: Why is there a Sort after an Index Only Scan?
Date
Msg-id CAMkU=1yjuKjFKsZ3h2yuwGHCZxm==yp6C2gim-tXh6q3xK51Lg@mail.gmail.com
Whole thread Raw
In response to Why is there a Sort after an Index Only Scan?  (André Hänsel <andre@webkr.de>)
List pgsql-performance
On Wed, May 4, 2022 at 7:15 PM André Hänsel <andre@webkr.de> wrote:
Quick(?) question... why is there a Sort node after an Index Only Scan?
Shouldn't the index already spit out sorted tuples?

CREATE INDEX ON orders_test(shipping_date, order_id);

EXPLAIN ANALYZE SELECT
FROM orders_test
WHERE TRUE
AND shipping_date >= '2022-05-01'
AND shipping_date <= '2022-05-01'
ORDER BY order_id
LIMIT 50;

They are sorted by order_id only within sets of the same shipping_date, which is not good enough.  (It would be good enough if it were smart enough to know that there is only one possible shipping date to satisfy your weird range condition.)
 
Cheers,

Jeff

pgsql-performance by date:

Previous
From: André Hänsel
Date:
Subject: Why is there a Sort after an Index Only Scan?
Next
From: David Rowley
Date:
Subject: Re: Why is there a Sort after an Index Only Scan?