Re: A cost issue in ORDER BY + LIMIT

2022-08-06 Thread Tom Lane
Paul Guo 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 cos

Re: A cost issue in ORDER BY + LIMIT

2022-08-06 Thread Zhang Mingli
HI, What if the the rows of t1 is less than the limit number(ex: t1 has 5 rows, limit 10)? Does it matter? Regards, Zhang Mingli On Aug 6, 2022, 23:38 +0800, Paul Guo , wrote: > > limit_tuples

A cost issue in ORDER BY + LIMIT

2022-08-06 Thread Paul Guo
Hello, 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. See below, postgres=# explain analyze verbose select * from t1 order by a limit 10;