Re: Order by (for 15 rows) adds 30 seconds to query time - Mailing list pgsql-performance

From Kevin Grittner
Subject Re: Order by (for 15 rows) adds 30 seconds to query time
Date
Msg-id 4B1522CE020000250002CEB1@gw.wicourts.gov
Whole thread Raw
In response to Order by (for 15 rows) adds 30 seconds to query time  (Richard Neill <rn214@cam.ac.uk>)
List pgsql-performance
Richard Neill <rn214@cam.ac.uk> wrote:

> I'd expect the ORDER BY to be the last thing that runs

>   Nested Loop Left Join  (cost=0.00..727737158.77
> rows=806903677108 width=195) (actual time=31739.052..32862.322
> rows=15 loops=1)

It probably would if it knew there were going to be 15 rows to sort.
It is estimating that there will be 806,903,677,108 rows, in which
case it thinks that using the index will be faster.  The question is
why it's 10 or 11 orders of magnitude off on the estimate of result
rows.  Could you show us the table definitions underlying that view?

-Kevin

pgsql-performance by date:

Previous
From: Richard Neill
Date:
Subject: Order by (for 15 rows) adds 30 seconds to query time
Next
From: Jean-Michel Pouré
Date:
Subject: Re: Order by (for 15 rows) adds 30 seconds to query time