Order with Use Keys

When doing a

SELECT * FROM default USE KEYS […]

Can I rely on the documents being returned in the order of the keys in the array fed to Use Keys?

Hello, yes you can. If you try it with one of the sample buckets you will see that changing the order of the keys inside USE keys will change the order the results are returned in.

Thanks!

1 Like

thank you very much. Glad to know.

It’ s not something you can just test out. relying means that you can rely on it :slight_smile:

In SQL order of the documents is guaranteed only when query has explicit ORDER BY.

In above case it might give you results in order (but can change if parallelism, JOIN , aggregates etc present), if really need it you should use ORDER BY.

2 Likes