Skip to content

Database Indexes

Indexes improve query performance by letting the database look up rows without scanning the entire table. SchemaStack lets you create, list, and delete indexes on any view through the Admin UI or the REST API.

How Indexes Work

An index is a separate data structure that the database maintains alongside your table. When you query or sort by an indexed column, the database uses the index to find matching rows quickly instead of reading every row.

When to add an index:

  • Columns you frequently filter on (e.g., status, email, created_date)
  • Columns you sort by in large tables
  • Foreign key columns (often indexed automatically)
  • Columns used in unique constraints

When indexes aren't needed:

  • Small tables (under a few thousand rows) — full scans are fast enough
  • Columns with very few distinct values (e.g., a boolean active flag)
  • Columns you rarely query or filter on

TIP

Adding an index speeds up reads but adds a small overhead to writes (inserts, updates, deletes), since the database must keep the index up to date. For most workloads this is negligible.

Index Types

TypeDescriptionUse Case
Single-columnIndex on one columnSimple lookups and sorts
CompositeIndex on multiple columnsQueries that filter or sort by several columns together
UniqueEnforces uniqueness across indexed columnsEnsuring no duplicate values (e.g., email addresses)

Creating an Index

Via API

http
POST /api/indexes/view/{viewUuid}
Content-Type: application/json
Authorization: Bearer {token}

{
  "name": "idx_orders_customer_date",
  "columnNames": ["customer_id", "order_date"],
  "isUnique": false
}

Response: 201 Created

json
{
  "uuid": "a1b2c3d4-...",
  "name": "idx_orders_customer_date",
  "columnNames": ["customer_id", "order_date"],
  "isUnique": false
}

The metadata record is created immediately. The actual CREATE INDEX DDL runs asynchronously in the background and is typically applied within seconds.

Naming Conventions

Choose descriptive index names that indicate the table and columns:

  • idx_orders_customer_id — single column
  • idx_orders_customer_date — composite
  • idx_users_email_unique — unique index

Listing Indexes

http
GET /api/indexes/view/{viewUuid}
Authorization: Bearer {token}

Response: 200 OK

json
[
  {
    "uuid": "a1b2c3d4-...",
    "name": "idx_orders_customer_date",
    "columnNames": ["customer_id", "order_date"],
    "isUnique": false
  }
]

Returns an empty array when no indexes exist on the view.

Deleting an Index

http
DELETE /api/indexes/{indexUuid}
Authorization: Bearer {token}

Response: 204 No Content

The index is dropped from the database asynchronously, similar to creation.

Schema Import

When you import an existing database schema, SchemaStack automatically detects and preserves all existing indexes — including composite and unique indexes. No manual setup is needed for tables that already have indexes.

Permissions

ActionRequired Permission
List indexesVIEW_DATA
Create indexCONFIGURE_VIEW
Delete indexCONFIGURE_VIEW

Limitations

  • Index rename is not supported — delete and recreate instead
  • Partial indexes (indexes with a WHERE clause) are not yet supported
  • Expression indexes (indexes on computed expressions) are not yet supported
  • Only B-tree indexes are created (the PostgreSQL default and most common type)

SchemaStack Documentation