Commit a3708e7
committed
feat: automatically include EXPLAIN plan in AI analysis
Enhanced AI-powered query analysis by automatically including query execution
plan (EXPLAIN) in the context sent to AI providers. This significantly improves
the quality of AI recommendations as it can see actual execution details.
Changes:
1. Updated AiAnalysisService::analyzeQuery():
- Added optional ExplainAnalysis parameter
- Passes explain plan to buildQueryContext() for AI context
2. Updated AiCommand::analyze():
- Now executes EXPLAIN plan before sending to AI
- Includes execution plan in AI context for better analysis
- Gracefully handles EXPLAIN failures (continues without plan)
3. Updated AiCommand::query():
- Passes baseAnalysis (which includes EXPLAIN plan) to AI service
- AI now receives both base analysis and execution plan
4. Updated SelectQueryBuilder::explainAiAdvice():
- Passes baseAnalysis to analyzeQuery() for better AI analysis
5. Updated MCP tools:
- AnalyzeQueryTool: Gets EXPLAIN plan and includes it in AI context
- ExplainPlanTool: Passes baseAnalysis to AI service
Benefits:
- AI can see actual execution plan (table scans, index usage, access types)
- More accurate optimization recommendations
- Better understanding of query performance bottlenecks
- No user action required - works automatically for all AI analysis commands
Both 'pdodb ai analyze' and 'pdodb ai query' commands now automatically
include EXPLAIN plan in AI context, providing more accurate and actionable
recommendations.1 parent e380095 commit a3708e7
File tree
5 files changed
+52
-8
lines changed- src
- ai
- mcp/tools
- cli/commands
- query
5 files changed
+52
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
100 | 101 | | |
101 | 102 | | |
102 | 103 | | |
| 104 | + | |
103 | 105 | | |
104 | 106 | | |
105 | 107 | | |
106 | | - | |
| 108 | + | |
107 | 109 | | |
108 | 110 | | |
109 | 111 | | |
| |||
120 | 122 | | |
121 | 123 | | |
122 | 124 | | |
123 | | - | |
| 125 | + | |
124 | 126 | | |
125 | 127 | | |
126 | 128 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
62 | 63 | | |
63 | 64 | | |
64 | 65 | | |
65 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
66 | 85 | | |
67 | 86 | | |
68 | 87 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
83 | | - | |
84 | | - | |
| 83 | + | |
| 84 | + | |
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
66 | 87 | | |
67 | 88 | | |
68 | 89 | | |
| |||
72 | 93 | | |
73 | 94 | | |
74 | 95 | | |
75 | | - | |
| 96 | + | |
76 | 97 | | |
77 | 98 | | |
78 | 99 | | |
| |||
152 | 173 | | |
153 | 174 | | |
154 | 175 | | |
155 | | - | |
| 176 | + | |
| 177 | + | |
156 | 178 | | |
157 | 179 | | |
158 | 180 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
991 | 991 | | |
992 | 992 | | |
993 | 993 | | |
994 | | - | |
| 994 | + | |
| 995 | + | |
995 | 996 | | |
996 | 997 | | |
997 | 998 | | |
| |||
0 commit comments