You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A developer tool that analyzes SQL queries for cost anti-patterns, estimates execution cost across cloud warehouses, recommends partitioning and clustering strategies, and benchmarks engines head-to-head — all from the command line.
Architecture
flowchart TD
subgraph Input
SQL[SQL Query / File]
WL[Query Workload]
end
subgraph Analyzer
PA[Query Analyzer<br/>sqlglot AST]
CE[Cost Estimator<br/>BigQuery · Snowflake · Spark]
end
subgraph Recommender
PR[Partition Recommender<br/>workload analysis]
ZO[Z-Order Advisor<br/>co-location scoring]
end
subgraph Benchmark
BR[Benchmark Runner<br/>p50 · p99 · mean]
DK[DuckDB Engine<br/>baseline]
SP[Spark Engine<br/>optional]
RP[Report Generator<br/>Markdown]
end
subgraph Outputs
CLI[CLI Output<br/>rich terminal]
SD[Streamlit Dashboard]
MD[Benchmark Report<br/>Markdown]
end
SQL --> PA
SQL --> CE
WL --> PR
WL --> ZO
PA --> CLI
CE --> CLI
PR --> CLI
ZO --> CLI
BR --> DK
BR --> SP
DK --> RP
SP --> RP
RP --> MD
CLI --> SD
MD --> SD
Loading
Features
Feature
Description
Query Analysis
Detects SELECT *, missing partition filters, cartesian joins, unbounded windows, large IN lists
Cost Estimation
Estimates cost on BigQuery ($6.25/TB), Snowflake (credits), Spark (cluster-hours)
Partition Recommender
Analyses a workload of queries to recommend PARTITION BY and ZORDER BY columns with DDL
Benchmark Runner
Runs the NYC Taxi query suite on DuckDB (and optionally Spark), reporting p50/p99 latency
Streamlit Dashboard
Interactive 4-page UI for exploratory analysis
Quick Start
pip install -e .# Analyze a single query
cost-optimizer analyze "SELECT pickup_date, COUNT(*) FROM nyc_taxi WHERE year=2024 GROUP BY 1"# Analyze queries from a file
cost-optimizer analyze --file queries/my_workload.sql
# Get partition recommendations for a workload directory
cost-optimizer recommend --workload-dir queries/
# Run the benchmark suite
cost-optimizer benchmark --engine duckdb --report benchmark_results/report.md
# Launch the Streamlit dashboard
streamlit run dashboard/streamlit_app.py
CLI Reference
cost-optimizer analyze
Options:
--dialect TEXT SQL dialect: bigquery, snowflake, spark, duckdb [default: spark]
--file PATH Read SQL from a file instead of inline
--json Output raw JSON instead of formatted table
Options:
--workload-dir PATH Directory of .sql files to analyse
--file PATH Single SQL file
--table TEXT Target table name for generated DDL [default: my_table]
cost-optimizer benchmark
Options:
--engine [duckdb|spark|all] Engine(s) to benchmark [default: duckdb]
--data-path PATH Path to NYC Taxi parquet files
--report PATH Write Markdown report to this path
--runs INTEGER Timed runs per query [default: 5]
Anti-Pattern Detection
Issue
Severity
Description
SELECT *
HIGH
Reads all columns; prevents projection pushdown
Missing partition filter
HIGH
Full table scan on partitioned tables
Cartesian join
CRITICAL
Cross join produces row explosion
Unbounded window
MEDIUM
No PARTITION BY on window function
Large IN list
MEDIUM
>50 values; rewrite as JOIN or temp table
No LIMIT on SELECT
LOW
Returns unbounded rows to client
Cost Model
Engine
Unit
Rate
BigQuery
TB scanned
$6.25 / TB
Snowflake
Credits
$3.00 / credit
Spark (EMR)
Node-hours
Cluster config × hours
DuckDB
—
Free (local)
Estimates assume typical column cardinality from the NYC Taxi dataset (~15M rows/month). Use --json to get raw estimates for your own calibration.