A runtime logical debugger for SQL
Project description
sql-autopsy
A runtime logical debugger for SQL.
Have you ever run a massive, 1,000-line SQL query with dozens of CTEs (Common Table Expressions) and JOINs, only to realize that somewhere in the middle, all of your data vanished? Or worse, a bad join caused your row count to explode?
Finding the exact line of code that broke your dataset usually means manually commenting out blocks of SQL and running SELECT COUNT(*) repeatedly.
sql-autopsy automates this process. It takes your failing SQL query, dissects it, caches each step locally, and pinpoints exactly which line of code broke your logic.
How It Works
- Disassembles your SQL: Parses your script and maps the execution order of all your CTEs.
- Avoids the Materialization Trap: Rewrites your query on the fly to cache intermediate results into temporary tables (using DuckDB by default), so your database doesn't re-calculate the entire query from scratch for every check.
- Probes the Data: Runs lightweight probes to check row counts and
NULLvalues at every step. - Diagnoses the Flaw: Pinpoints the exact cause of your data anomaly.
What it catches:
- Fatal Drops (Black Holes): A
WHEREclause that accidentally filters out 100% of the rows. - Cartesian Explosions (Fan-Outs): A bad
JOINthat accidentally multiplies your row counts. - Join Key Mismatches (Null-Outs): A
LEFT JOINwhere the join keys don't match, resulting in 100%NULLcolumns.
Installation
You can install sql-autopsy easily via pip. Requires Python 3.9+.
pip install sql-autopsy
Usage
Running sql-autopsy is as simple as pointing it at your broken SQL file.
autopsy broken_script.sql
By default, the autopsy runs locally using DuckDB in-memory (perfect for fast testing on mock data). You can also target a live database by passing a connection string:
autopsy broken_script.sql --target postgres://user:pass@localhost/db
Example
Imagine you have a script named broken_script.sql that joins users to orders and then filters them. Somewhere in the code, the rows disappear.
Simply run:
autopsy broken_script.sql
Output:
Execution Summary
+--------------------------------+
| Order | CTE Name | Row Count |
|-------+------------+-----------|
| 1 | first_cte | 3 |
| 2 | second_cte | 2 |
| 3 | third_cte | 3 |
| 4 | fourth_cte | 0 |
+--------------------------------+
Autopsy completed with 1 fatal flaw(s) found:
Fatal Drop in fourth_cte
WHERE clause removed 100% of incoming rows from 'third_cte' (3 -> 0).
+--------------------------- Offending SQL Snippet ---------------------------+
| 1 SELECT * FROM third_cte WHERE name = 'Charlie' |
+-----------------------------------------------------------------------------+
Instead of wasting hours digging through SQL, sql-autopsy immediately tells you that fourth_cte removed all incoming rows because nobody is named "Charlie".
Contributing
sql-autopsy is open-source and looking for contributors!
We rely heavily on sqlglot for parsing, networkx for DAG routing, and SQLAlchemy for query execution. Pull requests for new dialects (Snowflake, BigQuery) and new diagnostic rules are highly welcome.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sql_autopsy-0.1.4.tar.gz.
File metadata
- Download URL: sql_autopsy-0.1.4.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d9e32cc1b83a8824b97596fc4f8066bbb336530d35feecf052228827b2aec781
|
|
| MD5 |
b70594d7a6a770f40c607fa273a69f50
|
|
| BLAKE2b-256 |
94c2b5ebd3fa5991a43510838da3e37c567dc6bbc0e0335abd9eb188b041dc65
|
Provenance
The following attestation bundles were made for sql_autopsy-0.1.4.tar.gz:
Publisher:
publish.yml on prysthedev/sql-autopsy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sql_autopsy-0.1.4.tar.gz -
Subject digest:
d9e32cc1b83a8824b97596fc4f8066bbb336530d35feecf052228827b2aec781 - Sigstore transparency entry: 2195045269
- Sigstore integration time:
-
Permalink:
prysthedev/sql-autopsy@e8c5ad5d41828f455978866efa5d454c61535f5e -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/prysthedev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e8c5ad5d41828f455978866efa5d454c61535f5e -
Trigger Event:
release
-
Statement type:
File details
Details for the file sql_autopsy-0.1.4-py3-none-any.whl.
File metadata
- Download URL: sql_autopsy-0.1.4-py3-none-any.whl
- Upload date:
- Size: 9.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3035e23cbf74afe92108748dd3cd7eeb0b677281e74d66c7e080e60a0ffadbe1
|
|
| MD5 |
39191777bdfcbee90284b7db5d5b48c9
|
|
| BLAKE2b-256 |
b5c0c3b4e94e2536da09290c050ffd50c99e836735db5539a831062c9d725496
|
Provenance
The following attestation bundles were made for sql_autopsy-0.1.4-py3-none-any.whl:
Publisher:
publish.yml on prysthedev/sql-autopsy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sql_autopsy-0.1.4-py3-none-any.whl -
Subject digest:
3035e23cbf74afe92108748dd3cd7eeb0b677281e74d66c7e080e60a0ffadbe1 - Sigstore transparency entry: 2195045272
- Sigstore integration time:
-
Permalink:
prysthedev/sql-autopsy@e8c5ad5d41828f455978866efa5d454c61535f5e -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/prysthedev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e8c5ad5d41828f455978866efa5d454c61535f5e -
Trigger Event:
release
-
Statement type: