Partial or Filtered Index
suggest changeSQL Server, PostgreSQL, and SQLite can create an index on a subset of rows as well as a subset of columns. A filtered index is not standard SQL.
Consider a constantly growing set of orders with order_state_id equal to finished (2), and a stable set of orders with order_state_id equal to started (1).
If the business uses queries like this:
SELECT id, comment
FROM orders
WHERE order_state_id = 1
AND product_id = @some_value;
Partial indexing allows you to limit the index, including only the unfinished orders:
CREATE INDEX Started_Orders
ON orders(product_id)
WHERE order_state_id = 1;
This index will be smaller than an unfiltered index, which saves space and reduces the cost of updating the index.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents