Skip to content

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

fix: handle errors better in index advisor (#42043)

Ali Waseem9e1df69853aa
diff --git a/apps/studio/components/interfaces/QueryPerformance/QueryIndexes.tsx b/apps/studio/components/interfaces/QueryPerformance/QueryIndexes.tsx
index 371e7131c9f..ef1a2c71f6f 100644
--- a/apps/studio/components/interfaces/QueryPerformance/QueryIndexes.tsx
+++ b/apps/studio/components/interfaces/QueryPerformance/QueryIndexes.tsx
@@ -5,6 +5,7 @@ import { AccordionTrigger } from '@ui/components/shadcn/ui/accordion'
import { useIndexAdvisorStatus } from 'components/interfaces/QueryPerformance/hooks/useIsIndexAdvisorStatus'
import AlertError from 'components/ui/AlertError'
import { DocsButton } from 'components/ui/DocsButton'
+import { Admonition } from 'ui-patterns'
import { useDatabaseExtensionsQuery } from 'data/database-extensions/database-extensions-query'
import { useGetIndexAdvisorResult } from 'data/database/retrieve-index-advisor-result-query'
import { useGetIndexesFromSelectQuery } from 'data/database/retrieve-index-from-select-query'
@@ -256,7 +257,9 @@ export const QueryIndexes = ({
</QueryPanelSection>
<QueryPanelSection className="flex flex-col gap-y-6 py-6 border-t">
<div className="flex flex-col gap-y-1">
- <h4 className="mb-2">New index recommendations</h4>
+ {(!isSuccessIndexAdvisorResult || indexAdvisorResult !== null) && (
+ <h4 className="mb-2">New index recommendations</h4>
+ )}
{isLoadingExtensions ? (
<GenericSkeletonLoader />
) : !isIndexAdvisorEnabled ? (
@@ -273,7 +276,14 @@ export const QueryIndexes = ({
)}
{isSuccessIndexAdvisorResult && (
<>
- {(index_statements ?? []).length === 0 ? (
+ {indexAdvisorResult === null ? (
+ <Admonition
+ type="default"
+ showIcon={true}
+ title="Index recommendations not available"
+ description="Index advisor could not analyze this query. This can happen if the query references tables, functions, or extensions that no longer exist or were deleted."
+ />
+ ) : (index_statements ?? []).length === 0 ? (
<Alert_Shadcn_ className="[&>svg]:rounded-full">
<Check />
<AlertTitle_Shadcn_>This query is optimized</AlertTitle_Shadcn_>
diff --git a/apps/studio/data/database/retrieve-index-advisor-result-query.ts b/apps/studio/data/database/retrieve-index-advisor-result-query.ts
index 001b9c7b03f..057ba69a102 100644
--- a/apps/studio/data/database/retrieve-index-advisor-result-query.ts
+++ b/apps/studio/data/database/retrieve-index-advisor-result-query.ts
@@ -39,16 +39,18 @@ export async function getIndexAdvisorResult({
})
if (!results || results.length === 0) {
- throw new Error('Index advisor returned no results')
+ console.error('[index_advisor > getIndexAdvisorResult] No results from index_advisor')
+ return null
}
const parsed = IndexAdvisorResultSchema.safeParse(results[0])
if (!parsed.success) {
const firstError = parsed.error.errors[0]
const errorPath = firstError.path.length > 0 ? ` at path: ${firstError.path.join('.')}` : ''
- throw new Error(
+ console.error(
`Invalid index advisor response${errorPath}: ${firstError.message}. Received: ${JSON.stringify(results[0])}`
)
+ return null
}
return filterProtectedSchemaIndexAdvisorResult(parsed.data)