fix: don't scan the whole table to discover Map keys - #3082
niladrix719 wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: d4c52d0 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
@niladrix719 is attempting to deploy a commit to the HyperDX Team on Vercel. A member of the Team first needs to authorize it. |
Greptile SummaryBounds Map-key discovery so autocomplete cannot trigger unscoped ClickHouse table scans.
Confidence Score: 5/5The PR appears safe to merge; no blocking or non-blocking new issue remains after the latest changes. The latest changes preserve the bounded discovery behavior and safely move the AI metadata regression test into a focused file with sufficient mocks and setup. All previous findings are resolved; niladrix719 explicitly deferred the broader editor-coverage suggestion and accepted the narrow empty-index retry cost, while other fixes or withdrawals addressed the remaining threads.
|
| Filename | Overview |
|---|---|
| packages/common-utils/src/core/metadata.ts | Adds bounded Map-key discovery windows, separate cache scopes, guarded raw scans, and bounded fallback behavior. |
| packages/app/src/components/SQLEditor/SQLInlineEditor.tsx | Resolves matching source metadata without applying one source’s timestamp or rollup configuration to another table. |
| packages/app/src/hooks/useMetadata.tsx | Passes optional date-range and timestamp context through shared multi-table field discovery. |
| packages/api/src/controllers/ai.ts | Supplies AI metadata discovery with a default bounded range, timestamp expression, and metadata rollups. |
| packages/api/src/controllers/tests/aiMetadata.test.ts | Isolates bounded AI metadata coverage in a focused, fully mocked test file. |
| packages/app/src/components/SQLEditor/tests/SQLInlineEditor.test.tsx | Covers matching and mismatched source/table identities plus metric-source timestamp behavior. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart LR
E[Autocomplete editor] --> S[Resolve source and table]
S --> M[Map-key discovery]
M --> I{Text index available?}
I -->|Yes| B[Bounded part lookup]
I -->|No| R{Metadata rollup available?}
R -->|Yes| W[Bounded rollup query]
R -->|No| T{Timestamp expression available?}
T -->|Yes| Q[Bounded raw-table scan]
T -->|No| X[Skip Map-key discovery]
B --> C[Cache suggestions]
W --> C
Q --> C
Reviews (48): Last reviewed commit: "fix: don't scan the whole table to disco..." | Re-trigger Greptile
Deep ReviewIntent: bound Map-key metadata discovery in ✅ No critical (P0/P1) issues found. 🟡 P2 — recommended
🔵 P3 nitpicks (8)
Reviewers (9): correctness, adversarial, performance, reliability, testing, maintainability, kieran-typescript, project-standards, previous-comments. Testing gaps: getMapKeys kv text-index branch and text-index error fall-through are untested; no test asserts |
a3fb411 to
02b87c1
Compare
1712d3d to
bc6864f
Compare
bc6864f to
fc153e3
Compare
PR Review3 finding(s): 🔴 0 critical · 🟠 1 major · 🔵 2 minor 1 posted as inline comment(s) on the changed lines. 2 listed below. Findings outside the changed lines
1 minor
Severity is the reviewer's own estimate and is used for ordering, not filtering. |
fc153e3 to
1a29213
Compare
1a29213 to
001e0be
Compare
001e0be to
b3d622e
Compare
b3d622e to
518c53b
Compare
518c53b to
78143e9
Compare
78143e9 to
51a52da
Compare
51a52da to
91d76d3
Compare
1446c17 to
be9f509
Compare
be9f509 to
9e6709a
Compare
9e6709a to
379ae86
Compare
379ae86 to
c588b9c
Compare
c588b9c to
47c93f1
Compare
47c93f1 to
92e3385
Compare
92e3385 to
2c547a5
Compare
2c547a5 to
229ee95
Compare
229ee95 to
9c8a1c1
Compare
9c8a1c1 to
fde0eb3
Compare
fde0eb3 to
c5671fe
Compare
c5671fe to
c4b9561
Compare
Signed-off-by: Niladri Adhikary <niladrix719@gmail.com>
c4b9561 to
d4c52d0
Compare
Fixes #3037
Summary
getMapKeysonly added a time filter when the caller happened to pass both a date range and a timestamp expression. Several UI autocomplete call sites (chart editor, alert modal, dashboard filters) passed neither. When that happened, it fell back to an unbounded scan across the whole table instead of skipping or narrowing the querySteps to reproduce
open the chart editor, don't touch the time picker, and start typing a Group By expression on a Map column (
ResourceAttributes[). that keystroke sent ClickHouse a query with no time filter, reading every part of the table, not just recent onesThe fix
Both the raw-table scan and the text-index lookup now refuse to run without something to bound them. Field autocomplete falls back to a 24h window when it
knows the timestamp column but not the range, and the call sites that had a source/date range in scope but weren't passing them now do
Before / after
Before:
No
WHERE/predicate, full-table scanAfter:
Known gap
The SQL editors in source-configuration forms still don't pass scope, so Map keys won't autocomplete there. Left as a follow-up, needs the form's in-progress
timestampValueExpression, which isn't available the same way