I do queries like this with Python GAE:
a1 = Activity.query().filter(Activity.first=='foo').order(-Activity.date)
a2 = Activity.query().filter(Activity.second=='bar').order(-Activity.date)
Am I better off with two separate indices:
indexes:
- kind: Activity
properties:
- name: first
- name: date
direction: desc
- kind: Activity
properties:
- name: second
- name: date
direction: desc
Or with a single index that covers both:
indexes:
- kind: Activity
properties:
- name: first
- name: second
- name: date
direction: desc
I suspect the former is better but wanted to check.
=====
To the person who voted to close as "opinion based", the two options above will change the index size and possibly also the speed of responding to queries. Definitely not opinion based. There is a right answer.
CodePudding user response:
The first option will provide you with an index that directly answers your query, so it will scale better, but does have a higher write cost (2 index entries, instead of 1).
The second will write out fewer index entries (1), but both queries will need to skip over any index entries. Also, the service isn't required to allow the second query with the index provided. My tests show that the second query is currently rejected with an index like your second one.