Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix(studio): dynamic size for query perf time consumed col (#39379)

kemal.earth5c174b7ee6ba
diff --git a/apps/studio/components/interfaces/QueryPerformance/QueryPerformanceGrid.tsx b/apps/studio/components/interfaces/QueryPerformance/QueryPerformanceGrid.tsx
index fc8122627a0..e8e3c87ee0b 100644
--- a/apps/studio/components/interfaces/QueryPerformance/QueryPerformanceGrid.tsx
+++ b/apps/studio/components/interfaces/QueryPerformance/QueryPerformanceGrid.tsx
@@ -33,11 +33,48 @@ import {
} from './QueryPerformance.constants'
import { useQueryPerformanceSort } from './hooks/useQueryPerformanceSort'
import { formatDuration } from './QueryPerformance.utils'
+import { GetIndexAdvisorResultResponse } from 'data/database/retrieve-index-advisor-result-query'
interface QueryPerformanceGridProps {
queryPerformanceQuery: DbQueryHook<any>
}
+interface QueryPerformanceRow {
+ query: string
+ prop_total_time: number
+ total_time: number
+ calls: number
+ max_time: number
+ mean_time: number
+ min_time: number
+ rows_read: number
+ cache_hit_rate: string
+ rolname: string
+ index_advisor_result: GetIndexAdvisorResultResponse | null
+}
+
+const calculateTimeConsumedWidth = (data: QueryPerformanceRow[]) => {
+ if (!data || data.length === 0) return 150
+
+ let maxWidth = 150
+
+ data.forEach((row) => {
+ const percentage = row.prop_total_time || 0
+ const totalTime = row.total_time || 0
+
+ if (percentage && totalTime) {
+ const percentageText = `${percentage.toFixed(1)}%`
+ const durationText = formatDuration(totalTime)
+ const fullText = `${percentageText} / ${durationText}`
+ const estimatedWidth = fullText.length * 8 + 40
+
+ maxWidth = Math.max(maxWidth, estimatedWidth)
+ }
+ })
+
+ return Math.min(maxWidth, 300)
+}
+
export const QueryPerformanceGrid = ({ queryPerformanceQuery }: QueryPerformanceGridProps) => {
const { sort, setSortConfig } = useQueryPerformanceSort()
const gridRef = useRef<DataGridHandle>(null)
@@ -57,7 +94,8 @@ export const QueryPerformanceGrid = ({ queryPerformanceQuery }: QueryPerformance
name: col.name,
cellClass: `column-${col.id}`,
resizable: true,
- minWidth: col.minWidth ?? 120,
+ minWidth:
+ col.id === 'prop_total_time' ? calculateTimeConsumedWidth(data ?? []) : col.minWidth ?? 120,
sortable: !nonSortableColumns.includes(col.id),
headerCellClass: 'first:pl-6 cursor-pointer',
renderHeaderCell: () => {