Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

fix(plugin-plan): resolve Doris profiles to the Doris explain dialect

jearhe84ec5eac7476
diff --git a/crates/dbx-core/src/ai/agent_explain.rs b/crates/dbx-core/src/ai/agent_explain.rs
index e1b2fec74e..c91652b44a 100644
--- a/crates/dbx-core/src/ai/agent_explain.rs
+++ b/crates/dbx-core/src/ai/agent_explain.rs
@@ -74,12 +74,16 @@ pub async fn get_agent_explain_info_core(
decode_agent_explain_result(result)
}
-/// Resolves the dialect an EXPLAIN must be generated for. A custom JDBC
-/// connection is only known to be Oracle when its configuration says so; every
-/// other custom JDBC connection stays `Jdbc` and therefore gets no plan
-/// acquisition. Shared with the plugin Host plan API so both paths agree on
-/// which dialects are treatable.
+/// Resolves the dialect an EXPLAIN must be generated for. Doris' MySQL-based
+/// connection profiles are Doris dialects, not MySQL. A custom JDBC connection
+/// is only known to be Oracle when its configuration says so; every other
+/// custom JDBC connection stays `Jdbc` and therefore gets no plan acquisition.
+/// Shared with the plugin Host plan API so both paths agree on which dialects
+/// are treatable.
pub(crate) fn explain_database_type(config: &ConnectionConfig) -> DatabaseType {
+ if crate::db::doris::is_config(config) {
+ return DatabaseType::Doris;
+ }
if config.db_type != DatabaseType::Jdbc {
return config.db_type;
}
@@ -129,6 +133,7 @@ mod tests {
use crate::plugins::{
InstalledPlugin, PluginDriverManifest, PluginDriverSession, PluginManifest, PluginRuntimeEnv,
};
+ use crate::query_execution_sql::{build_explain_sql, ExplainSqlOptions};
#[cfg(unix)]
use std::sync::Arc;
@@ -153,6 +158,41 @@ mod tests {
assert!(decode_agent_explain_result(serde_json::json!(["unexpected"])).is_err());
}
+ #[test]
+ fn resolves_doris_profiles_to_doris_explain_sql_without_changing_mysql() {
+ let cases = [
+ (DatabaseType::Doris, None, DatabaseType::Doris, "EXPLAIN SELECT 1"),
+ (DatabaseType::Mysql, Some("doris"), DatabaseType::Doris, "EXPLAIN SELECT 1"),
+ (DatabaseType::Mysql, Some("selectdb"), DatabaseType::Doris, "EXPLAIN SELECT 1"),
+ (DatabaseType::Mysql, None, DatabaseType::Mysql, "EXPLAIN FORMAT=JSON SELECT 1"),
+ (DatabaseType::Mysql, Some("mysql"), DatabaseType::Mysql, "EXPLAIN FORMAT=JSON SELECT 1"),
+ ];
+
+ for (raw_type, driver_profile, expected_type, expected_sql) in cases {
+ let config: ConnectionConfig = serde_json::from_value(serde_json::json!({
+ "id": "dialect-test",
+ "name": "Dialect test",
+ "db_type": raw_type.as_str(),
+ "driver_profile": driver_profile,
+ "host": "127.0.0.1",
+ "port": 9030,
+ "username": "user",
+ "password": "secret"
+ }))
+ .unwrap();
+
+ let resolved_type = explain_database_type(&config);
+ assert_eq!(resolved_type, expected_type, "{raw_type:?} + {driver_profile:?}");
+ let explain = build_explain_sql(ExplainSqlOptions {
+ database_type: Some(resolved_type),
+ format: None,
+ analyze: None,
+ sql: "SELECT 1".to_string(),
+ });
+ assert_eq!(explain.sql.as_deref(), Some(expected_sql), "{raw_type:?} + {driver_profile:?}");
+ }
+ }
+
#[test]
fn infers_only_oracle_custom_jdbc_for_oracle_explain_safety() {
let oracle: ConnectionConfig = serde_json::from_value(serde_json::json!({
diff --git a/crates/dbx-core/src/query/plugin_plan.rs b/crates/dbx-core/src/query/plugin_plan.rs
index 230384a539..790ef2c951 100644
--- a/crates/dbx-core/src/query/plugin_plan.rs
+++ b/crates/dbx-core/src/query/plugin_plan.rs
@@ -851,4 +851,17 @@ mod tests {
unsupported_dialect_message(DatabaseType::Redis)
);
}
+
+ #[tokio::test]
+ async fn capabilities_report_doris_for_the_mysql_doris_profile() {
+ let mut doris = config(DatabaseType::Mysql, 30);
+ doris.driver_profile = Some("doris".to_string());
+ let (state, _dir) = saved_connection_state(std::slice::from_ref(&doris)).await;
+ open_connection(&state, &doris.id).await;
+
+ let capabilities = plugin_plan_capabilities(&state, &doris.id).await.unwrap();
+ let capabilities = serde_json::to_value(capabilities).unwrap();
+ assert_eq!(capabilities["dbType"], "doris");
+ assert!(capabilities["supports"]["estimatedPlan"].as_bool().unwrap_or_default());
+ }
}