Getting Started

Tutorial: Building with CleaveDB

INDEX — Speed Up Lookups

By default, primary lookups by document ID (like FIND users "jane") resolve in $O(1)$ constant time. For arbitrary property filters (like WHERE age > 30 or WHERE dept = "Eng"), CleaveDB maintains secondary B+Tree indexes created via INDEX.

Creating a single-field index

Index a single field to accelerate equality and range queries:

CleaveQLExample · Single-field index
INDEX age ON emp

You can also use the parenthesized bucket-first syntax if you prefer:

CleaveQLExample · Bucket-first syntax
INDEX emp ON (age)

Both forms construct a persistent B+Tree over the specified attribute in the background.

Composite multi-field indexes

When queries filter or sort across multiple attributes simultaneously, declare a composite index across comma-separated keys:

CleaveQLExample · Composite index
INDEX dept, age ON emp

Or equivalently:

CleaveQLExample · Composite index with parentheses
INDEX staff ON (dept, role)

Composite indexes accelerate queries that match the leading prefix of the indexed tuple (e.g. filtering by dept, or filtering by both dept and age).

Verifying active indexes

List all active indexes across your buckets using SHOW INDEXES:

CleaveQLExample · List indexes
SHOW INDEXES

Returns a JSON payload with the total count and index specifications: {"count": 2, "data": [...]}.