Partial index workaround using helper column
SQL
Medium
2 views
Problem Description
You want index only on active rows (status='ACTIVE'). Create a helper column active_flag and index it with customer_id.
Output Format
DDL statement(s)
Sample Test Case
Input:
Orders(status, customer_id)
Constraints
Workaround for DBs without partial indexes
Official Solution
ALTER TABLE Orders ADD COLUMN active_flag INT; UPDATE Orders SET active_flag = CASE WHEN status='ACTIVE' THEN 1 ELSE 0 END; CREATE INDEX idx_orders_active_customer ON Orders(active_flag, customer_id);
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!