ctx sql runs read-only SQL against the code-intelligence index through DuckDB.
The query surface is the versioned v1 schema: a set of stable views over
the physical index. Query v1.* — not the underlying tables.
v1.* is the contract. Columns and views may be added within
schema_version 1. Renaming or removing anything increments
v1.meta.schema_version and is noted in the changelog.
Everything outside v1.* is internal and unstable. The raw index is
reachable as code.*, but its shape can change at any time and it is excluded
from all compatibility guarantees. Do not depend on it.
Access is read-only and engine-hardened. Filesystem access, extension
loading, and attaching other databases are disabled; the index cannot be
modified.
-- Ten most complex symbolsSELECT name, file, complexityFROM v1.symbolsORDER BY complexity DESCLIMIT 10;
-- Symbol counts by kindSELECT kind, COUNT(*) AS nFROM v1.symbolsGROUP BY kindORDER BY n DESC;
-- Public functions that nothing calls (dead-code candidates)SELECT name, fileFROM v1.symbolsWHERE kind IN ('function', 'method') AND is_public AND fan_in = 0ORDER BY file, name;
ctx sql --snapshots[=DIR] (default DIR is .ctx/snapshots) additionally
loads the Parquet snapshot partitions written by ctx snapshot as in-memory
tables in the snap schema. These tables exist only when --snapshots
is passed; without it, any snap.* reference is an error. Every row is
denormalized with the partition stamp:
Stamp columns plus the v1.symbols columns id, name, qualified_name,
kind, file, line_start, line_end, is_public, complexity,
fan_in, and fan_out (same types as in v1.symbols; no doc).
snap.dup_pairs — one row per near-duplicate pair per commit
-- Duplication trendSELECT commit_sha, min(committed_at) AS committed_at, count(*) AS dup_pairs FROM snap.dup_pairs GROUP BY commit_sha ORDER BY committed_at;
-- Violation trendSELECT commit_sha, min(committed_at) AS committed_at, sum(violation_count) AS violations FROM snap.files GROUP BY commit_sha ORDER BY committed_at;
-- Hotspot mass (top-decile complexity by commit)WITH ranked AS (SELECT commit_sha, committed_at, churn_commits * total_complexity AS mass, percent_rank() OVER (PARTITION BY commit_sha ORDER BY total_complexity) AS pr FROM snap.files) SELECT commit_sha, min(committed_at) AS committed_at, sum(mass) AS hotspot_mass FROM ranked WHERE pr >= 0.9 GROUP BY commit_sha ORDER BY committed_at;