From 115063bc97940d37a89bd155908822dc9dd40eae Mon Sep 17 00:00:00 2001 From: Aaron Knudtson <87577305+knudtty@users.noreply.github.com> Date: Tue, 24 Nov 2026 15:01:16 -0500 Subject: [PATCH] feat: only use cache for row lookups if cache is available --- .changeset/row-lookup-filesystem-cache.md | 7 +++++++ .../app/src/components/DBRowDataPanel.tsx | 17 ++++++++++++++++- .../DBRowDataPanel.rowQuery.test.tsx | 10 ++++++++++ .../__tests__/DBRowDataPanel.test.ts | 19 +++++++++++++------ 4 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 .changeset/row-lookup-filesystem-cache.md diff --git a/.changeset/row-lookup-filesystem-cache.md b/.changeset/row-lookup-filesystem-cache.md new file mode 100644 index 0000000000..08ae48b45b --- /dev/null +++ b/.changeset/row-lookup-filesystem-cache.md @@ -0,0 +1,7 @@ +--- +'@hyperdx/app': patch +--- + +perf: row lookups read from the ClickHouse filesystem cache when the data is +already there, without filling the cache with data nothing else is likely to +read. diff --git a/packages/app/src/components/DBRowDataPanel.tsx b/packages/app/src/components/DBRowDataPanel.tsx index 2667f7f4ae..82526be630 100644 --- a/packages/app/src/components/DBRowDataPanel.tsx +++ b/packages/app/src/components/DBRowDataPanel.tsx @@ -5,6 +5,7 @@ import { tcFromSource } from '@hyperdx/common-utils/dist/core/metadata'; import { isLogSource, isTraceSource, + QuerySettings, SourceKind, TSource, } from '@hyperdx/common-utils/dist/types'; @@ -54,6 +55,15 @@ export enum ROW_DATA_ALIASES { // looks the same row up again. Those lookups reuse a found row instead of // running `SELECT *` again. A miss stays stale so the next lookup retries it: // the row may not have been ingested yet. +// A single-row lookup reads few granules, so it uses whatever is already in the +// filesystem cache without filling it with data nothing else is likely to read. +const ROW_LOOKUP_QUERY_SETTINGS: QuerySettings = [ + { + setting: 'read_from_filesystem_cache_if_exists_otherwise_bypass_cache', + value: '1', + }, +]; + function rowLookupStaleTime(query: Query) { return query.state.data?.data.length ? Infinity : 0; } @@ -273,7 +283,12 @@ export function useRowData({ ...(aliasWith && aliasWith.length > 0 ? { with: aliasWith } : {}), }; - const additionalQuerySettings = useSelectAllColumnsQuerySettings(source); + const selectAllColumnsQuerySettings = + useSelectAllColumnsQuerySettings(source); + const additionalQuerySettings: QuerySettings = [ + ...ROW_LOOKUP_QUERY_SETTINGS, + ...(selectAllColumnsQuerySettings ?? []), + ]; // This key replaces the config-derived one, so it has to carry the column // check's effect on the select. diff --git a/packages/app/src/components/__tests__/DBRowDataPanel.rowQuery.test.tsx b/packages/app/src/components/__tests__/DBRowDataPanel.rowQuery.test.tsx index 19cb6fd1c4..89b8ec6809 100644 --- a/packages/app/src/components/__tests__/DBRowDataPanel.rowQuery.test.tsx +++ b/packages/app/src/components/__tests__/DBRowDataPanel.rowQuery.test.tsx @@ -116,6 +116,16 @@ describe('row lookup', () => { }, ); + it('reads from the filesystem cache without filling it', async () => { + renderPanel({ source, rowId: "id='a'" }); + await settled(); + + expect(mockQueryChartConfig.mock.calls[0][0].querySettings).toContainEqual({ + setting: 'read_from_filesystem_cache_if_exists_otherwise_bypass_cache', + value: '1', + }); + }); + it('reuses a found row when the panel opens it again', async () => { const first = renderPanel({ source, rowId: "id='a'" }); await settled(); diff --git a/packages/app/src/components/__tests__/DBRowDataPanel.test.ts b/packages/app/src/components/__tests__/DBRowDataPanel.test.ts index fc21028fd2..e51c4b8e45 100644 --- a/packages/app/src/components/__tests__/DBRowDataPanel.test.ts +++ b/packages/app/src/components/__tests__/DBRowDataPanel.test.ts @@ -53,6 +53,11 @@ function queriedOptions(call = 0) { return options; } +const ROW_LOOKUP_SETTING = { + setting: 'read_from_filesystem_cache_if_exists_otherwise_bypass_cache', + value: '1', +}; + const showMaterializedAliasColumns = () => localStorage.setItem('hdx-row-show-materialized-alias-columns', 'true'); @@ -321,11 +326,11 @@ describe('DBRowDataPanel', () => { }); }); - it('adds no query settings while the viewer option is off', () => { + it('adds only the filesystem cache setting while the viewer option is off', () => { renderHook(() => useRowData({ source, rowId: "id='abc123'" })); for (const options of [queriedOptions(0), queriedOptions(1)]) { - expect(options.additionalQuerySettings).toBeUndefined(); + expect(options.additionalQuerySettings).toEqual([ROW_LOOKUP_SETTING]); expect(options.retry).toBeUndefined(); } }); @@ -336,6 +341,7 @@ describe('DBRowDataPanel', () => { for (const options of [queriedOptions(0), queriedOptions(1)]) { expect(options.additionalQuerySettings).toEqual([ + ROW_LOOKUP_SETTING, { setting: 'asterisk_include_materialized_columns', value: '1' }, { setting: 'asterisk_include_alias_columns', value: '1' }, ]); @@ -357,11 +363,12 @@ describe('DBRowDataPanel', () => { const options = queriedOptions(); expect(options.additionalQuerySettings).toEqual([ + ROW_LOOKUP_SETTING, { setting: 'asterisk_include_materialized_columns', value: '1' }, ]); }); - it('adds no query settings when the source sets both itself', () => { + it('adds no column settings when the source sets both itself', () => { showMaterializedAliasColumns(); const sourceWithSettings: TLogSource = { ...source, @@ -376,10 +383,10 @@ describe('DBRowDataPanel', () => { ); const options = queriedOptions(); - expect(options.additionalQuerySettings).toBeUndefined(); + expect(options.additionalQuerySettings).toEqual([ROW_LOOKUP_SETTING]); }); - it('adds no query settings when the source has a Known Columns List', () => { + it('adds no column settings when the source has a Known Columns List', () => { showMaterializedAliasColumns(); const sourceWithKnownColumns: TLogSource = { ...source, @@ -391,7 +398,7 @@ describe('DBRowDataPanel', () => { ); for (const options of [queriedOptions(0), queriedOptions(1)]) { - expect(options.additionalQuerySettings).toBeUndefined(); + expect(options.additionalQuerySettings).toEqual([ROW_LOOKUP_SETTING]); } });