An SQL index, which corresponds to an underlying eXtremeDB index, can be created to improve lookup performance for specific queries. (Please see SQL Optimizer for details about performance optimization using indexes.) Indexes are created using the SQL
create indexstatement specifying the table and key field(s) For example:create table t (x integer); create index tx on t(x);Here a B-Tree (tree) index (the default type) is created on column (field)
xof tablet.The syntax is as follows:
CREATE [UNIQUE] INDEX name ON table "(" key { "," key } ")" [USING (HASH | RTREE | PTREE | TRIGRAM | INCLUSIVE)] [IF NOT EXISTS] key : column_name [ asc | desc ]Note that all SQL keywords are case insensitive in eXtremeSQL - i.e.
CREATE INDEXandcreate indexare equivalent.The keywords
HASH, RTREE, PTREE,andTRIGRAMrefer to the eXtremeDB indexes of type(hash table),hashrtree(spatial search),(Patricia Trie),trietrigram(Trigram search) respectively. The keywordINCLUSIVEindicates that the index is a key-value-inclusive index.A
keyspecification can include the keywordsASCorDESCto indicate whether the index sorts in ascending or descending order. And note that compound indexes can be created by specifying a comma-delimited list of keys.If Not Exists
The
if not existsclause can be used to override an error when the index already exists. For example, note how the following create indexstatement fails while adding theif not existsclause allows the execution to succeed:XSQL>create table foo(x integer); XSQL>insert into foo values (1); XSQL>create index idx on foo(x); XSQL>create index idx on foo(x); ERROR: Compiler error at position 24: Index idx already defined for table foo create index idx on foo(x) ^ XSQL>create index if not exists idx on foo(x); XSQL>select * from foo; x ------------------------------------------------------------------------------ 1 Selected records: 1