Use it when queries filter on a subset or on an expression.
Partial and Expression Indexes
Partial indexes cover only rows matching a condition; expression indexes index the result of an expression such as lower(email). (PostgreSQL; MySQL has functional indexes in 8.0.)
1. Query filter/expression.
2. Create: CREATE INDEX ON users (lower(email)); / … WHERE active;.
3. EXPLAIN uses it?
4. Query text matches the index expression.
5. Monitor usage.
index on subset/expression → matching query predicates → index scan
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 How to verify Verify boundary
Test with the real query parameters. Confirm writes are not slowed noticeably.
Step 2 Common failures Narrow the fault
A query written as LOWER(email) with different casing rules or a cast does not match. Parameterised queries may not match a partial index condition the planner cannot show. Unused specialised indexes still cost writes.
The query must use the same condition or expression for the index to be used. Partial indexes save space for skewed data (e.g. WHERE active).
CREATE INDEX ON users (lower(email));— first check for this topicpsql -c "SELECT now(), version();"— PostgreSQL reachable and versionmysql -e "SELECT NOW(), VERSION();"— MariaDB/MySQL reachable and versionsqlcmd -S <server> -Q "SELECT @@VERSION"— SQL Server reachable and version
ReferenceWhat it is1 section · depth on demand
How it works
PostgreSQL supports both directly (CREATE INDEX ... ON t (lower(email)) and ... WHERE status = 'open'). MySQL 8 supports functional key parts; MariaDB uses indexed virtual columns. SQL Server uses filtered indexes and computed columns.
ReferenceImportant terms & boundaries3 sections · depth on demand
Examples
-- partial: only index active orders
CREATE INDEX orders_open_idx ON orders (customer_id) WHERE status = 'open';
-- expression: case-insensitive email lookups
CREATE INDEX customers_email_lower_idx ON customers (lower(email));
SELECT * FROM customers WHERE lower(email) = lower($1);
Documented example, not captured output. Queries must use the same predicate/expression to use the index. MySQL 8 supports functional indexes; SQL Server uses filtered indexes and computed columns.
In depth
When a partial index wins
A queue table with 50 million done rows and 2,000 pending rows:
CREATE INDEX jobs_pending_idx ON jobs (priority, created_at) WHERE status = 'pending';
SELECT id FROM jobs WHERE status = 'pending' ORDER BY priority, created_at LIMIT 100;
The index holds only the 2,000 pending rows: tiny, always cached, and updated only when rows enter or leave the pending state.
The planner must be able to prove the predicate
| Query | Uses WHERE status = 'pending' index? |
|---|---|
WHERE status = 'pending' | Yes |
WHERE status = $1 (generic prepared plan) | No — the value is unknown at plan time |
WHERE status IN ('pending','retry') | No — wider than the index predicate |
WHERE status = 'pending' AND priority > 5 | Yes |
Write the literal in the query (or use custom plans) when relying on a partial index.
Expression indexes
CREATE INDEX users_email_lower ON users (lower(email));
SELECT * FROM users WHERE lower(email) = lower($1); -- matches the indexed expression
CREATE UNIQUE INDEX users_email_lower_uq ON users (lower(email)); -- case-insensitive uniqueness
The query expression must match the index expression exactly (same function, same casts). ANALYZE collects statistics on indexed expressions, which also improves estimates.
MySQL and MariaDB
MySQL 8.0.13+ supports functional key parts: CREATE INDEX users_email_lower ON users ((lower(email))); (note the double parentheses). MySQL has no partial indexes; MariaDB uses indexed virtual (generated) columns for expressions. A common workaround for partial indexes is a generated column that is NULL for uninteresting rows, indexed normally.
Common mistakes
- Expression indexes not matching the query expression exactly.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.