Re: Why is there a Sort after an Index Only Scan?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: André Hänsel <andre(at)webkr(dot)de>
Cc: "'Pgsql Performance'" <pgsql-performance(at)lists(dot)postgresql(dot)org>
Subject: Re: Why is there a Sort after an Index Only Scan?
Date: 2022-05-05 02:08:59
Message-ID: 2604686.1651716539@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

=?UTF-8?Q?Andr=C3=A9_H=C3=A4nsel?= <andre(at)webkr(dot)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.728 rows=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

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Sudhir Guna 2022-05-10 16:59:01 DB connection issue suggestions
Previous Message André Hänsel 2022-05-05 01:12:40 RE: Why is there a Sort after an Index Only Scan?