Do App Engine datastore queries have a default sort order?

Is there a default sort order for App Engine datastore query return values? If so, what is it?

+5
source share
3 answers

By default, you get the order of the keys, and the order of the keys depends on whether you took the default identifier or specified the key name, and if the first, did you use the default policy to allocate the keys. The document says: "The default policy generates a random sequence of identifiers that are approximately evenly distributed. Each identifier can contain up to 16 decimal digits."

The 16-digit part is interesting. In principle, keys have 53 bits — the fractional part of a double IEEE. JavaScript uses IEEE doubling, so 53 bits is the largest integer value that you can safely commit via JSON.

+3
source

The cost of writing to the data warehouse says that the data warehouse object includes the built-in EntityByKinds index. This index includes an entity key.

Each time a new object of any kind is added, a new row is automatically added to this table with a new entity key, so it can be requested later.

So, I think that if no order is provided, the datastore returns objects ordered by key.

The entity key is stored in such a way that the object itself can be efficiently retrieved if it was returned as a result for a completed request.

I could not find a document on asc / desc, but when I asked below, the default was asc .

 >SELECT * FROM Model order by __key__ asc >SELECT * FROM Model success and same result >SELECT * FROM Model order by __key__ desc no matching index found 

So, the conclusion of my research is that the default order

 order by __key__ asc 

Please correct me if I miss something.

+2
source

it depends on which parameter you are filtering. Basically, the sort order is always ASC, depending on how it is filtered. Take a look at this document which may help. Basically, which filter you use, the sort order will be determined. Another interesting document would be this one , which explains indexes in more detail.

In case you do not use a filter, I believe that the index used is a key-based index, so you have an upstream key as your order.

+1
source

Source: https://habr.com/ru/post/1207685/


All Articles