Add Indexes to Tables
You can speed up most queries by adding indexes to tables. Database indexes work by creating a separate data structure that allows the database to quickly locate relevant data without scanning every single row of the table. They are free to create, as storage is free with our Managed DB.
Create an Index on your table
Create an index sorted in descending order:
CREATE INDEX idx_products_price_desc ON myschema.products (price DESC);
Here are many more examples (note that best practices for index creation are in the "best practices" section of this page):
- Basic Index (Default BTREE with multiple columns)
CREATE INDEX BOAT_IDX ON NORTH.BOAT (ID, COST)
- No explicit type specified, defaults to BTREE
- Multi-column index
- BTREE Index (Explicit)
CREATE INDEX BOAT_IDX_BTREE ON NORTH.BOAT USING BTREE (ID)
- Explicitly specifies BTREE type
- Single column index
- HASH Index
CREATE INDEX BOAT_IDX_HASH ON NORTH.BOAT USING HASH (NAME)
- Uses HASH algorithm
- Good for equality comparisons
- GIN Index (Generalized Inverted Index)
CREATE INDEX BOAT_IDX_GIN ON NORTH.BOAT USING GIN (NAME)
- Used for composite values (arrays, full-text search, JSONB)
- GIST Index (Generalized Search Tree)
CREATE INDEX BOAT_IDX_GIST ON NORTH.BOAT USING GIST (NAME)
- Used for geometric data, full-text search, range types
Drop an Index
Remove an existing index:
DROP INDEX myschema.idx_users_email;
Drop an index only if it exists:
DROP INDEX IF EXISTS myschema.idx_users_email;
Limitations
- Maximum Indexes per Subscription – Although adding indexes is free (since only query compute is metered not storage), each subscription is limited to 10 indexes by default.
- External Tables – Indexes cannot be created on external tables or materialized views.
- System Schemas – Indexes cannot be created on system schemas such as SXT_META, SYS, etc.
- Index Name Length – Index names must not exceed 63 characters.
- Table Requirement – The referenced table must exist before creating an index.
Best Practices for adding Indexes
- Index Selective Columns – Use indexes on columns in WHERE, JOIN, ORDER BY clauses.
- Composite Indexes – More efficient than multiple single-column indexes.
- Column Order Matters – Put most selective column first.
- Avoid Over-Indexing – Too many indexes slow writes.
- Choose Right Index Type:
- BTREE – Range queries and sorting
- HASH – Equality lookups
- GIN – Arrays and full-text search
Error Messages
"Maximum number of indexes reached" – Drop unused indexes for your Subscription or contact support.
"Indexes cannot be created on external tables" – Use native PostgreSQL tables.
"Index already exists" – Use different name for the index or drop an existing index if you've already created one with the same name.
"Table not found" – Verify schema and table name then try again.
Updated 2 days ago