feat: v0.2.4 异步Compaction + 槽位压缩 + EXPLAIN + 慢查询日志
CI / test (18.x) (push) Failing after 5m0s
CI / test (20.x) (push) Failing after 4m58s
CI / test (22.x) (push) Failing after 4m58s
CI / test (24.x) (push) Failing after 4m57s

This commit is contained in:
thzxx
2026-07-27 21:53:13 +08:00
parent da999d607b
commit 82e6baaae9
4 changed files with 104 additions and 2 deletions
+26
View File
@@ -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
// ===================================================================