[PATCH] Make skipped sort explicit in EXPLAIN ANALYZE

Started by Marti Raudseppalmost 14 years ago4 messageshackers
Jump to latest
#1Marti Raudsepp
marti@juffo.org

Hi,

This is just a small clarity improvement. tuplesort_performsort()
skips sorting entirely when the result set has 0 or 1 tuples, but
EXPLAIN still says it's using "quicksort". The patch changes that to
"skipped"

For example:

db=# explain analyze select * from now() order by 1;
Sort (cost=0.02..0.03 rows=1 width=8) (actual time=0.126..0.126
rows=1 loops=1)
Sort Key: now
Sort Method: skipped Memory: 25kB
-> Function Scan on now (cost=0.00..0.01 rows=1 width=8) (actual
time=0.032..0.033 rows=1 loops=1)

Patch attached.

Regards,
Marti

Attachments:

explain-sort-skipped.patchapplication/octet-stream; name=explain-sort-skipped.patchDownload+4-4
#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Marti Raudsepp (#1)
Re: [PATCH] Make skipped sort explicit in EXPLAIN ANALYZE

Marti Raudsepp <marti@juffo.org> writes:

This is just a small clarity improvement. tuplesort_performsort()
skips sorting entirely when the result set has 0 or 1 tuples, but
EXPLAIN still says it's using "quicksort". The patch changes that to
"skipped"

I'm not convinced this is an improvement; it's just one more value
to confuse people with. And any implementation of quicksort is likely
to have a fast exit path for 0 or 1 item, so I don't think the existing
display is incorrect either.

regards, tom lane

#3Marti Raudsepp
marti@juffo.org
In reply to: Tom Lane (#2)
Re: [PATCH] Make skipped sort explicit in EXPLAIN ANALYZE

On Fri, May 25, 2012 at 4:49 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

I'm not convinced this is an improvement; it's just one more value
to confuse people with.

I understand where you're coming from, but personally I think the
current output is more confusing: "Gee Postgres is stupid, it's
sorting when there's nothing to sort!"

But let's wait for a third opinion.

Regards,
Marti

In reply to: Marti Raudsepp (#3)
Re: [PATCH] Make skipped sort explicit in EXPLAIN ANALYZE

On 25 May 2012 15:19, Marti Raudsepp <marti@juffo.org> wrote:

I understand where you're coming from, but personally I think the
current output is more confusing: "Gee Postgres is stupid, it's
sorting when there's nothing to sort!"

But let's wait for a third opinion.

I agree with Tom. The idea that you "sort when there's nothing to
sort" is not confusing. Textbook implementations of recursive sorting
algorithms explicitly have a notion of sorting one element, by simply
recognising that one element must already be sorted. For example, look
at the quicksort pseudocode here:

http://en.wikipedia.org/wiki/Quicksort

--
Peter Geoghegan       http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training and Services