Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/remote/optimization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const LiveQueryOptimization = z.discriminatedUnion("state", [
costReductionPercentage: z.number(),
indexRecommendations: z.array(IndexRecommendation),
indexesUsed: z.array(z.string()),
consideredIndexes: z.array(IndexRecommendation).optional(),
explainPlan: z.custom<PostgresExplainStage>(),
optimizedExplainPlan: z.custom<PostgresExplainStage>(),
}),
Expand Down
8 changes: 8 additions & 0 deletions src/remote/query-optimizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ export class QueryOptimizer extends EventEmitter<EventMap> {
costReductionPercentage,
indexRecommendations,
indexesUsed,
consideredIndexes: mapConsideredIndexes(result),
explainPlan,
optimizedExplainPlan: result.explainPlan,
};
Expand Down Expand Up @@ -512,6 +513,7 @@ export class QueryOptimizer extends EventEmitter<EventMap> {
costReductionPercentage,
indexRecommendations,
indexesUsed,
consideredIndexes: mapConsideredIndexes(result),
explainPlan,
optimizedExplainPlan: result.explainPlan,
};
Expand Down Expand Up @@ -582,6 +584,12 @@ function mapIndexRecommandations(
});
}

function mapConsideredIndexes(
result: Extract<OptimizeResult, { kind: "ok" }>,
): IndexRecommendation[] {
return Array.from(result.triedIndexes.values());
}

type PercentageDifference = number;

export function costDifferencePercentage(
Expand Down