release: v0.5.1 — 存储后端生产级硬化(CRC-32/全库加密/WAL分片/页面化存储/多标签页锁/e2e)+ 深度审查修复(假实现接线/死代码清理)
This commit is contained in:
+77
-1
@@ -72,6 +72,19 @@ export class Parser {
|
||||
return this.parseCommit();
|
||||
case TokenType.ROLLBACK:
|
||||
return this.parseRollback();
|
||||
// v0.5.1: 维护语句入口
|
||||
case TokenType.EXPLAIN:
|
||||
return this.parseExplain();
|
||||
case TokenType.ANALYZE:
|
||||
return this.parseAnalyze();
|
||||
case TokenType.REINDEX:
|
||||
return this.parseReindex();
|
||||
case TokenType.VACUUM:
|
||||
return this.parseVacuum();
|
||||
case TokenType.SAVEPOINT:
|
||||
return this.parseSavepoint();
|
||||
case TokenType.RELEASE:
|
||||
return this.parseSavepoint();
|
||||
default:
|
||||
throw this.error(`Unexpected token "${this.curToken.value}"`);
|
||||
}
|
||||
@@ -95,6 +108,57 @@ export class Parser {
|
||||
return statements;
|
||||
}
|
||||
|
||||
// ---- 维护语句(v0.5.1) ----
|
||||
|
||||
/** EXPLAIN <statement> — 输出查询计划 */
|
||||
private parseExplain(): import('../query/ast').ExplainStatement {
|
||||
this.expect(TokenType.EXPLAIN);
|
||||
if (this.curTokenIs(TokenType.EXPLAIN)) {
|
||||
throw this.error('Nested EXPLAIN is not allowed');
|
||||
}
|
||||
const query = this.parseStatement();
|
||||
return { type: 'EXPLAIN', query };
|
||||
}
|
||||
|
||||
/** ANALYZE [TABLE] name — 收集表统计信息 */
|
||||
private parseAnalyze(): import('../query/ast').AnalyzeStatement {
|
||||
this.expect(TokenType.ANALYZE);
|
||||
if (this._isKeywordAsIdent() && this.curToken.value.toUpperCase() === 'TABLE') {
|
||||
this.nextToken();
|
||||
}
|
||||
return { type: 'ANALYZE', table: this.expectIdentifier('table name') };
|
||||
}
|
||||
|
||||
/** REINDEX [TABLE] name — 重建表二级索引 */
|
||||
private parseReindex(): import('../query/ast').ReindexStatement {
|
||||
this.expect(TokenType.REINDEX);
|
||||
if (this._isKeywordAsIdent() && this.curToken.value.toUpperCase() === 'TABLE') {
|
||||
this.nextToken();
|
||||
}
|
||||
return { type: 'REINDEX', table: this.expectIdentifier('table name') };
|
||||
}
|
||||
|
||||
/** VACUUM — 压缩 LSM + 清理碎片 */
|
||||
private parseVacuum(): import('../query/ast').VacuumStatement {
|
||||
this.expect(TokenType.VACUUM);
|
||||
return { type: 'VACUUM' };
|
||||
}
|
||||
|
||||
/** SAVEPOINT name | RELEASE [SAVEPOINT] name */
|
||||
private parseSavepoint(): import('../query/ast').SavepointStatement {
|
||||
let action: 'SAVE' | 'ROLLBACK' | 'RELEASE';
|
||||
if (this.curTokenIs(TokenType.RELEASE)) {
|
||||
action = 'RELEASE';
|
||||
this.nextToken();
|
||||
} else {
|
||||
action = 'SAVE';
|
||||
this.expect(TokenType.SAVEPOINT);
|
||||
}
|
||||
// 可选 SAVEPOINT 关键字(RELEASE SAVEPOINT name)
|
||||
if (this.curTokenIs(TokenType.SAVEPOINT)) this.nextToken();
|
||||
return { type: 'SAVEPOINT', name: this.expectIdentifier('savepoint name'), action };
|
||||
}
|
||||
|
||||
// ---- 事务语句 ----
|
||||
|
||||
private parseBegin(): BeginTransactionStatement {
|
||||
@@ -114,10 +178,22 @@ export class Parser {
|
||||
return { type: 'COMMIT' };
|
||||
}
|
||||
|
||||
private parseRollback(): RollbackTransactionStatement {
|
||||
/** ROLLBACK [TRANSACTION] | ROLLBACK TO [SAVEPOINT] name(v0.5.1) */
|
||||
private parseRollback(): Statement {
|
||||
this.expect(TokenType.ROLLBACK);
|
||||
if (this._isKeywordAsIdent() && this.curToken.value.toUpperCase() === 'TRANSACTION') {
|
||||
this.nextToken();
|
||||
return { type: 'ROLLBACK' };
|
||||
}
|
||||
// ROLLBACK TO [SAVEPOINT] name
|
||||
if (this.curTokenIs(TokenType.TO) ||
|
||||
(this._isKeywordAsIdent() && this.curToken.value.toUpperCase() === 'TO')) {
|
||||
this.nextToken();
|
||||
if (this.curTokenIs(TokenType.SAVEPOINT) ||
|
||||
(this._isKeywordAsIdent() && this.curToken.value.toUpperCase() === 'SAVEPOINT')) {
|
||||
this.nextToken();
|
||||
}
|
||||
return { type: 'SAVEPOINT', name: this.expectIdentifier('savepoint name'), action: 'ROLLBACK' };
|
||||
}
|
||||
return { type: 'ROLLBACK' };
|
||||
}
|
||||
|
||||
@@ -83,6 +83,15 @@ export enum TokenType {
|
||||
ELSE = 'ELSE',
|
||||
END = 'END',
|
||||
|
||||
// v0.5.1: 维护语句(EXPLAIN / ANALYZE / REINDEX / VACUUM / SAVEPOINT)
|
||||
EXPLAIN = 'EXPLAIN',
|
||||
ANALYZE = 'ANALYZE',
|
||||
REINDEX = 'REINDEX',
|
||||
VACUUM = 'VACUUM',
|
||||
SAVEPOINT = 'SAVEPOINT',
|
||||
RELEASE = 'RELEASE',
|
||||
TO = 'TO',
|
||||
|
||||
// 标识符 & 字面量
|
||||
IDENTIFIER = 'IDENTIFIER',
|
||||
STRING = 'STRING',
|
||||
@@ -195,4 +204,13 @@ export const KEYWORDS: Record<string, TokenType> = {
|
||||
'THEN': TokenType.THEN,
|
||||
'ELSE': TokenType.ELSE,
|
||||
'END': TokenType.END,
|
||||
|
||||
// v0.5.1
|
||||
'EXPLAIN': TokenType.EXPLAIN,
|
||||
'ANALYZE': TokenType.ANALYZE,
|
||||
'REINDEX': TokenType.REINDEX,
|
||||
'VACUUM': TokenType.VACUUM,
|
||||
'SAVEPOINT': TokenType.SAVEPOINT,
|
||||
'RELEASE': TokenType.RELEASE,
|
||||
'TO': TokenType.TO,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user