Skip to content

Commit

Permalink
feat: add vacuum
Browse files Browse the repository at this point in the history
  • Loading branch information
matthias-Q committed Jun 17, 2023
1 parent f3c3515 commit bf8edb4
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
39 changes: 39 additions & 0 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ module.exports = grammar({
keyword_current_timestamp: _ => make_keyword("current_timestamp"),
keyword_check: _ => make_keyword("check"),
keyword_option: _ => make_keyword("option"),
keyword_vacuum: _ => make_keyword("vacuum"),

keyword_trigger: _ => make_keyword('trigger'),
keyword_function: _ => make_keyword("function"),
Expand Down Expand Up @@ -1401,6 +1402,44 @@ module.exports = grammar({
$.where,
)
),
// Vacuum
seq(
$.keyword_vacuum,
optional($._vacuum_option),
$.table_reference,
optional(
seq(
optional(
paren_list($.field)
)
)
),
),
// MariaDB Optimize
seq(
$.keyword_optimize,
optional(
choice(
$.keyword_local,
//$.keyword_no_write_to_binlog,
)
),
$.keyword_table,
$.table_reference,
repeat(seq(',', $.table_reference)),
),
),

_vacuum_option: $ => choice(
seq($.keyword_full, optional(choice($.keyword_true, $.keyword_false))),
seq($.keyword_parallel, optional(choice($.keyword_true, $.keyword_false))),
seq($.keyword_analyze, optional(choice($.keyword_true, $.keyword_false))),
// seq($.keyword_freeze, choice($.keyword_true, $.keyword_false)),
// seq($.keyword_skip_locked, choice($.keyword_true, $.keyword_false)),
// seq($.keyword_truncate, choice($.keyword_true, $.keyword_false)),
// seq($.keyword_disable_page_skipping, choice($.keyword_true, $.keyword_false)),
// seq($.keyword_process_toast, choice($.keyword_true, $.keyword_false)),
// seq($.keyword_index_cleanup, choice($.keyword_auto, $.keyword_on, $.keyword_off)),
),

// TODO: this does not account for partitions specs like
Expand Down
52 changes: 52 additions & 0 deletions test/corpus/optimize.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,55 @@ OPTIMIZE mytable REWRITE DATA USING BIN_PACK
(keyword_not))
(literal
(keyword_null))))))

================================================================================
Vacuum
================================================================================

VACUUM my_table;

--------------------------------------------------------------------------------

(program
(statement
(keyword_vacuum)
(table_reference
(identifier))))

================================================================================
Vacuum Postgres with options
================================================================================

VACUUM FULL true my_table (col1, col2);

--------------------------------------------------------------------------------

(program
(statement
(keyword_vacuum)
(keyword_full)
(keyword_true)
(table_reference
(identifier))
(field
(identifier))
(field
(identifier))))

================================================================================
MariaDB Optimize Table
================================================================================

OPTIMIZE LOCAL TABLE my_table1, my_table2

--------------------------------------------------------------------------------

(program
(statement
(keyword_optimize)
(keyword_local)
(keyword_table)
(table_reference
(identifier))
(table_reference
(identifier))))

0 comments on commit bf8edb4

Please sign in to comment.