Any tips for order by clause performance tuning?

select * from abc order by id
This kind of n1ql will take about 500+ms in execute the query, but remove the order by clause, it reduced to 10+ms, is there some performance tuning tips for this?

CREATE INDEX ix1 ON abc(id);
SELECT *
FROM abc 
WHERE id IS NOT MISSING
ORDER BY id;

https://blog.couchbase.com/create-right-index-get-right-performance/

You are correct, but the key is

id is not missing

with this sentence, it force use id as index search then everything fine.

Found another issue:
If order by id desc, will fall to 500+ms, any solution???

CREATE INDEX ix1 ON abc(id DESC);
SELECT *
FROM abc 
WHERE id IS NOT MISSING
ORDER BY id DESC;

Thanks, that’s what I want. So if we want to use asc and desc, we should create 2 indexes, right?

Above link has all the details. If you are looking performance and query expose index order you need two indexes and must provide USE INDEX hint based on query ORDER BY. Otherwise single index will serve.

Thanks, this is really helpful.