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

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

问题描述

我正在使用 "将一两个实体添加到您的数据存储区.运行您的查询,这将使用所有必需的索引填充您的 index.yaml.然后您可以运行 appcfg.py update_indexes 来部署您的 index.yaml(this页)

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

索引工作原理的快速总结

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

因此,您需要构建这些索引,它们会影响您可以运行的查询.默认情况下,每个属性都按降序自行索引.对于对多个属性(或具有不同排序顺序)的任何查询,您需要有索引(在这种情况下,它们被称为 复合索引) 由数据存储构建,因此您需要在 index.yaml 中声明它.

最近几年,谷歌添加了之字形合并连接算法,基本上是一种采用 2 个复合索引(以相同的属性开始,因此 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 GDSSchema('Add Log'))
    ->addString('name', TRUE)
    ->addDatetime('time', TRUE);
$obj_store = new GDSStore($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天全站免登陆