在 google-app-engine 中使用 GQL 实现联接查询
我有一个类似以下的实体:
prop1 prop2 docid other-properties
str1 p1 1001 ........
str2 p1 1002 ........
str2 p2 1001 ........
str1 p2 1003 ……
我想要所有那些具有“prop1 as str1和prop2 as p1”和“prop1 as str2和prop2 as p2”共同的docid,并且想要使用它们的其他属性。就像这里的答案是 docid 1001。任何人都可以建议我一种方法吗?如果需要,我什至准备更改我的数据库结构,但我希望这些事情仅通过单个查询来完成...
好吧,其他属性没问题,我可能不需要使用它们,我只想要所有常见的 docid。
现在我正在使用这样的东西:
for b in db.GqlQuery("SELECT * FROM b"):
for a in db.GqlQuery("SELECT * FROM a WHERE y=:1", by):
print ax
但这需要花费很多时间,因为我有大量的条目。
I have an entity kind like:
prop1 prop2 docid other-properties
str1 p1 1001 .........
str2 p1 1002 .........
str2 p2 1001 .........
str1 p2 1003 .........
I want to have all those docid's that have "prop1 as str1 and prop2 as p1" and "prop1 as str2 and prop2 as p2" in common and want to use their other-properties. Like here the answer would be docid 1001. Can anyone suggest me a method to do so? I am even ready to change my database structure if required but I want these thing to be done by a single query only...
Ok its fine about other properties I may not need to use them, I just want all docid's that are common.
Right now I am using something like this:
for b in db.GqlQuery("SELECT * FROM b"):
for a in db.GqlQuery("SELECT * FROM a WHERE y=:1", b.y):
print a.x
But this is taking of lot of time since I have a huge number of entries.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
建模的最简单方法是让文档本身有一个字符串列表:
然后,您可以像这样查询该列表中的多个字符串:
这将默认使用合并连接策略,因此不会'不需要您构建任何自定义索引。
The easiest way to model this would be to have the docs themselves have a list of strings:
Then, you can do a query for multiple strings in that list like so:
This will use the merge-join strategy by default, and thus won't require you to build any custom indexes.