-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Utilizes the EXPLAIN ESTIMATE feature and queries CH to return # of rows that will be potentially read. Ref: HDX-1136
- Loading branch information
Showing
2 changed files
with
92 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { useQuery, UseQueryOptions } from '@tanstack/react-query'; | ||
|
||
import { sendQuery } from '@/clickhouse'; | ||
import { | ||
ChartConfigWithDateRange, | ||
renderChartConfig, | ||
} from '@/renderChartConfig'; | ||
|
||
export function useExplainQuery( | ||
config: ChartConfigWithDateRange, | ||
options?: Omit<UseQueryOptions<any>, 'queryKey' | 'queryFn'>, | ||
) { | ||
const { data, isLoading, error } = useQuery({ | ||
queryKey: ['explain', config], | ||
queryFn: async ({ signal }) => { | ||
const query = await renderChartConfig(config); | ||
const response = await sendQuery<'JSONEachRow'>({ | ||
query: `EXPLAIN ESTIMATE ${query.sql}`, | ||
query_params: query.params, | ||
format: 'JSONEachRow', | ||
abort_signal: signal, | ||
connectionId: config.connection, | ||
}); | ||
return response.json(); | ||
}, | ||
retry: false, | ||
staleTime: 1000 * 60, | ||
...options, | ||
}); | ||
|
||
return { data, isLoading, error }; | ||
} |