Appengine backreferences - need composite index?

ⅰ亾dé卋堺 提交于 2019-12-11 00:26:42

问题


I have a query that is very recently starting to throw:

"The built-in indices are not efficient enough for this query and your data. Please add a composite index for this query."

I checked the line on which this exception is being thrown, and the problem query is this one:

count = self.vote_set.filter("direction =", 1).count()

This is literally a one-filter operation using appengine's built-in backreferences. I have no idea how to optimize this query...anyone have any suggestions? I tried to add this index:

 - kind: Vote
   properties:
   - name: direction
     direction: desc

 - kind: Vote
   properties:
   - name: direction

And I got a message (obviously) saying this was an unnecessary index.

Thanks for your help in advance.


回答1:


If you run all relevant queries on your local SDK, it should generate all needed indices (in index.yaml) and the recommended policy is not to edit index.yaml yourself but rather to let the local SDK do it for you. If the SDK is not generating all needed indices, as long of course as you do exercise all relevant code paths in your local testing!, you should open a bug for it in the App Engine tracker here (after checking that there isn't already a bug report for this problem, of course).




回答2:


The backreferences actually just construct a query that's filtered on the reference property, so by adding another filter you have a 2-filter query.

Your compsite index would look something like:

- kind: Vote
  properties:
  - name: your_reference_property_name
  - name: direction
    direction: desc


来源:https://stackoverflow.com/questions/3025018/appengine-backreferences-need-composite-index

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!