Summary
Allow users to paste existing ETL SQL (queries, stored procedures, views) and get AI-powered performance analysis: index suggestions, anti-pattern detection, partitioning recommendations, and optimization tips — all contextualized with the actual schema from connected sources.
Problem
Slow ETL queries are the WhatsApp Integration #1 operational issue in data pipelines
Users lack tools that combine SQL analysis with actual schema knowledge
Generic SQL linters don't know the data distribution, row counts, or column cardinality
EXPLAIN plans are hard to read without experience
Anti-patterns (SELECT *, implicit cartesian joins, N+1 patterns) go undetected until production
Proposed Solution
Analysis Capabilities
Anti-pattern detection : SELECT *, implicit cross joins, OR chains instead of IN, unnecessary subqueries, non-sargable WHERE clauses
Index suggestions : Based on WHERE/JOIN/ORDER BY columns + table cardinality from profiling
Partitioning recommendations : Suggest partition keys based on date columns and query patterns
Query rewrite suggestions : CTEs vs subqueries, window functions vs self-joins, UNION ALL vs UNION
Dialect-specific advice : BigQuery (avoid SELECT *, use APPROX_COUNT_DISTINCT), Snowflake (clustering keys), PostgreSQL (partial indexes)
Complexity scoring : Estimate query complexity (joins, subqueries, aggregations) as a readability metric
How It Works
User pastes SQL or selects a saved query
Platform identifies the target dialect and referenced tables
If tables match connected sources → enrich analysis with actual profiling data (row counts, cardinality, data types)
LLM analyzes the query with full context and returns structured recommendations
Output: annotated SQL with inline suggestions + summary report
Technical Notes
Schema context : Match referenced table names against Source.metadata_.table_infos for enriched analysis
LLM prompt : System prompt with SQL optimization expertise + actual schema stats as context
No execution : The platform does not run EXPLAIN — it analyzes SQL statically with LLM reasoning
New endpoint : POST /api/tools/analyze-sql with sql, dialect, source_ids[] (optional for schema context)
Frontend : SQL editor with syntax highlighting + annotation sidebar for suggestions
Acceptance Criteria
Summary
Allow users to paste existing ETL SQL (queries, stored procedures, views) and get AI-powered performance analysis: index suggestions, anti-pattern detection, partitioning recommendations, and optimization tips — all contextualized with the actual schema from connected sources.
Problem
Proposed Solution
Analysis Capabilities
How It Works
Technical Notes
Source.metadata_.table_infosfor enriched analysisPOST /api/tools/analyze-sqlwithsql,dialect,source_ids[](optional for schema context)Acceptance Criteria