To add an index definition to the store, use a CREATE INDEX
statement. Its form is:
CREATE INDEX [IF NOT EXISTS] index-name ON table-name (field-name)
When indexing a map field, the previous syntax is acceptible, as are any of the following:
CREATE INDEX [IF NOT EXISTS] index-name ON table-name (KEYOF(field-name))
or
CREATE INDEX [IF NOT EXISTS] index-name ON table-name \ (ELEMENTOF(field-name))
or
CREATE INDEX [IF NOT EXISTS] index-name ON table-name \ (KEYOF(field-name),ELEMENTOF(field-name))
where:
IF NOT EXISTS
is optional, and it
causes the CREATE INDEX
statement to
be ignored if an index by that name currently exists.
If this phrase is not specified, and an index using the
specified name does currently exist, then the
CREATE INDEX
statement will fail
with an error.
index-name is the name of the index you want to create.
table-name is the name of the table that you want to index.
field-name is the name of the field that you want to index.
KEYOF
is a keyword that causes index
entries to be created based on keys contained in
a map.
ELEMENTOF
is a keyword that causes index
entries to be created based on the values contained in
a map.
For example, if table Users
has a field
called lastName
, then you can index that
field with the following statement:
CREATE INDEX surnameIndex ON Users (lastName)
Note that depending on the amount of data in your store, creating indexes can take a long time. This is because index creation requires Oracle NoSQL Database to examine all the data in the store.
For a description of using indexes with non-scalar data types, see Indexing Non-Scalar Data Types.