Skip to content

No slow-query log or per-statement profiling for DbContext.Execute #1789

Description

@Widthdom

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions