|
| 1 | +import { buildExplainPlanPrompt } from '../../src/prompts'; |
| 2 | + |
| 3 | +const defaultExplainPlan = { |
| 4 | + queryPlanner: { |
| 5 | + plannerVersion: 1, |
| 6 | + namespace: 'account.users', |
| 7 | + indexFilterSet: false, |
| 8 | + parsedQuery: {}, |
| 9 | + winningPlan: { |
| 10 | + stage: 'COLLSCAN', |
| 11 | + direction: 'forward', |
| 12 | + }, |
| 13 | + rejectedPlans: [], |
| 14 | + }, |
| 15 | + executionStats: { |
| 16 | + executionSuccess: true, |
| 17 | + nReturned: 1, |
| 18 | + executionTimeMillis: 0, |
| 19 | + totalKeysExamined: 0, |
| 20 | + totalDocsExamined: 1, |
| 21 | + executionStages: { |
| 22 | + stage: 'COLLSCAN', |
| 23 | + nReturned: 1, |
| 24 | + executionTimeMillisEstimate: 0, |
| 25 | + works: 3, |
| 26 | + advanced: 1, |
| 27 | + needTime: 1, |
| 28 | + needYield: 0, |
| 29 | + saveState: 0, |
| 30 | + restoreState: 0, |
| 31 | + isEOF: 1, |
| 32 | + direction: 'forward', |
| 33 | + docsExamined: 1, |
| 34 | + }, |
| 35 | + }, |
| 36 | + serverInfo: { |
| 37 | + host: 'M-LKXPQX2JRY', |
| 38 | + port: 27017, |
| 39 | + version: '4.4.24', |
| 40 | + gitVersion: '0b86b9b7b42ad9970c5f818c527dd86c0634243a', |
| 41 | + }, |
| 42 | + ok: 1, |
| 43 | + $clusterTime: { |
| 44 | + clusterTime: { |
| 45 | + $timestamp: '7541009763346153473', |
| 46 | + }, |
| 47 | + signature: { |
| 48 | + hash: 'AAAAAAAAAAAAAAAAAAAAAAAAAAA=', |
| 49 | + keyId: 0, |
| 50 | + }, |
| 51 | + }, |
| 52 | + operationTime: { |
| 53 | + $timestamp: '7541009763346153473', |
| 54 | + }, |
| 55 | +}; |
| 56 | + |
| 57 | +export function buildPrompt(): string { |
| 58 | + return buildExplainPlanPrompt({ |
| 59 | + explainPlan: JSON.stringify(defaultExplainPlan), |
| 60 | + }).prompt; |
| 61 | +} |
| 62 | + |
| 63 | +export function buildExpected(): string { |
| 64 | + return `**Human-Readable Explanation:** |
| 65 | +
|
| 66 | +This query performed a collection scan (\`COLLSCAN\`) on the \`account.users\` collection, reading documents sequentially without using any indexes. The query returned one result and examined one document, completing very quickly. |
| 67 | +
|
| 68 | +**Performance Impact:** |
| 69 | +
|
| 70 | +- For small collections, a collection scan is fast and does not present a performance issue. |
| 71 | +- For large collections, collection scans can become slow because every document must be read, especially if queries become frequent or the result set grows. |
| 72 | +
|
| 73 | +**Optimization Suggestion:** |
| 74 | +
|
| 75 | +- If there are no filters in your query (i.e., it retrieves all documents), creating an index is unnecessary and provides no performance benefit. |
| 76 | +- If you add query filters in the future (e.g., searching by username or email), consider creating an index on those fields to enhance performance. |
| 77 | +- In MongoDB Compass, you can create indexes using the "Indexes" tab for your collection. |
| 78 | +
|
| 79 | +**Summary:** |
| 80 | +No index is needed for this query as written, but be aware collection scans do not scale well with large data. Monitor query performance as your collection grows or your query changes, and add indexes only if your query includes a filter or sort. |
| 81 | +
|
| 82 | +If you'd like to see how your query performs as your data grows, MongoDB Compass provides performance tools like the "Explain Plan" feature to visualize query execution and index usage.`; |
| 83 | +} |
| 84 | + |
| 85 | +export function buildExpectedSources(): string[] { |
| 86 | + return []; |
| 87 | +} |
0 commit comments