Problem Statement
Explain SARGability and give two examples of non-SARGable predicates with index-friendly rewrites.
Explanation
SARGable predicates let the engine Search ARGuments directly via an index. Non-SARGable expressions wrap the column or start with a wildcard so the engine cannot seek.
Rewrite DATE(created_at)=d as created_at >= d AND created_at < d+1. Rewrite LOWER(email)=x as email ILIKE x or use a functional index on LOWER(email). Avoid leading '%' in LIKE; prefer anchored prefixes or specialized text indexes.
Code Solution
SolutionRead Only
/* Good date filter */ created_at >= '2025-10-01' AND created_at < '2025-10-02' /* Functional index option */ CREATE INDEX ix_email_lower ON users((lower(email)));
Practice Sets
This question appears in the following practice sets:
