Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 27 additions & 8 deletions src/query/ast/src/ast/statements/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -667,23 +667,42 @@ impl Display for TruncateTableStmt {
}

#[derive(Debug, Clone, PartialEq, Drive, DriveMut)]
pub struct VacuumTableStmt {
pub struct VacuumTargetTable {
pub catalog: Option<Identifier>,
pub database: Option<Identifier>,
pub table: Identifier,
}

#[derive(Debug, Clone, PartialEq, Drive, DriveMut)]
pub enum VacuumTarget {
Table(VacuumTargetTable),
All,
}

#[derive(Debug, Clone, PartialEq, Drive, DriveMut)]
pub struct VacuumTableStmt {
pub target: VacuumTarget,
pub option: VacuumTableOption,
}

impl Display for VacuumTableStmt {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
write!(f, "VACUUM TABLE ")?;
write_dot_separated_list(
f,
self.catalog
.iter()
.chain(&self.database)
.chain(Some(&self.table)),
)?;
match &self.target {
VacuumTarget::Table(target) => {
write_dot_separated_list(
f,
target
.catalog
.iter()
.chain(&target.database)
.chain(Some(&target.table)),
)?;
}
VacuumTarget::All => {
write!(f, " ALL")?;
}
}
write!(f, " {}", &self.option)?;

Ok(())
Expand Down
34 changes: 27 additions & 7 deletions src/query/ast/src/parser/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1163,13 +1163,28 @@ pub fn statement_body(i: Input) -> IResult<Statement> {
},
|(_, _, (catalog, database, table), option)| {
Statement::VacuumTable(VacuumTableStmt {
catalog,
database,
table,
target: VacuumTarget::Table(VacuumTargetTable {
catalog,
database,
table,
}),
option,
})
},
);

let vacuum_all_table = map(
rule! {
VACUUM ~ TABLE ~ ALL ~ #vacuum_table_option
},
|(_, _, _, option)| {
Statement::VacuumTable(VacuumTableStmt {
target: VacuumTarget::All,
option,
})
},
);

let vacuum_drop_table = map(
rule! {
VACUUM ~ DROP ~ TABLE ~ (FROM ~ ^#dot_separated_idents_1_to_2)? ~ #vacuum_drop_table_option
Expand All @@ -1186,6 +1201,7 @@ pub fn statement_body(i: Input) -> IResult<Statement> {
})
},
);

let analyze_table = map(
rule! {
ANALYZE ~ TABLE ~ #dot_separated_idents_1_to_3 ~ NOSCAN?
Expand Down Expand Up @@ -2572,7 +2588,6 @@ pub fn statement_body(i: Input) -> IResult<Statement> {
| #show_indexes : "`SHOW INDEXES`"
| #show_locks : "`SHOW LOCKS [IN ACCOUNT] [WHERE ...]`"
| #kill_stmt : "`KILL (QUERY | CONNECTION) <object_id>`"
| #vacuum_temp_files : "VACUUM TEMPORARY FILES [RETAIN number SECONDS|DAYS] [LIMIT number]"
| #set_priority: "`SET PRIORITY (HIGH | MEDIUM | LOW) <object_id>`"
| #system_action: "`SYSTEM (ENABLE | DISABLE) EXCEPTION_BACKTRACE`"
),
Expand Down Expand Up @@ -2676,8 +2691,6 @@ pub fn statement_body(i: Input) -> IResult<Statement> {
| #rename_table : "`RENAME TABLE [<database>.]<table> TO <new_table>`"
| #truncate_table : "`TRUNCATE TABLE [<database>.]<table>`"
| #optimize_table : "`OPTIMIZE TABLE [<database>.]<table> (ALL | PURGE | COMPACT [SEGMENT])`"
| #vacuum_table : "`VACUUM TABLE [<database>.]<table> [RETAIN number HOURS] [DRY RUN | DRY RUN SUMMARY]`"
| #vacuum_drop_table : "`VACUUM DROP TABLE [FROM [<catalog>.]<database>] [RETAIN number HOURS] [DRY RUN | DRY RUN SUMMARY]`"
| #analyze_table : "`ANALYZE TABLE [<database>.]<table>`"
| #exists_table : "`EXISTS TABLE [<database>.]<table>`"
| #show_table_functions : "`SHOW TABLE_FUNCTIONS [<show_limit>]`"
Expand Down Expand Up @@ -2801,7 +2814,14 @@ AS
| #call_procedure : "`CALL PROCEDURE <procedure_name>()`"
),
rule!(#comment),
rule!(#vacuum_temporary_tables),
// Vacuum
rule!(
#vacuum_temporary_tables
| #vacuum_temp_files : "VACUUM TEMPORARY FILES [RETAIN number SECONDS|DAYS] [LIMIT number]"
| #vacuum_table : "`VACUUM TABLE [<database>.]<table> [DRY RUN | DRY RUN SUMMARY]`"
| #vacuum_all_table : "`VACUUM TABLE ALL [DRY RUN | DRY RUN SUMMARY]`"
| #vacuum_drop_table : "`VACUUM DROP TABLE [FROM [<catalog>.]<database>] [RETAIN number HOURS] [DRY RUN | DRY RUN SUMMARY]`"
),
))(i)
}

Expand Down
72 changes: 42 additions & 30 deletions src/query/ast/tests/it/testdata/stmt.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15459,16 +15459,20 @@ VACUUM TABLE t
---------- AST ------------
VacuumTable(
VacuumTableStmt {
catalog: None,
database: None,
table: Identifier {
span: Some(
13..14,
),
name: "t",
quote: None,
ident_type: None,
},
target: Table(
VacuumTargetTable {
catalog: None,
database: None,
table: Identifier {
span: Some(
13..14,
),
name: "t",
quote: None,
ident_type: None,
},
},
),
option: VacuumTableOption {
dry_run: None,
},
Expand All @@ -15483,16 +15487,20 @@ VACUUM TABLE t DRY RUN
---------- AST ------------
VacuumTable(
VacuumTableStmt {
catalog: None,
database: None,
table: Identifier {
span: Some(
13..14,
),
name: "t",
quote: None,
ident_type: None,
},
target: Table(
VacuumTargetTable {
catalog: None,
database: None,
table: Identifier {
span: Some(
13..14,
),
name: "t",
quote: None,
ident_type: None,
},
},
),
option: VacuumTableOption {
dry_run: Some(
false,
Expand All @@ -15509,16 +15517,20 @@ VACUUM TABLE t DRY RUN SUMMARY
---------- AST ------------
VacuumTable(
VacuumTableStmt {
catalog: None,
database: None,
table: Identifier {
span: Some(
13..14,
),
name: "t",
quote: None,
ident_type: None,
},
target: Table(
VacuumTargetTable {
catalog: None,
database: None,
table: Identifier {
span: Some(
13..14,
),
name: "t",
quote: None,
ident_type: None,
},
},
),
option: VacuumTableOption {
dry_run: Some(
true,
Expand Down
1 change: 1 addition & 0 deletions src/query/ee/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ uuid = { workspace = true }

[dev-dependencies]
databend-common-functions = { workspace = true }
goldenfile = { workspace = true }
jsonb = { workspace = true }
tantivy = { workspace = true }
walkdir = { workspace = true }
Expand Down
Loading