feat: support mysql flavor show processlist shortcut (#6328) (#6379)

* feat: support mysql flavor show processlist shortcut (#6328)

Signed-off-by: codephage. <381510760@qq.com>

* Refactor SHOW PROCESSLIST handling and add tests

Signed-off-by: codephage. <381510760@qq.com>

* add sqlness test

Signed-off-by: codephage. <381510760@qq.com>

* add sqlness test result

Signed-off-by: codephage. <381510760@qq.com>

* fix sqlness test show_processList

Signed-off-by: codephage. <381510760@qq.com>

---------

Signed-off-by: codephage. <381510760@qq.com>
This commit is contained in:
codephage
2025-06-24 11:50:16 +08:00
committed by GitHub
parent 90a3894564
commit 116d5cf82b
11 changed files with 169 additions and 20 deletions

View File

@@ -25,8 +25,8 @@ use crate::error::{
use crate::parser::ParserContext;
use crate::statements::show::{
ShowColumns, ShowCreateDatabase, ShowCreateFlow, ShowCreateTable, ShowCreateTableVariant,
ShowCreateView, ShowDatabases, ShowFlows, ShowIndex, ShowKind, ShowRegion, ShowSearchPath,
ShowStatus, ShowTableStatus, ShowTables, ShowVariables, ShowViews,
ShowCreateView, ShowDatabases, ShowFlows, ShowIndex, ShowKind, ShowProcessList, ShowRegion,
ShowSearchPath, ShowStatus, ShowTableStatus, ShowTables, ShowVariables, ShowViews,
};
use crate::statements::statement::Statement;
@@ -104,6 +104,8 @@ impl ParserContext<'_> {
self.parse_show_columns(true)
} else if self.consume_token("DATABASES") || self.consume_token("SCHEMAS") {
self.parse_show_databases(true)
} else if self.consume_token("PROCESSLIST") {
self.parse_show_processlist(true)
} else {
self.unsupported(self.peek_token_as_string())
}
@@ -119,6 +121,8 @@ impl ParserContext<'_> {
Ok(Statement::ShowStatus(ShowStatus {}))
} else if self.consume_token("SEARCH_PATH") {
Ok(Statement::ShowSearchPath(ShowSearchPath {}))
} else if self.consume_token("PROCESSLIST") {
self.parse_show_processlist(false)
} else {
self.unsupported(self.peek_token_as_string())
}
@@ -571,6 +575,15 @@ impl ParserContext<'_> {
Ok(Statement::ShowFlows(ShowFlows { kind, database }))
}
fn parse_show_processlist(&mut self, full: bool) -> Result<Statement> {
match self.parser.next_token().token {
Token::EOF | Token::SemiColon => {
Ok(Statement::ShowProcesslist(ShowProcessList { full }))
}
_ => self.unsupported(self.peek_token_as_string()),
}
}
}
#[cfg(test)]
@@ -1212,4 +1225,29 @@ mod tests {
);
assert_eq!(sql, stmts[0].to_string());
}
#[test]
pub fn test_show_processlist() {
let sql = "SHOW PROCESSLIST";
let result =
ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}, ParseOptions::default());
let stmts = result.unwrap();
assert_eq!(1, stmts.len());
assert_eq!(
stmts[0],
Statement::ShowProcesslist(ShowProcessList { full: false })
);
assert_eq!(sql, stmts[0].to_string());
let sql = "SHOW FULL PROCESSLIST";
let result =
ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}, ParseOptions::default());
let stmts = result.unwrap();
assert_eq!(1, stmts.len());
assert_eq!(
stmts[0],
Statement::ShowProcesslist(ShowProcessList { full: true })
);
assert_eq!(sql, stmts[0].to_string());
}
}

View File

@@ -321,6 +321,23 @@ impl Display for ShowSearchPath {
}
}
/// SQL structure for `SHOW PROCESSLIST`.
#[derive(Debug, Clone, PartialEq, Eq, Visit, VisitMut, Serialize)]
pub struct ShowProcessList {
pub full: bool,
}
impl Display for ShowProcessList {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if self.full {
write!(f, "SHOW FULL PROCESSLIST")?;
} else {
write!(f, "SHOW PROCESSLIST")?;
}
Ok(())
}
}
#[cfg(test)]
mod tests {
use std::assert_matches::assert_matches;

View File

@@ -37,8 +37,8 @@ use crate::statements::query::Query;
use crate::statements::set_variables::SetVariables;
use crate::statements::show::{
ShowColumns, ShowCreateDatabase, ShowCreateFlow, ShowCreateTable, ShowCreateView,
ShowDatabases, ShowFlows, ShowIndex, ShowKind, ShowRegion, ShowSearchPath, ShowStatus,
ShowTableStatus, ShowTables, ShowVariables, ShowViews,
ShowDatabases, ShowFlows, ShowIndex, ShowKind, ShowProcessList, ShowRegion, ShowSearchPath,
ShowStatus, ShowTableStatus, ShowTables, ShowVariables, ShowViews,
};
use crate::statements::tql::Tql;
use crate::statements::truncate::TruncateTable;
@@ -141,6 +141,8 @@ pub enum Statement {
CloseCursor(CloseCursor),
// KILL <process>
Kill(Kill),
// SHOW PROCESSLIST
ShowProcesslist(ShowProcessList),
}
impl Display for Statement {
@@ -198,6 +200,7 @@ impl Display for Statement {
Statement::FetchCursor(s) => s.fmt(f),
Statement::CloseCursor(s) => s.fmt(f),
Statement::Kill(k) => k.fmt(f),
Statement::ShowProcesslist(s) => s.fmt(f),
}
}
}