Summary
DbContext.Execute (DbContext.cs:795-800) and the surrounding DbReader / DbWriter SQL invocations have no instrumentation hook for query-level profiling. There is no slow-query log, no per-statement-type counter, no aggregate "this kind of statement was issued N times this run" report. When a query is slow on a large index, the only tool is an external profiler or manual EXPLAIN QUERY PLAN. New regressions in query patterns go undetected until users complain.
Where
src/CodeIndex/Database/DbContext.cs:795-800 (Execute)
src/CodeIndex/Database/DbReader.cs / DbWriter.cs (call sites)
Suggested approach
(1) Wrap Execute in a helper that records (statement_hash, elapsed_ms, row_count) per call. (2) Aggregate per-process: total count, p50/p95/p99 elapsed, total wall-clock contribution. (3) Behind a --profile-db flag, emit the aggregate as a JSON footer on the command's output. (4) Behind a CDIDX_SLOW_QUERY_MS=100 env var, log any statement exceeding the threshold to stderr with the first 200 chars of the SQL and the bind values. (5) Expose the aggregate through status --json for long-running MCP servers under db.query_stats. (6) Cover with a regression test that issues a synthetic slow query and asserts it appears in the slow-query log. (7) Cross-link with #1437 (composite index) — instrumentation will reveal which queries benefit.
Summary
DbContext.Execute(DbContext.cs:795-800) and the surroundingDbReader/DbWriterSQL invocations have no instrumentation hook for query-level profiling. There is no slow-query log, no per-statement-type counter, no aggregate "this kind of statement was issued N times this run" report. When a query is slow on a large index, the only tool is an external profiler or manualEXPLAIN QUERY PLAN. New regressions in query patterns go undetected until users complain.Where
src/CodeIndex/Database/DbContext.cs:795-800(Execute)src/CodeIndex/Database/DbReader.cs/DbWriter.cs(call sites)Suggested approach
(1) Wrap
Executein a helper that records(statement_hash, elapsed_ms, row_count)per call. (2) Aggregate per-process: total count, p50/p95/p99 elapsed, total wall-clock contribution. (3) Behind a--profile-dbflag, emit the aggregate as a JSON footer on the command's output. (4) Behind aCDIDX_SLOW_QUERY_MS=100env var, log any statement exceeding the threshold to stderr with the first 200 chars of the SQL and the bind values. (5) Expose the aggregate throughstatus --jsonfor long-running MCP servers underdb.query_stats. (6) Cover with a regression test that issues a synthetic slow query and asserts it appears in the slow-query log. (7) Cross-link with #1437 (composite index) — instrumentation will reveal which queries benefit.