"""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
print("Usage: check_explain.py <review.md>", file=sys.stderr)
text = open(sys.argv[1], encoding="utf-8").read()
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")
print("❌ no EXPLAIN output or query-plan evidence found — a performance claim needs a real plan, not a guess")
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")
print(f"✅ names specific index(es): {', '.join(sorted(set(named_index)))}")
print("⚠️ no index discussion found — confirm this review didn't need one")
if __name__ == "__main__":