查询所选的字段在客观化的实体 - 应用程序引擎 [英] Querying selected fields in an entity in objectify - appengine

查看:294
本文介绍了查询所选的字段在客观化的实体 - 应用程序引擎的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的应用程序引擎和客体作为后端为我的应用程序。当我在数据存储查询,我得到一个实体对象,它有需要行的数据。但是,采用物化我将如何查询实体,并获得奥菱选择个行业的呢?因为查询整个实体将是沉重的,它需要更多的数据带宽。

I am using appengine and objectify as a backend for my app. And when i query in the datastore i get a Entity object which has the data of required row. But, using objectify how will i query entities and get oly selected fileds from it? because querying the whole entity will be heavy and it needs more data bandwidth.

例如:与4列,一个实体 - >编号,名称,描述,年龄。我要查询奥菱ID,姓名,年龄。我不想描述进行查询。

Eg : In a entity with 4 columns, --> Id,name,description,age. I should query oly Id,name,age. I dont want description to be queried.

推荐答案

在GAE数据存储的作品并不像一个RDBMS;你不能随意挑选哪些字段查询出来的实体。数据存储查询的标准行为是遵循指数(映射属性值设置为实体键),然后取按键中的所有实体中。

The GAE datastore does not work like an RDBMS; you can't arbitrarily pick and choose which fields to query out of an entity. The standard behavior of a datastore query is to follow an index (which maps attribute value to entity key), then fetch-by-key all the entities found.

有一个名为投影查询功能(该物化支持,查找项目()方法查询命令对象),但它不是一般的像你这样的目的SELECT语句得到的SQL。投影查询,利用该指数本身包含索引值的事实,因此,如果你只希望数据是在索引中,则不需要进行后续的整个实体的获取。但是,这有一些限制:

There is a feature called "projection queries" (which Objectify supports; look for the project() method on the query command object), however it is not a general purpose SELECT statement like you get in SQL. Projection queries capitalize on the fact that the index itself contains the index values, so if you only want data that's in the index, you don't need to perform a subsequent fetch of the whole Entity. However, this comes with some restrictions:

  • 您必须保持与所有你要投射的数据的多人房地产指数。
  • 您必须保持单性能指标为每一个在多人房地产指数字段。
  • 您可以在按照特定的索引的查询唯一项目。
  • 查询旁路客体的内存缓存为基础的实体缓存。

请注意使用投影查询的成本。在你的榜样,你需要对姓名和年龄单一性能指标加上 A多人房地产指数{__ key__,姓名,年龄} 。而不是按照书面的实体3的写操作,您的新实体将花费8个写欢声笑语。另一方面,投影查询的成本是一个常数1读出的运算

Be aware of the cost of using projection queries. In your example, you will need single-property indexes on Name and Age plus a multiproperty index on {__key__, Name, Age}. Instead of 3 write operations per entity written, your new entity will cost 8 write ops. On the other hand, the cost of a projection query is a constant 1 read op.

在所述的其他的另一方面,一批次的成本从memcache中得到的是0,和最坏情况下的成本为1读取运算。除非你的描述字段是已知的导致您的问题,这是一个巨大的premature优化。

On the other other hand, the cost of a batch get from memcache is 0, and the worst-case cost is 1 read op. Unless your description field is known to be causing you problems, this is a massive premature optimization.

这篇关于查询所选的字段在客观化的实体 - 应用程序引擎的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆