Create an index
Oracle
CREATE INDEX customer_city_idx ON customer(city) ONLINE;ONLINE builds it without locking the table. Use CREATE UNIQUE INDEX for unique; (a, b) for composite.
PostgreSQL
CREATE INDEX CONCURRENTLY customer_city_idx ON customer(city);CONCURRENTLY does not block writes to the table, but it cannot run inside a transaction block and is slower.
MySQL
CREATE INDEX customer_city_idx ON customer(city);
-- Lock-free: ... ALGORITHM=INPLACE, LOCK=NONE;InnoDB adds most indexes online; on large tables allow writes with LOCK=NONE.
SQL Server
CREATE NONCLUSTERED INDEX IX_customer_city
ON dbo.customer (city)
WITH (ONLINE = ON);ONLINE is an Enterprise feature. For covering columns use INCLUDE (col1, col2).
MongoDB
db.customer.createIndex({ city: 1 })
// Unique: { city: 1 }, { unique: true }
// Built in the background without blocking (default behavior in 4.2+)1 is ascending, -1 descending order. On large collections, building on a secondary first reduces load.
Redis
# Not applicable (core). If RediSearch is present:
# FT.CREATE idx ON HASH PREFIX 1 customer: SCHEMA city TAGSecondary indexes come only with the RediSearch module; core Redis access is by key.