Re: EXPLAIN ANALYZE output weird for Top-N Sort

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Simon Riggs <simon(at)2ndQuadrant(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: EXPLAIN ANALYZE output weird for Top-N Sort
Date: 2014-11-14 00:53:56
Message-ID: 27498.1415926436@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Simon Riggs <simon(at)2ndQuadrant(dot)com> writes:
> Limit (cost=.... rows=20 width=175) (actual time=.... rows=20 loops=1)
> -> Sort (cost=.... rows=568733 width=175) (actual time=....
> rows=20 loops=1)
> Sort Method: top-N heapsort

> The Sort estimate shows 568733 rows, whereas the actual rows are 20.

[ shrug... ] The estimated value is the planner's estimate of what would
happen *if you ran the node to completion*, which in practice doesn't
happen because of the LIMIT. The actual value is, well, the actual value.
We certainly should not munge around the actual value.

We could imagine munging the reported estimates to account for the parent
LIMIT, but that would make it a lot harder to understand the planner's
"thought processes", because the reported estimates would have that much
less to do with the numbers actually used in the internal calculations.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David Rowley 2014-11-14 00:55:48 Re: using custom scan nodes to prototype parallel sequential scan
Previous Message Tom Lane 2014-11-14 00:47:24 Re: Re: [GENERAL] Performance issue with libpq prepared queries on 9.3 and 9.4