Re: A cost issue in ORDER BY + LIMIT

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Paul Guo <paulguo(at)gmail(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: A cost issue in ORDER BY + LIMIT
Date: 2022-08-06 16:12:56
Message-ID: 102404.1659802376@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Paul Guo <paulguo(at)gmail(dot)com> writes:
> Postgres seems to always optimize ORDER BY + LIMIT as top-k sort.
> Recently I happened to notice
> that in this scenario the output tuple number of the sort node is not
> the same as the LIMIT tuple number.

No, it isn't, and your proposed patch is completely misguided.
The cost and rowcount estimates for a plan node are always written
on the assumption that the node is run to completion.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2022-08-06 16:59:24 conchuela doesn't like gnu_printf anymore
Previous Message Andrew Dunstan 2022-08-06 16:10:55 Re: `make check` doesn't pass on MacOS Catalina