Query/GqlQuery .order() 限制结果集?
我刚刚注意到一个我无法理解的查询的奇怪结果。看起来好像向查询添加 order() 限制了我返回的结果。
这是我的交互:
>>> SomeModel.all().filter('action =', 'foo').order('created_at').count(),
SomeModel.all().filter('action =', 'foo').count()
(192L, 293L)
>>> SomeModel.all().filter('action =', 'foo').order('created_at').count(),
SomeModel.all().filter('action =', 'foo').count()
(193L, 294L)
如您所见,两个查询之间没有添加一百个实体。看起来 order() 指令限制了结果集。但 created_at
是必需的属性,并且存在于所有实体中。
>>> count = 0
>>> for entity in SomeModel.all().filter('action =', 'foo'):
... if not entity.created_at:
... raise Exception, 'Not found!'
... count += 1
...
>>> print count
361
没有例外。那么为什么使用 ORDER 的查询不会返回所有实体呢?
最后,调查是否是坏数据:
>>> print "ascending=%d no-filter=%d descending=%d" % (
SomeModel.all().filter('action =', 'foo').order('created_at').count(),
SomeModel.all().filter('action =', 'foo').count(),
SomeModel.all().filter('action =', 'foo').order('-created_at').count())
ascending=79 no-filter=179 descending=173
I just noticed a strange result from a query that I have trouble understanding. It appears as if adding an order() to a Query is limiting the results I get back.
Here is my interaction:
>>> SomeModel.all().filter('action =', 'foo').order('created_at').count(),
SomeModel.all().filter('action =', 'foo').count()
(192L, 293L)
>>> SomeModel.all().filter('action =', 'foo').order('created_at').count(),
SomeModel.all().filter('action =', 'foo').count()
(193L, 294L)
As you can see, a hundred entities were not added between the two queries. It seems like the order() instruction is limiting the result set. But created_at
is a required property and is present in all entities.
>>> count = 0
>>> for entity in SomeModel.all().filter('action =', 'foo'):
... if not entity.created_at:
... raise Exception, 'Not found!'
... count += 1
...
>>> print count
361
No exceptions. So why would the query with the ORDER not return all entities?
Finally, investigating whether it's bad data:
>>> print "ascending=%d no-filter=%d descending=%d" % (
SomeModel.all().filter('action =', 'foo').order('created_at').count(),
SomeModel.all().filter('action =', 'foo').count(),
SomeModel.all().filter('action =', 'foo').order('-created_at').count())
ascending=79 no-filter=179 descending=173
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尽管没有更改我的代码,问题还是消失了。我最好的猜测是索引可能落后了,尽管我假设如果我从 put() 成功返回,那么索引就会更新。
The problem has disappeared despite not having changed my code. The best guess I have is that maybe the index fell behind, although I had assumed that if I get a successful return from put() then the indexes are updated.