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

From Tom Lane
Subject Re: Why is there a Sort after an Index Only Scan?
Date
Msg-id 2604686.1651716539@sss.pgh.pa.us
Whole thread Raw
In response to RE: Why is there a Sort after an Index Only Scan?  (André Hänsel <andre@webkr.de>)
List pgsql-performance
=?UTF-8?Q?Andr=C3=A9_H=C3=A4nsel?= <andre@webkr.de> writes:
> Limit  (cost=0.43..296.63 rows=50 width=4) (actual time=1052.692..1052.737 rows=50 loops=1)
>   ->  Index Scan using orders_test_pkey on orders_test  (cost=0.43..71149.43 rows=12010 width=4) (actual
time=1052.690..1052.728rows=50 loops=1) 
>         Filter: ((shipping_date >= '2022-04-30'::date) AND (shipping_date <= '2022-05-01'::date))
>         Rows Removed by Filter: 1998734

> Is it overestimating the cost of the sorting?

No, but it's guessing it will hit 50 rows that satisfy the filter
before it's gone very far in this index.  If the shipping date and
pkey are correlated in the wrong direction, that could be a very
overoptimistic guess.  I don't think we have adequate stats yet
to detect this sort of problem.

            regards, tom lane



pgsql-performance by date:

Previous
From: André Hänsel
Date:
Subject: RE: Why is there a Sort after an Index Only Scan?
Next
From: Sudhir Guna
Date:
Subject: DB connection issue suggestions