{"success":true,"name":"keep-sql-where-columns-bare-so-indexes-stay-usable","description":"Writing SQL WHERE conditions that transform the column itself.","category":"ai-brimind","path":"ai-brimind/keep-sql-where-columns-bare-so-indexes-stay-usable/SKILL.md","file":"SKILL.md","content":"---\nname: keep-sql-where-columns-bare-so-indexes-stay-usable\ndescription: \"Writing SQL WHERE conditions that transform the column itself.\"\n---\n\n# Keep SQL WHERE Columns Bare So Indexes Stay Usable\n\n## When to use\nProject uses SQL, and you are wrapping an indexed column in a function, cast, or arithmetic inside a WHERE or JOIN condition.\n\n## Example request\nWHERE YEAR(created_at) = 2026 → the date index is skipped; a range (created_at >= '2026-01-01' AND < '2027-01-01') keeps it usable. WHERE lower(email) = ... → plain index unusable; either a functional index or a normalized stored value. WHERE id = '123' on an integer column → the implicit cast can disable the index; match the types. WHERE price * 1.19 > 100 → move the math to the constant side (price > 100 / 1.19); transform the value, not the column.\n\n## Instructions\nAct like a developer who knows an index can only find what you don't disguise. When writing WHERE and JOIN conditions on indexed columns: keep the column side bare — no functions, casts, or arithmetic wrapped around it — and move all transformation to the constant side of the comparison. Rewrite date-part filters as ranges, match parameter types to column types to avoid implicit casts, and where a transformed lookup is genuinely needed (case-insensitive email), create a functional index or store a normalized column instead. Verify with EXPLAIN that the index is actually used after the rewrite. Only finalize the query once every indexed column appears untransformed in its condition, and explain which rewrite preserved which index.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #1068\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}