Skip to content

Check_explain

FieldValue
TypeSkill Resource
Source~/.copilot/skills/database/scripts/check_explain.py
DescriptionNot specified

Source Content

#!/usr/bin/env python3
"""Check that a query-performance write-up actually backs its claims.
Usage: check_explain.py <review.md>
Fails if the doc recommends/discusses a query but contains no EXPLAIN output
(the actual evidence this skill requires), or claims an index helped without
naming it.
"""
import re
import sys
def main() -> int:
if len(sys.argv) != 2:
print("Usage: check_explain.py <review.md>", file=sys.stderr)
return 2
text = open(sys.argv[1], encoding="utf-8").read()
fail = 0
has_explain = bool(re.search(r"\bEXPLAIN\b", text, re.IGNORECASE))
has_plan_shape = bool(re.search(r"(Seq Scan|Index Scan|Bitmap|cost=|actual time=)", text))
if has_explain or has_plan_shape:
print("✅ EXPLAIN output or plan-shape evidence present")
else:
print("❌ no EXPLAIN output or query-plan evidence found — a performance claim needs a real plan, not a guess")
fail = 1
mentions_index = re.findall(r"\bindex(?:es)?\b", text, re.IGNORECASE)
named_index = re.findall(r"\bidx_[a-zA-Z0-9_]+\b", text)
if mentions_index and not named_index:
print("❌ discusses an index but never names one (expected an idx_* identifier) — name the specific index")
fail = 1
elif named_index:
print(f"✅ names specific index(es): {', '.join(sorted(set(named_index)))}")
else:
print("⚠️ no index discussion found — confirm this review didn't need one")
return fail
if __name__ == "__main__":
raise SystemExit(main())