CosmosDB: How SELECT TOP works?

I have a 450 GB database ... with millions of records.

Here's an example request:

SELECT TOP 1 * FROM c WHERE c.type='water';

      

To speed up our queries, I only thought of the first one, but we noticed that the query was still taking quite a long time despite the very first record in the database that met our limits.

So my question is, how does it work SELECT TOP 1

? It:

A) Select ALL records and then return only the first (top) number where   type='water'

B) Returns the first record that occurs wheretype='water'

+3


source to share


1 answer


Assuming you are not sorting your results (which you are not asking for) then TOP 1

will return the first result as soon as it finds it. Then he must complete the request.



Since it is c.type

not indexed and you have millions of rows, the lag you are experiencing is probably due to the fact that it simply takes the DB a while to find what you are looking for. Comparing strings is slow, especially when you are talking about huge numbers.

0


source







All Articles