Query/GqlQuery .order() 限制结果集?

发布于 2024-08-10 19:48:04 字数 1153 浏览 4 评论 0原文

我刚刚注意到一个我无法理解的查询的奇怪结果。看起来好像向查询添加 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

流心雨 2024-08-17 19:48:04

尽管没有更改我的代码,问题还是消失了。我最好的猜测是索引可能落后了,尽管我假设如果我从 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文