Skip to content

Commit 1088682

Browse files
authored
feat: Add # of planned read rows on search (#538)
1 parent 83f9997 commit 1088682

File tree

2 files changed

+92
-18
lines changed

2 files changed

+92
-18
lines changed

packages/app/src/DBSearchPage.tsx

Lines changed: 60 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import WhereLanguageControlled from '@/components/WhereLanguageControlled';
5555
import { IS_LOCAL_MODE } from '@/config';
5656
import { DisplayType } from '@/DisplayType';
5757
import { useQueriedChartConfig } from '@/hooks/useChartConfig';
58+
import { useExplainQuery } from '@/hooks/useExplainQuery';
5859
import { withAppNav } from '@/layout';
5960
import {
6061
ChartConfig,
@@ -151,6 +152,33 @@ function SearchTotalCount({
151152
);
152153
}
153154

155+
function SearchNumRows({
156+
config,
157+
enabled,
158+
}: {
159+
config: ChartConfigWithDateRange;
160+
enabled: boolean;
161+
}) {
162+
const { data, isLoading, error } = useExplainQuery(config, {
163+
enabled,
164+
});
165+
166+
if (!enabled) {
167+
return null;
168+
}
169+
170+
const numRows = data?.[0]?.rows;
171+
return (
172+
<Text size="xs" c="gray.4" mb={4}>
173+
{isLoading
174+
? 'Scanned Rows ...'
175+
: error || !numRows
176+
? ''
177+
: `Scanned Rows: ${numRows}`}
178+
</Text>
179+
);
180+
}
181+
154182
function SaveSearchModal({
155183
searchedConfig,
156184
opened,
@@ -1006,26 +1034,40 @@ function DBSearchPage() {
10061034
)}
10071035
<div style={{ display: 'flex', flexDirection: 'column' }}>
10081036
{analysisMode === 'results' && (
1009-
<Box style={{ height: 120, minHeight: 120 }} p="xs" mb="md">
1037+
<Box
1038+
style={{ height: 140, minHeight: 140 }}
1039+
p="xs"
1040+
pb="md"
1041+
mb="md"
1042+
>
10101043
{chartConfig && (
10111044
<>
1012-
<SearchTotalCount
1013-
config={{
1014-
...chartConfig,
1015-
select: [
1016-
{
1017-
aggFn: 'count',
1018-
aggCondition: '',
1019-
valueExpression: '',
1020-
},
1021-
],
1022-
orderBy: undefined,
1023-
granularity: 'auto',
1024-
dateRange: searchedTimeRange,
1025-
displayType: DisplayType.StackedBar,
1026-
}}
1027-
queryKeyPrefix={QUERY_KEY_PREFIX}
1028-
/>
1045+
<Group justify="space-between" mb={4}>
1046+
<SearchTotalCount
1047+
config={{
1048+
...chartConfig,
1049+
select: [
1050+
{
1051+
aggFn: 'count',
1052+
aggCondition: '',
1053+
valueExpression: '',
1054+
},
1055+
],
1056+
orderBy: undefined,
1057+
granularity: 'auto',
1058+
dateRange: searchedTimeRange,
1059+
displayType: DisplayType.StackedBar,
1060+
}}
1061+
queryKeyPrefix={QUERY_KEY_PREFIX}
1062+
/>
1063+
<SearchNumRows
1064+
config={{
1065+
...chartConfig,
1066+
dateRange: searchedTimeRange,
1067+
}}
1068+
enabled={isReady}
1069+
/>
1070+
</Group>
10291071
<DBTimeChart
10301072
sourceId={searchedConfig.source ?? undefined}
10311073
showLegend={false}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { useQuery, UseQueryOptions } from '@tanstack/react-query';
2+
3+
import { sendQuery } from '@/clickhouse';
4+
import {
5+
ChartConfigWithDateRange,
6+
renderChartConfig,
7+
} from '@/renderChartConfig';
8+
9+
export function useExplainQuery(
10+
config: ChartConfigWithDateRange,
11+
options?: Omit<UseQueryOptions<any>, 'queryKey' | 'queryFn'>,
12+
) {
13+
const { data, isLoading, error } = useQuery({
14+
queryKey: ['explain', config],
15+
queryFn: async ({ signal }) => {
16+
const query = await renderChartConfig(config);
17+
const response = await sendQuery<'JSONEachRow'>({
18+
query: `EXPLAIN ESTIMATE ${query.sql}`,
19+
query_params: query.params,
20+
format: 'JSONEachRow',
21+
abort_signal: signal,
22+
connectionId: config.connection,
23+
});
24+
return response.json();
25+
},
26+
retry: false,
27+
staleTime: 1000 * 60,
28+
...options,
29+
});
30+
31+
return { data, isLoading, error };
32+
}

0 commit comments

Comments
 (0)