I made a Gae application and encountered many problems when using datastore. datastore has many restrictions, which are different from the previously used relational databases. I have summarized them myself to avoid forgetting them.
This document does not describe how to use the Google App Engine datastore API.
Only entity can be returned for any query, so select * From someentity is required. Only certain fields cannot be returned.
Gql. fetch () can contain the limit and offset parameters to return the specified number of records starting from the specified position. however, in fact, datastore returns Offset + limit records, but only skips the offset records in the fetch method and returns only the last limit records. This is not like the common rmdb. similar functions are often used during paging. Therefore, if fetch (limit, offset) is used, the efficiency is a problem.
Gql. Fetch () returns a maximum of 1000 records, no matter how large you set the limit value. It should be for performance consideration.
The painful count is the most widely used count in the groups: unlike in rmdb, the count () method actually reads all records that meet the conditions and calculates them, therefore, performance is a big problem. for the sake of performance, we do not recommend that you use count more for Google Documents, or count () for queries with a large amount of data ().
Count () can only return a maximum of 1000. The cause is the same as fetch ().
About count (), many solutions are discussed in group. it is generally recommended that you implement count () by yourself: create several counters in the database, and randomly take out a counter and add one when creating a new entity. the sum of the values of several Counters is the final count value;
All the entity of the transaction must be in an entity group, and the SELECT query cannot exist in the transaction.
Non-equality filtering conditions can only be performed on one attribute (or field). The following query is not allowed.
Select * From person where birth_year> =: min_year
And height> =: min_height
You can only use an inequality for the birth_year attribute.
Select * From person where birth_year >=: min
And birth_year <=: Max
If there is an inequality in the query and order by exists, the first field in the inequality query must be order by. The following two queries are all incorrect:
Select * From person where birth_year> =: min_year
Order by last_name, birth_year"
Select * From person where birth_year> =: min_year
Order by last_name
Select * From person where birth_year> =: min_year
Order by birth_year, last_name
is it strange to see so many restrictions? Is Google taking such a thing out of sight? Google explains that this is for scalability of datastore ). my guess is that each created entity will be randomly stored on a server node of hundreds of servers, which makes the aggregation computing cost in the database very high, therefore, more computing will be pushed to the app layer. similarly, all the entity in the transaction must be in an entity group and the entity in the transaction must be on a node (or cluster. this is just my conjecture. anyone knows more, please leave a message.