import { useRouter } from 'next/router' import Table from 'components/to-be-cleaned/Table' import { DbQueryHook } from 'hooks/analytics/useDbQuery' import { Tabs } from 'ui' import { Markdown } from '../Markdown' import ReportQueryPerformanceTableRow from '../Reports/ReportQueryPerformanceTableRow' import { PresetHookResult } from '../Reports/Reports.utils' import { QueryPerformanceFilterBar } from '../QueryPerformanceV2/QueryPerformanceFilterBar' import { ResetAnalysisNotice } from './ResetAnalysisNotice' import ShimmeringLoader from 'ui-patterns/ShimmeringLoader' import { QUERY_PERFORMANCE_REPORT_TYPES } from '../QueryPerformanceV2/QueryPerformance.constants' type QueryPerformancePreset = 'time' | 'frequent' | 'slowest' const panelClassNames = 'text-sm max-w-none flex flex-col gap-4' const TimeConsumingHelperText = `This table lists queries ordered by their cumulative total execution time. It displays the total time a query has spent running and the proportion of total execution time the query has consumed. ` const MostFrequentHelperText = `This table lists queries in order of their execution count, providing insights into the most frequently executed queries. Pay attention to queries with high max_time or mean_time values that are called frequently, as they may benefit from optimization. ` const SlowestExecutionHelperText = `This table lists queries ordered by their maximum execution time. It shows outliers with high execution times. Look for queries with high or mean execution times as these are often good candidates for optimization. ` interface QueryPerformanceProps { queryHitRate: PresetHookResult queryPerformanceQuery: DbQueryHook } const QueryPerformanceLoadingRow = ({ colSpan }: { colSpan: number }) => { return ( <> {Array(4) .fill('') .map((_, i) => ( ))} ) } export const QueryPerformance = ({ queryHitRate, queryPerformanceQuery, }: QueryPerformanceProps) => { const router = useRouter() const handleRefresh = async () => { queryPerformanceQuery.runQuery() queryHitRate.runQuery() } return ( { // To reset the search and sort query params when switching tabs const { sort, search, ...rest } = router.query router.push({ ...router, query: { ...rest, preset: e, }, }) }} >
RoleQueryCallsTime ConsumedTotal Latency } body={ !queryPerformanceQuery.isLoading ? ( queryPerformanceQuery?.data?.map((item, i) => { return ( {item.rolname}

{item.query}

{item.calls} {item.prop_total_time} {item.total_time.toFixed(2)}ms
) }) ) : ( ) } />
RoleQueryAvg. RolesCallsMax TimeMean TimeMin TimeTotal Latency } body={ queryPerformanceQuery.isLoading ? ( ) : ( queryPerformanceQuery.data?.map((item, i) => { return ( {item.rolname}

{item.query}

{item.avg_rows} {item.calls} {item.max_time?.toFixed(2)}ms {item.mean_time?.toFixed(2)}ms {item.min_time?.toFixed(2)}ms {item.total_time?.toFixed(2)}ms
) }) ) } />
RoleQueryAvg RowsCallsMax TimeMean TimeMin TimeTotal Latency } body={ queryPerformanceQuery.isLoading ? ( ) : ( queryPerformanceQuery.data?.map((item, i) => { return ( {item.rolname}

{item.query}

{item.avg_rows} {item.calls} {item.max_time?.toFixed(2)}ms {item.mean_time?.toFixed(2)}ms {item.min_time?.toFixed(2)}ms {item.total_time?.toFixed(2)}ms
) }) ) } /> ) }