Skip to content

feat(api): bypass cache for raw admin SQL queries #93

Closed

Description

@taitelee

Problem

Currently, raw SQL queries submitted via the /v1/query endpoint are routed through the TieredCache and singleflight mechanism. This is an anti-pattern for administrative tools because:

  1. Consistency: Admins and CI/CD E2E tests require real-time data to verify ingestion correctness (read-your-writes).
  2. Cache Pollution: Ad-hoc raw SQL queries are highly unique and rarely re-executed, causing unnecessary memory/Redis churn in the TieredCache.

Proposed Solution

  • Modify api/query.go: Update the QueryHandler.Handle method to bypass the h.Cache (Get/Set) and singleflight (if applicable) logic when processing raw SQL.
  • Header Management: Ensure the response is served with Cache-Control: no-cache to discourage intermediate or client-side caching.
  • Separation of Concerns: This change must strictly apply to raw SQL (/v1/query). Structured queries and pipes must remain cached to maintain system performance.

Acceptance Criteria

  • Direct execution against ClickHouse for all POST /v1/query requests.
  • No h.Cache.Get or h.Cache.Set logic triggered for the raw SQL path.
  • Raw SQL responses include Cache-Control: no-cache header.
  • E2E/Admin tests that perform inserts followed by counts/reads now pass reliably without stale data collisions.
  • /pipes (Named Queries) and Structured Queries retain current caching/singleflight behavior.

This issue is part of the "Query Cache" improvement initiative discussed in the recent standup (#73 . It serves as the primary "escape hatch" for administrative data verification while we implement more complex invalidation logic for structured queries.

Alternatives Considered

None

Additional Context

None

Activity

  1. self-assigned this
    on May 6, 2026
  2. moved this from Backlog to In progress in WaveHouse Task Boardon May 6, 2026
  3. moved this from In progress to Ready in WaveHouse Task Boardon May 11, 2026
  4. moved this from Ready to In progress in WaveHouse Task Boardon May 12, 2026
  5. EricAndrechek commented on May 19, 2026

    @EricAndrechek
    Member

    Closing as done by PR #164.

    Two commits cover this:

    • 45bc840 — moves raw SQL from /v1/query to /v1/admin/query under the admin gate.
    • 421c3ce — strips the TieredCache + singleflight from QueryHandler entirely. Both Cache.Get and Cache.Set are gone, no cache key is computed, no X-Cache: HIT/MISS header is emitted, and the mutation cache-bypass branch is removed (no cache to bypass). The structured query and pipes endpoints retain their caching unchanged.

    Acceptance criteria status:

    • Direct execution against ClickHouse for all raw-SQL requests — every request is a fresh round-trip.
    • No h.Cache.Get / h.Cache.Set triggered — QueryHandler no longer holds a Cache field.
    • E2E reliability — no cache, no stale-read class of bug for this endpoint.
    • /pipes + structured queries retain caching — unchanged.
    • Cache-Control: no-cache response header — not yet shipped; will land in the upcoming HTTP-proxy refactor (next commit on the same branch, replacing clickhouse-go Query/Exec with a thin proxy to ClickHouse's HTTP interface). Tracking that change in PR refactor(ingest)!: insert-only pipeline; mutations via /v1/query #164 too.
  6. EricAndrechek commented on May 19, 2026

    @EricAndrechek
    Member

    Reopening — jumped the gun. The work is in PR #164 but the issue should auto-close on merge, not before. I've updated the PR description to include `Closes #93` so GitHub closes it when (and only when) the PR lands.

  7. moved this from Ready to In progress in WaveHouse Task Boardon May 19, 2026
  8. added a commit that references this issue on May 20, 2026
    e07d5ed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/apiHTTP handlers, routing, middlewareenhancementNew feature or request

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions