Skip to main content

CREATE INDEX

Create an index on a table to improve query performance for lookups, joins, and ordering.

Syntax

Description

CREATE INDEX builds an index on one or more columns or expressions of a table. Turso uses B-tree indexes in the same format as SQLite. The query planner automatically uses indexes when they can speed up a query — you do not need to reference an index explicitly in your SQL statements.

Parameters

Column Indexes

The most common form indexes one or more columns by name.
A composite index is useful when queries filter or sort by multiple columns. The order of columns matters — an index on (a, b) can accelerate queries filtering on a alone, but not queries filtering only on b.

UNIQUE Indexes

A UNIQUE index enforces that no two rows contain the same combination of values in the indexed columns. NULL values are considered distinct from each other, so a UNIQUE index permits multiple rows with NULL in the indexed columns.

Partial Indexes

A partial index includes only the rows that satisfy the WHERE clause. Partial indexes are smaller than full indexes and are more efficient for queries that always include the same filter condition.
The WHERE clause of a partial index can reference any column of the table and may use operators, literal values, and built-in functions. Subqueries are not allowed.

Expression Indexes

An expression index stores the result of an expression rather than a raw column value. Use expression indexes when queries frequently filter or sort by a computed value.
Each expression in the index must be a deterministic expression that references only columns of the indexed table. Aggregate functions and subqueries are not allowed.

Custom Index Methods

Turso Extension: Custom index methods extend indexing beyond B-trees. This feature is experimental and must be enabled before use.
Turso supports a USING clause to specify an alternative index method.

Full-Text Search with USING fts

The fts index method creates a full-text search index powered by Tantivy. FTS indexes support tokenizer configuration through the WITH clause.
Once an FTS index exists, use the search() function to query it:

Examples

Index for a Common Lookup Pattern

Unique Index to Enforce a Business Rule

Partial Index for a Status Filter

See Also