如何构建数据存储区索引(PHP GAE) [英] How to build datastore indexes (PHP GAE)

查看:80
本文介绍了如何构建数据存储区索引(PHP GAE)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用添加一个或两个实体到您的数据存储区中运行您的查询,这将填充您的index.yaml然后运行appcfg.py update_indexes来部署您的index.yaml(底部这个页面



2-您的其他解决方案是阅读这个,一个页面介绍数据存储索引的工作方式。然后阅读这篇关于索引的高级文章。您还应该观看以下演示文稿,以便您更好地了解索引和数据存储区。完成这些工作后,找出需要的查询,并填充 index.yaml 中所需的索引,然后使用与1中相同的方法进行部署。



快速总结索引如何工作

因此,您可以将数据存储视为纯粹的读者。它不像正常的关系数据库那样在读取数据并返回数据时进行任何计算。因此,为了能够运行一个给定的查询(比如说在2013年圣诞节前通过的所有客户订单),那么您需要一个表格,您的所有客户订单都按日期排序(因此系统不必检查每一行的日期看看它是否匹配,它只是获取数据的第一个大块,直到找到的日期为止,然后返回它)。

因此,你需要建立这些索引,它们会影响你可以运行的查询。默认情况下,每个属性都按其自身索引,按降序排列。对于多个属性(或不同的排序顺序)的任何查询,您需要拥有索引(在这种情况下,它们称为 composite indexes ),所以你需要在你的 index.yaml 中声明它。



在过去几年中,Google添加了锯齿形合并连接算法 a>,这基本上是一种采用2个复合索引(以相同属性开始,所以两个子查询之间有共同点)并且对它们运行2个子查询的方法,然后使算法加入两个子查询。


I am using Tom Walder's Google Datastore Library for PHP to insert data into my Google App Engine Datastore.

$obj_schema = (new GDS\Schema('Add Log'))
    ->addString('name', TRUE)
    ->addDatetime('time', TRUE);
$obj_store = new GDS\Store($obj_gateway, $obj_schema);
$obj_store->upsert($obj_store->createEntity(['name' => "test",'time' => date('Y-m-d H:i:s', time())]));

When I insert data like the above code, everything seems to be importing properly (each property say they are indexed).

But when I go to do a query with multiple selectors it says "You need an index to execute this query".

My query

The error message

Does anyone know what I need to do to make sure my queries are being indexed? This is what my dashboard hows with plenty of data using the code I showed.

解决方案

As Alex Martelli mentioned in a comment, most of the time, your indexes are built when you run your app on the devserver and have your datastore get queried there (this adds the required indexes for any question into your index.yaml file.

So you have two ways you can go at it.

1- Run your app on local devserver, go to your dev "Developer Console" to add one or two entities to your datastore. Run your queries, that'll populate your index.yaml with all required indexes. You can then run appcfg.py update_indexes to just deploy your index.yaml (bottom of this page)

2- Your other solution would be to read this, a page on how datastore indexes work. Then read this advanced article on indexes. You should also watch the following presentation that will give you a better insight into indexes and the datastore. Once that's all done, figure out which queries you want, and flesh out the required indexes in your index.yaml, then deploy with the same method as in 1.

Quick summary of how indexes work

So you can think of the datastore as a pure READER. It doesn't, like normal relational databases, do any kind of computation as it reads your data and returns it. Therefore, to be able to run a given query (say "all client orders passed before christmas 2013"), then you need a table where all your client orders are ordered by date (so the system doesn't have to check every row's date to see if it matches. It just takes the first "chunk" of your data, up to the date you're looking for, and returns it).

Therefore, you need to have those indexes built, and they will influence the queries you can run. By default, every attribute is indexed by itself, in descending order. For any queries on more than one attribute (or with a different sort order), you need to have the index (in that case they are called composite indexes) built by the datastore, so you need to declare it in your index.yaml.

In the last years, Google added the zigzag merge join algorithm, which is basically a way to take 2 composite indexes (that start with the same attributes, so there is common ground between the 2 sub-queries) and run 2 sub-queries on them, then have the algorithm join the responses of both sub-queries.

这篇关于如何构建数据存储区索引(PHP GAE)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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