インデックスを作成
Oracle
CREATE INDEX customer_city_idx ON customer(city) ONLINE;ONLINE はテーブルをロックせずに作成する。一意インデックスは CREATE UNIQUE INDEX、複合インデックスは (a, b) を使用する。
PostgreSQL
CREATE INDEX CONCURRENTLY customer_city_idx ON customer(city);CONCURRENTLY はテーブルへの書き込みをブロックしないが、トランザクションブロック内では実行できず、低速。
MySQL
CREATE INDEX customer_city_idx ON customer(city);
-- Lock-free: ... ALGORITHM=INPLACE, LOCK=NONE;InnoDB はほとんどのインデックスをオンラインで追加する。大きなテーブルでは LOCK=NONE で書き込みを許可する。
SQL Server
CREATE NONCLUSTERED INDEX IX_customer_city
ON dbo.customer (city)
WITH (ONLINE = ON);ONLINE は Enterprise の機能。カバリング列には 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 は昇順、-1 は降順。大きなコレクションでは、先にセカンダリで作成すると負荷を軽減できる。
Redis
# Not applicable (core). If RediSearch is present:
# FT.CREATE idx ON HASH PREFIX 1 customer: SCHEMA city TAGセカンダリインデックスは RediSearch モジュールでのみ提供される。コアの Redis ではキーでアクセスする。