在Appengine数据存储中设置操作 [英] Set operations in Appengine datastore
问题描述
我假设没有好的方法可以这样做,但是如果你不得不这样做,你会如何在Appengine的数据存储上实现set操作?例如,给出两个集合整数,你将如何将它们存储在数据存储中以获得相交和除(A中所有那些不在B中的项目)操作的良好性能?
数据存储区API中没有任何内置集操作。我看到你有两种选择:
-
对于小型套餐(数百个商品)通过为集合A和集合B执行只有键的查询,并在您的应用程序代码中进行交集。 smallish的确切定义将取决于您的申请。
你需要什么交点,你可以在每次插入新记录时计算它们。例如,假设您有两个集合A和B,并且您知道最终您想查询(A与B相交)。每当你插入一个A时,检查它是否已经在B中。如果是,在某处记录这个事实(在一个单独的实体类型中,或者在A或B本身上作为一个布尔属性)。当然,你也需要为你的B做这个。 For smallish sets (hundreds of items) You might get away with doing keys-only queries for both set A and set B, and doing the intersection in your application code. The precise definition of "smallish" will depend on your application.
For largish sets (millions of items) If you know ahead of time which intersections you'll want, you can calculate them each time you insert a new record. For example, assume you have two sets A and B, and you know that you'll eventually want to query on (A intersects B). whenever you insert an A, check to see if it is already in B. If it is, record this fact somewhere (either in a separate entity type, or as a boolean property on A or B itself). Of course, you'll need to do this for your B's also.
使用选项1,您可以有很多不同套的数量,但受限于每套的大小。
使用选项2,您可以拥有数百万成员的集合,但是如果您有多个集合,试图定义集合和运算符的所有可能排列组合变得笨拙。
I assume there's no good way to do so, but if you had to, how would you implement set operations on Appengine's datastore?
For example given two collections of integers, how would you store them in the datastore to get a good performance for intersect and except (all those items in A that are not in B) operations?
There aren't any built in set operations in the datastore API. I see you having two options:
With option 1, you can have lots of different sets, but are limited by how big each set is.
With option 2, you can have sets with millions of members, but if you have more than a few sets, trying to define all the possible permutations of sets and operators will get unwieldy.
这篇关于在Appengine数据存储中设置操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!