Skip to main content
Indexes speed up data retrieval at the cost of slower writes.

Basic Syntax

Create Index

Unique Index

Drop Index

When to Use Indexes

Index Best Practices

Do:
  • Index columns used in WHERE clauses
  • Index columns used in JOIN conditions
  • Index columns used in ORDER BY
  • Use unique indexes for email, username, etc.
Don’t:
  • Over-index (slows down writes)
  • Index rarely queried columns
  • Index very small tables

Complete Examples

User Table

Order Table

Database Support

For MongoDB indexes, use native driver methods.

Limitations

Current index implementation supports:
  • Single column indexes
  • UNIQUE constraint
For advanced indexes (composite, partial, full-text, GIN), use native SQL.

Next Steps

Views

Create virtual tables

Transactions

Group operations safely