# Indexes

Source: https://cubibase.com/docs/database/indexes

Also available: [Markdown version](https://cubibase.com/docs/database/indexes.md) · [llms.txt](https://cubibase.com/llms.txt) · [full site content](https://cubibase.com/llms-full.txt)

Speed up the queries your app actually runs. Create btree, hash, GIN, GiST, SP-GiST, and BRIN indexes on public tables — single-column, composite, expression, or partial.

## Choosing a method

| Method | Good for |
| --- | --- |
| `btree` | Equality and range queries, sorting — the default and the only unique-capable method |
| `hash` | Equality-only lookups |
| `gin` | jsonb containment, arrays, full-text search |
| `gist` | Geometry, ranges, nearest-neighbour search |
| `spgist` | Partitioned data like points and text prefixes |
| `brin` | Very large tables whose physical order matches the column (e.g. timestamps) |

The Indexes screen lists every index in the public schema with its method, columns or expression, uniqueness, and size on disk.

## Composite, expression, and partial indexes

- Composite: pick up to 16 columns, each with ASC/DESC and optional NULLS FIRST/LAST. Column order matters — put the most-filtered column first.
- Expression: index a computed value, e.g. `lower(email)`, when your queries filter on that expression.
- Partial: add a WHERE filter, e.g. `status = 'active'`, to index only the rows you query.
- Unique: btree only; enforces uniqueness like a constraint.

**Examples · what the Console creates**

```sql
CREATE INDEX customers_plan_name ON public.customers (plan, name);

CREATE INDEX customers_email_lower ON public.customers (lower(email));

CREATE INDEX customers_active ON public.customers (owner_id)
WHERE status = 'active';

CREATE UNIQUE INDEX customers_email_unique ON public.customers (email);
```

> **note**: Index creation on a large table takes a lock while it builds. Create indexes before the table grows, or during a quiet period.

## Constraint-backed indexes are protected

- Primary keys and unique constraints own their indexes. The screen marks them and refuses to drop them — dropping the index would drop the constraint’s enforcement.
- Ordinary indexes can be dropped at any time; queries fall back to sequential scans.
- Every index costs write speed and storage. Watch the size column and drop indexes your queries no longer use.

## Additional resources

- [Querying rows](https://cubibase.com/docs/data-api/querying) The filters and sorts your indexes should serve.
- [SQL editor](https://cubibase.com/docs/database/sql-editor) Run EXPLAIN to confirm the planner uses your index.
- [Tables and columns](https://cubibase.com/docs/database/tables) Where the primary key index comes from.
