# Dashboard Numeric Search Timeout Plan

## Current Design

- Numeric dashboard searches query cluster ID, parent ID, project ID, and TiDB Cloud organization ID through four `UNION` branches.
- The count query projects only `c.id`, but the list query projects complete dashboard rows before applying the outer sort and pagination.
- A large project or organization can therefore materialize and sort many wide rows even when the API requests only ten items.
- All database transactions currently use the shared 30-second timeout.

## Target Contract

- Each numeric list branch sorts identically to the outer query and returns at most `offset + limit` rows before `UNION` deduplication.
- The outer query keeps the existing sort, limit, and offset behavior, so API ordering and pagination remain unchanged.
- Numeric count queries keep their existing narrow projection and 30-second timeout.
- Only the numeric list transaction receives a 45-second timeout; all other transactions retain the 30-second default.
- HTTP parameters, response fields, database schema, and indexes remain unchanged.

## Implementation Steps

1. Add an explicit-timeout database transaction helper while preserving the existing default transaction behavior.
2. Extend numeric list SQL generation with branch-local ordering and an `offset + limit` cap.
3. Use the 45-second transaction helper only when loading numeric search list rows.
4. Add SQL-generation and transaction-timeout regression tests.

## Verification Checklist

- Four numeric list branches contain the requested ordering and branch-local limit.
- First-page and later-page queries use the correct branch cap.
- Created-at, deleted-at, and duration ordering remain consistent between branch and outer queries.
- Numeric count SQL remains unordered and unbounded.
- `go test ./pkg/datasource ./pkg/db -count=1` passes.
- Staging numeric search returns HTTP 200 with correct totals, ordering, pagination, and latency below the timeout threshold.

## Non-Goals

- Do not increase the global database transaction timeout.
- Do not add or force database indexes without execution-plan evidence.
- Do not change fuzzy text search behavior.
- Do not introduce the broader narrow-ID UNION and row-fetch redesign in this change.
