SQL Indexing And Sargability

Guides portable index design and the sargability rule — an index is a sorted B-tree, so the database can use it only when the predicate leaves the indexed column bare. Bans the recurring index-killers — wrapping an indexed column in a function or expression (`WHERE LOWER(email) = …`, `WHERE DATE(ts) = …`, `WHERE col + 0 = …`) and leading-wildcard `LIKE '%term'`, both of which force a full table scan. Auto-invokes when writing or editing `CREATE INDEX`, a slow `WHERE`/`ORDER BY`/`JOIN`/`GROUP BY`, a function or arithmetic applied to a filtered column, a `LIKE` pattern, or on "why is this query slow" / "what index do I need" / "this query does a full table scan" requests. The highest-leverage performance skill, taught vendor-neutrally.

ctoth 2af4246 3 files · 34.9 KB Updated

File contents

ctoth/sql-skills-plugin/tree/main/plugins/sql/skills/sql-indexing-and-sargability commit 2af42461b8

Frequently asked questions

npx skillmds@latest add ctoth/sql-indexing-and-sargability