Indexes are special data structures set up within a database to make queries run faster. Consider the following table: id age last_name hometown To find all the records with a particular last name, e.g., Johnson, the database engine would have to compare every record in the table with "Johnson". Indexes are auxiliary data structures that reorganize the data using the fields that are part of the query. An index for a last_name query would have only the last_name and id fields: Breyer 10001 ... Fetterman 10000 .... Johnson 1 Johnson 104 ... With the data reconfigured, the database can find all the records with a particular name faster. In fact, using a B-Tree data structure, performance can be better than O(log n). This means that if there are 64 records, it can find the data with at most 6 comparisons. Here's a sample B-Tree, organized by some field of type integer: diagram from http://www.bluerwhite.org/btree/With App Engine, you may find that some queries will not even work unless you set up indexes for them. App Engine generates simple indexes for you and specifies them in a file called index.yaml. For more complex queries , you may have to explicitly add indexes to the index.yaml file. Here's what the App Engine docs (http://code.google.com/appengine/docs/python/datastore/queriesandindexes.html) say: App Engine provides automatic indexes for the following forms of queries:
Other forms of queries require their indexes to be specified in
Tip: If during testing the app exercises every query it will make using the development web server, then the generated entries in If you do to set up an index manually, you can modify the index.yaml file. For instance, consider the following query: SELECT * FROM Person WHERE last_name = "Smith" AND height < 72 ORDER BY height DESC It has a one equality filter and one inequality filter, and it has a desc ordering. The index for it, in the index.yaml file, would be defined as: indexes: - kind: Person properties: - name: last_name - name: height direction: desc |
