3 Overview of SODA Indexing

The performance of SODA QBEs can sometimes be improved by using indexes. You define a SODA index with an index specification, which specifies how particular QBE patterns are to be indexed for quicker matching.

Suppose that you often use a query such as {"dateField" : {"$date" : DATE-STRING}}, where DATE-STRING is a string in the supported ISO 8601 format. Here, item method $date transforms DATE-STRING to a SQL value of data type DATE. You can typically improve the performance of queries on a field such as "dateField" by creating a B-tree index for it.

Or suppose that you want to be able to perform full-text queries using QBE operator $contains. You can enable such queries by creating a JSON search index for your data.

Or suppose that you want to perform metadata queries on a JSON data guide, which is a summary of the structural and type information about a set of JSON documents. You can create a JSON search index that holds and automatically updates such data-guide information.

In all such cases you specify the index you want by creating a SODA index specification and then using it to create the specified index.

Each SODA implementation that supports indexing provides a way to create an index. They all use a SODA index specification to define the index to be created. For example, with SODA for REST you use an HTTP POST request, passing URI argument action=index, and providing the index specification in the POST body.

Example 3-1 Specifying a B-Tree Index

This example specifies a B-tree non-unique index for numeric field address.zip.

{"name"   : "ZIPCODE_IDX",
 "fields" : [{"path"     : "address.zip",
              "datatype" : "number",
              "order"    : "asc"}]}

This indexes the field at path address.zip in Example 2-1 and Example 2-2.

Example 2-3 has no such field, so that document is skipped during indexing.

If the index specification included scalarRequired = true, and if the collection contained a document, such as Example 2-3, that lacks the indexed field, then an error would be raised when creating the index. In addition, if such an index exists and you try to write a document that lacks the indexed field then an error is raised for the write operation.

Example 3-2 Specifying a JSON Search Index

This example specifies a JSON search index. The index does both of these things:

  • Enables you to perform ad hoc full-word and full-number queries on your JSON documents.

  • Automatically accumulates and updates aggregate structural and type information about your JSON documents.

{"name" : "SEARCH_AND_DATA_GUIDE_IDX"}

This index specification is equivalent. It just makes explicit the default values.

{"name"      : "SEARCH_AND_DATA_GUIDE_IDX",
 "dataguide" : "on",
 "search_on" : "text_value"}

See Also: