Files
kemal.earthandAli Waseem 511b6faada feat(studio): surface index advisor indicators (#40788)
* feat: change the check to show index advisor tab at all times

* fix: hide add to log drains on export menu in query perf

* fix: small fallback for pathname check

* fix: query perf header block responsiveness

* feat: admonition for index advisor

* fix: add aria-describedby to query perf sheet

* feat: proper way to do sheet description

* chore: better title spacing in panel

* fix: indexes in use empty state

* fix: key in observability menu

* feat: better highlighting of index advisor issues

* feat: add docs button to empty indexes tab

* feat: remove unused code

* feat: use button tooltips for reset and refresh to gain space

* feat: add dismiss to index advisor banner

* feat: add warnings filter to query perf

* feat: filter all queries for warnings

* fix: selected state for warning rows

* fix: fallback for isLogs check

* fix: other instance of download button

---------

Co-authored-by: Ali Waseem <waseema393@gmail.com>
2025-11-27 08:20:07 -07:00

73 lines
1.7 KiB
TypeScript

import useDbQuery from 'hooks/analytics/useDbQuery'
import { PRESET_CONFIG } from './Reports.constants'
import { Presets } from './Reports.types'
export type QueryPerformanceSort = {
column:
| 'query'
| 'rolname'
| 'total_time'
| 'prop_total_time'
| 'calls'
| 'avg_rows'
| 'max_time'
| 'mean_time'
| 'min_time'
order: 'asc' | 'desc'
}
export type QueryPerformanceQueryOpts = {
preset:
| 'mostFrequentlyInvoked'
| 'mostTimeConsuming'
| 'slowestExecutionTime'
| 'queryHitRate'
| 'unified'
| 'slowQueriesCount'
| 'queryMetrics'
searchQuery?: string
orderBy?: QueryPerformanceSort
roles?: string[]
runIndexAdvisor?: boolean
minCalls?: number
filterIndexAdvisor?: boolean
}
export const useQueryPerformanceQuery = ({
preset,
orderBy,
searchQuery = '',
roles,
runIndexAdvisor = false,
minCalls,
filterIndexAdvisor = false,
}: QueryPerformanceQueryOpts) => {
const queryPerfQueries = PRESET_CONFIG[Presets.QUERY_PERFORMANCE]
const baseSQL = queryPerfQueries.queries[preset]
const whereSql = [
roles !== undefined && roles.length > 0
? `auth.rolname in (${roles.map((r) => `'${r}'`).join(', ')})`
: '',
searchQuery.length > 0 ? `statements.query ~* '${searchQuery}'` : '',
typeof minCalls === 'number' && minCalls > 0 ? `statements.calls >= ${minCalls}` : '',
]
.filter((x) => x.length > 0)
.join(' AND ')
const orderBySql = orderBy && `ORDER BY ${orderBy.column} ${orderBy.order}`
const sql = baseSQL.sql(
[],
whereSql.length > 0 ? `WHERE ${whereSql}` : undefined,
orderBySql,
runIndexAdvisor,
filterIndexAdvisor
)
return useDbQuery({
sql,
params: undefined,
where: whereSql,
orderBy: orderBySql,
})
}