## What this teaches
How to improve limit -1 performance.
## The problem
Issue questdb/questdb#5915 (closed, 15 comments): ### Is your feature request related to a problem? Noticed that limit -1 can be quite slow, specially while ingesting data on a large table. This can be tested on demo box with the new dataset. ``` select * from market_data limit -1; select * from market_data latest by symbol; ``` Explain says latest on does a frame backward scan, while limit -1 needs to skip over billions of frames, then do a row forward scan.
## What worked (verified answer)
limit -1 on a large QuestDB table is slow because it skips over billions of rows before scanning forward. The maintainer's workaround: use (select * from trades order by timestamp desc limit 1) order by timestamp instead, or latest by symbol. It is not 100 percent equivalent for rows with identical timestamps, but it is much faster.
## Source
gh:questdb/questdb#5915 - https://github.com/questdb/questdb/issues/5915