Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I save an item to Datastore with 0 write operations on indexes?

The number of Datastore write operations it takes to persist an entity is 1 + number of indexes.

What if I update an existing entity and indexed fields are not changed. How many write operations will it take? Is it possible to save an existing item with only 1 write op. if indexes are not affected?

like image 347
Ski Avatar asked Dec 01 '25 06:12

Ski


1 Answers

The short answer is no. If you want to search by the field, it needs to be indexed, and you will have to pay per write. On each entity write, the entire entity is written, and the datastore doesn't know whether you changed an indexed field or not.

If you're worried about costs, you can create fields that are not indexed. Unindexed fields do not add any write ops. However, you can't search by unindexed fields: http://code.google.com/appengine/docs/python/datastore/queries.html#Unindexed_Properties

You can manually set a property to be unindexed, write an entity, and then set it to be indexed again afterwards. This is practically useless and a bunch of effort, and is probably not what you're looking for. It sounds like you want to use the old index, but this technique will blow away the index, and this particular entity won't be indexed (and won't turn up in search results), while others of the same kind are.

If you have a field that you may write a lot compared to the rest of your entity, the cost conscious thing to do may be to break that field off into its own, unindexed entity, and store its key in the original entity. You'll need an extra db fetch to get it each time though.

EDIT: This original answer is incorrect. I might have misread the question at the time. While you cannot create a new entity with 1 write op, if you write an existing entity where indexed properties are not changed, you can indeed write with 1 write op.

like image 200
dragonx Avatar answered Dec 04 '25 03:12

dragonx



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!