Redshift ignores CREATE INDEX; use SORT KEY, DIST KEY, and materialized views instead.
Redshift is a column-oriented, massively parallel analytic database that does not implement secondary B-tree indexes. Any attempt to run CREATE INDEX returns an error. Instead, Redshift relies on SORT KEYs, DIST KEYs, zone maps, and result caching to accelerate queries.
PostgreSQL uses:
CREATE INDEX index_name ON table_name (column1, column2);
Redshift’s SQL parser lacks this statement, so the same syntax is unsupported.
A SORT KEY physically orders data blocks, enabling zone maps to skip entire blocks during scans. Choose columns frequently filtered by range or used in ORDER BY, such as order_date.
CREATE TABLE Orders (
id BIGINT IDENTITY(1,1),
customer_id BIGINT,
order_date DATE,
total_amount NUMERIC(12,2)
)
SORTKEY (order_date);
Set DISTKEY on a high-cardinality column used in joins—customer_id for Orders and Customers tables keeps related rows on the same node and avoids network shuffles.
CREATE TABLE OrderItems (
id BIGINT IDENTITY(1,1),
order_id BIGINT,
product_id BIGINT,
quantity INT
)
DISTKEY(order_id)
SORTKEY(order_id);
The query below filters the last 7 days. With order_date as SORT KEY, only the most-recent storage blocks are scanned, delivering sub-second results.
SELECT o.id,
c.name,
o.total_amount
FROM Orders o
JOIN Customers c
ON c.id = o.customer_id
WHERE o.order_date >= CURRENT_DATE - INTERVAL '7 day';
The command fails because Redshift does not implement it. Rewrite the table with proper SORT and DIST keys.
A column with few distinct values, like status, clusters similar rows together, forcing full scans. Pick high-cardinality or time-based columns.
Key constraints exist only for query planners; Redshift does not enforce them. They help the optimizer skip joins but offer no physical index.
You can’t add secondary indexes, but you can ALTER TABLE to add a compound SORT KEY or create a materialized view to pre-aggregate data.
Use compound when queries filter on the leading column. Use interleaved when multiple columns appear in different filter combinations.