feat: v0.2.4 异步Compaction + 槽位压缩 + EXPLAIN + 慢查询日志
This commit is contained in:
@@ -26,6 +26,7 @@ export class QueryExecutor {
|
||||
async execute(stmt: Statement): Promise<unknown> {
|
||||
switch (stmt.type) {
|
||||
case 'SELECT': return this.executeSelect(stmt);
|
||||
case 'EXPLAIN': return this.executeExplain(stmt as any);
|
||||
case 'INSERT': return this.executeInsert(stmt);
|
||||
case 'UPDATE': return this.executeUpdate(stmt);
|
||||
case 'DELETE': return this.executeDelete(stmt);
|
||||
@@ -35,6 +36,31 @@ export class QueryExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
/** EXPLAIN: 输出查询计划 */
|
||||
private async executeExplain(stmt: { query: Statement }): Promise<Record<string, unknown>> {
|
||||
const plan = compileStatement(stmt.query.type === 'SELECT' ? stmt.query : stmt.query as any);
|
||||
const startTime = Date.now();
|
||||
let result: unknown = null;
|
||||
try {
|
||||
result = await this.execute(stmt.query);
|
||||
} catch { /* explain 即使执行失败也返回计划 */ }
|
||||
const elapsed = Date.now() - startTime;
|
||||
const rows = Array.isArray(result) ? result.length : 0;
|
||||
|
||||
return {
|
||||
type: stmt.query.type,
|
||||
table: plan.table,
|
||||
columns: plan.columns,
|
||||
where: plan.where || {},
|
||||
orderBy: plan.orderBy || [],
|
||||
limit: plan.limit,
|
||||
offset: plan.offset,
|
||||
usingIndex: plan.table ? 'auto' : 'none',
|
||||
estimatedRows: rows,
|
||||
actualTimeMs: elapsed,
|
||||
};
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
// SELECT
|
||||
// ===================================================================
|
||||
|
||||
Reference in New Issue
Block a user