Posted 06/13/2025

Composite Index and Separate Indexes

Separate Indexes

Useful when queries filter or join using only one column. Provides flexibility for queries that use only one column.

Composite Index

Useful when queries filter or join using both columns together. Example: How Foreign Keys and Indexes Work Together Foreign keys ensure referential integrity but do not optimize query performance. Indexes on foreign key columns improve query performance by reducing the number of rows scanned during joins, filters, updates, and deletes.

Best Practices

Disadvantages

CREATE INDEX

CREATE INDEX IF NOT EXISTS indexName ON tableName USING btree (columns);

CREATE INDEX CONCURRENTLY

CREATE INDEX CONCURRENTLY IF NOT EXISTS indexName ON tableName USING btree (columns);