import { LoadingLine, cn } from 'ui' import { useState, useEffect, useMemo } from 'react' import { Button } from 'ui' import { X, RefreshCw, RotateCcw } from 'lucide-react' import { Markdown } from '../../Markdown' import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal' import { useLocalStorageQuery } from 'hooks/misc/useLocalStorage' import { LOCAL_STORAGE_KEYS, useParams } from 'common' import { useDatabaseSelectorStateSnapshot } from 'state/database-selector' import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject' import { DOCS_URL, IS_PLATFORM } from 'lib/constants' import { executeSql } from 'data/sql/execute-sql-query' import { toast } from 'sonner' import { useReadReplicasQuery } from 'data/read-replicas/replicas-query' import { formatDatabaseID } from 'data/read-replicas/replicas.utils' import { PresetHookResult } from 'components/interfaces/Reports/Reports.utils' import { DbQueryHook } from 'hooks/analytics/useDbQuery' import { QueryPerformanceMetrics } from '../QueryPerformanceMetrics' import { QueryPerformanceFilterBar } from '../QueryPerformanceFilterBar' import { QueryPerformanceGrid } from '../QueryPerformanceGrid' import { transformStatementDataToRows } from './WithStatements.utils' import { DownloadResultsButton } from 'components/ui/DownloadResultsButton' interface WithStatementsProps { queryHitRate: PresetHookResult queryPerformanceQuery: DbQueryHook queryMetrics: PresetHookResult } export const WithStatements = ({ queryHitRate, queryPerformanceQuery, queryMetrics, }: WithStatementsProps) => { const { ref } = useParams() const { data: project } = useSelectedProjectQuery() const state = useDatabaseSelectorStateSnapshot() const { data, isLoading, isRefetching } = queryPerformanceQuery const isPrimaryDatabase = state.selectedDatabaseId === ref const formattedDatabaseId = formatDatabaseID(state.selectedDatabaseId ?? '') const [showResetgPgStatStatements, setShowResetgPgStatStatements] = useState(false) const [showBottomSection, setShowBottomSection] = useLocalStorageQuery( LOCAL_STORAGE_KEYS.QUERY_PERF_SHOW_BOTTOM_SECTION, true ) const handleRefresh = () => { queryPerformanceQuery.runQuery() queryHitRate.runQuery() queryMetrics.runQuery() } const processedData = useMemo(() => { return transformStatementDataToRows(data || []) }, [data]) const { data: databases } = useReadReplicasQuery({ projectRef: ref }) useEffect(() => { state.setSelectedDatabaseId(ref) // eslint-disable-next-line react-hooks/exhaustive-deps }, [ref]) return ( <> } />

Reset report

Consider resetting the analysis after optimizing any queries

How is this report generated?

Inspect your database for potential issues

setShowResetgPgStatStatements(false)} onConfirm={async () => { const connectionString = databases?.find( (db) => db.identifier === state.selectedDatabaseId )?.connectionString if (IS_PLATFORM && !connectionString) { return toast.error('Unable to run query: Connection string is missing') } try { await executeSql({ projectRef: project?.ref, connectionString, sql: `SELECT pg_stat_statements_reset();`, }) handleRefresh() setShowResetgPgStatStatements(false) } catch (error: any) { toast.error(`Failed to reset analysis: ${error.message}`) } }} >

This will reset the pg_stat_statements table in the extensions schema on your{' '} {isPrimaryDatabase ? 'primary database' : `read replica (ID: ${formattedDatabaseId})`} , which is used to calculate query performance. This data will repopulate immediately after.

) }