I have a model:
class MyModel(db.Model):
some_list = db.StringListProperty(indexed=True)
some_value = db.StringProperty(indexed=True)
and a composite index:
indexes:
- kind: MyModel
properties:
- name: some_list
- name: some_value
If I create a new entity:
entity = MyModel(some_list=['a', 'b'], some_value='xxx')
then I put it into the datastore:
key = entity.put()
This will result in
- 2 writes (in this case 2 writes)
- 2 writes per indexed property value (in this case 2 + 4 writes)
- 1 write per composite index value (in this case 2 writes)
A total of 10 writes in this case. So far I understand the documentation.
But now I get the existing property, add ‘c’ to some_list and put it back:
existing = MyModel.get(key)
existing.some_list.append('c')
existing.put()
How many datastore writes is that?
The documentation says:
1 write + 4 writes per modified indexed property value + 2 writes per modified composite index value
Does this mean the index for ‘a’ and ‘b’ from some_list does not need to be rewritten:
1 + 4 + 2 = 7 writes
Or is the index for ‘a’ and ‘b’ from some_list rewritten because some_list changed:
1 + 12 + 6 = 19 writes
?
(Without the composite index) appstats shows the following
billed_ops:For the 1st put:
@2ms datastore_v3.Put real=169ms api=0ms cost=800 billed_ops=[DATASTORE_WRITE:8]
some_valueindex table (asc/desc)some_listindex table (2 per added value, asc/desc)For the 2nd put(update):
@187ms datastore_v3.Put real=50ms api=0ms cost=300 billed_ops=[DATASTORE_WRITE:3]
some_listindex table (2 per added value, asc/desc)The doc says
4 writes per modified indexed property valuebut since each of the list property element has its own index row (1 row per value), adding an element is equivalent to creating new indexed property (not modifying one).However if you modify
some_value, this will result in:@484ms datastore_v3.Put real=46ms api=0ms cost=500 billed_ops=[DATASTORE_WRITE:5]
some_valueindex table (2 writes for deleting existing row asc/desc, 2 writes for adding a new row asc/desc)