The SQL analyzer ships in phases. Each phase delivers usable output before the next phase compounds on it.Documentation Index
Fetch the complete documentation index at: https://mehen.ophi.dev/llms.txt
Use this file to discover all available pages before exploring further.
Phase 1 — parser adapter and raw metrics
Deliverables:- Dialect selection / configuration (CLI flag, project config, conservative inference).
- Parse diagnostics and parser-confidence metrics.
- Statement count and statement-kind classification.
- LOC / comment / blank / code metrics for
.sqlfiles. - Query-block count / depth.
- CTE count and dependency graph.
- Join count / kind metrics.
- Subquery and derived-table metrics.
- CASE, boolean predicate, window, aggregate, set-operation counts.
- SELECT
*, missing alias, unqualified column ratio. - Basic DDL/DML risk metrics.
- SQL Halstead counts.
Phase 2 — composite scores and profiles
sql.structural_complexity.sql.cognitive_complexity.sql.review_burden_index.sql.change_risk_score.sql.maintainability_index.sql.modularity_health.- Profile-based thresholds (
sql.analytics_default,sql.migration_default,sql.procedural_default). - Diff-aware deltas.
Phase 3 — procedural SQL
- PL/SQL and T-SQL procedural block detection.
- Procedural cyclomatic / cognitive complexity (using Sonar’s PL/SQL increments as reference).
- Exception / cursor / loop / dynamic-SQL metrics.
- Embedded query complexity attribution inside routines.
Phase 4 — optional schema and lineage enrichments
- Optional schema catalog input.
- More accurate object/column reference resolution.
- Foreign-key-aware join graph classification.
- Optional sqruff lineage integration or mehen lineage implementation.
- Schema blast-radius metrics.
Dialect coverage (initial)
ansi, postgres, sqlite, mysql, tsql, oracle/plsql, snowflake, bigquery, duckdb (subject
to parser maturity).
Validation strategy
- Golden fixtures by dialect and file role (analytics, migration, procedural).
- Prior-art compatibility tests against
sqlfluff-complexityCPX rules. - Repository calibration on migration-heavy, dbt/analytics, app-embedded SQL, and PL/SQL projects.
- Human validation ranking sampled SQL files against
structural_complexity,cognitive_complexity,review_burden_index, Halstead volume, and LOC.
References
- SonarQube PL/SQL.
- SonarQube T-SQL.
- SQLFluff complexity plugin.
- sqruff.
- Yu et al. (2018). Spider: A Large-Scale Human-Labeled Dataset for Complex and Cross-Domain Semantic Parsing and Text-to-SQL Task. arXiv:1809.08887 · Benchmark site.
- Vashistha, A. & Jain, S. Measuring Query Complexity in SQLShare Workload. PDF.
- Piattini, M. & Martínez, A. Measuring for Database Programs Maintainability. DOI.
See also
- SQL metrics overview — namespace inventory.
- Concepts → Architecture — where
mehen-sqlwill fit.