Join Inspector
Catch row multiplication from bad JOINs before they inflate your numbers
Analyzes your SQL JOINs before execution to detect many-to-many relationships that silently multiply rows. Warns you that revenue is about to be 3x too high before you send the wrong number to the CFO.
PROMPT
Create a skill called "Join Inspector". When I paste a SQL query, analyze every JOIN and determine: (1) The cardinality of each join relationship (one-to-one, one-to-many, many-to-many) based on the join keys and available constraints. (2) The estimated row count after each JOIN step. (3) Whether any JOIN is likely to cause row fan-out (multiplying rows unexpectedly). (4) Whether any JOIN has missing or incomplete join conditions (potential cross join). For each risk found, explain the impact (e.g., "This many-to-many JOIN will inflate your SUM(revenue) by a factor of ~3x") and suggest a fix (dedup CTE, GROUP BY, DISTINCT, or restructured JOIN order). If I can connect to the database, verify cardinality against actual data.
How It Works
One of the most insidious SQL bugs: a many-to-many JOIN silently inflates
your row count, and all your aggregations are wrong. The query runs without
errors, the numbers look plausible, and you send them to leadership. This
skill catches it before that happens.
What You Get
- Pre-execution JOIN analysis: is each JOIN one-to-one, one-to-many, or many-to-many?
- Row count estimates at each JOIN step (expected vs. actual)
- Warnings for fan-out risk with specific mitigation suggestions
- Detection of accidental cross joins from missing join conditions
- Suggestions for deduplication or GROUP BY when fan-out is unavoidable
Setup Steps
- Ask your Claw to create a "Join Inspector" skill with the prompt below
- Paste any SQL query with JOINs
- Get a JOIN-by-JOIN analysis before running it on production data
Tips
- Especially useful when joining dimension tables to fact tables — the cardinality assumptions are rarely documented
- Run this on any query that feeds executive dashboards
- The row count comparison (before vs. after each JOIN) is the fastest way to spot fan-out
- Pairs with Query Decoder for understanding unfamiliar queries' JOIN logic