ORDER BY requires that all rows be sent to a single worker which then sorts them. ORDER BY might often require a lot of memory on a Presto worker. When you want to look up the top or bottom N records, use LIMIT which can reduce the sort cost and memory pressure.

SQL Example

 

good

SELECT * FROM tbl ORDER BY time LIMIT 100

bad

SELECT * FROM tbl ORDER BY time

  • No labels