From db000516322365d00747ba6f71a7d76f94556cce Mon Sep 17 00:00:00 2001 From: t8y2 <1156263951@qq.com> Date: Mon, 25 May 2026 18:04:50 +0800 Subject: [PATCH] fix: avoid creating session pool without database context for Doris/StarRocks When database is empty, get_or_create_pool_for_session would create a new pool via metadata_connection_config, which clears the database for Doris and StarRocks (is_metadata_connection_scoped). The resulting connection URL had no database path, causing "Current database is not selected" errors on query execution. Fall back to the shared pool (get_or_create_pool) when database is empty, matching the 0.5.19 behavior. Session-scoped pools are still used when a database is explicitly set. --- crates/dbx-core/src/query.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/crates/dbx-core/src/query.rs b/crates/dbx-core/src/query.rs index bd89d47028..d4d2a3f0cf 100644 --- a/crates/dbx-core/src/query.rs +++ b/crates/dbx-core/src/query.rs @@ -602,8 +602,12 @@ pub async fn execute_sql_statement_with_options( cancel_token: Option, options: QueryExecutionOptions, ) -> Result { + // When database is not set, fall back to the shared (non-session-scoped) pool + // to avoid creating a connection without a default database context. + // This is particularly important for Doris/StarRocks, where metadata connections + // omit the database and would cause "Current database is not selected" errors. let pool_key = if database.is_empty() { - state.get_or_create_pool_for_session(connection_id, None, options.client_session_id.as_deref()).await? + state.get_or_create_pool(connection_id, None).await? } else { state .get_or_create_pool_for_session(connection_id, Some(database), options.client_session_id.as_deref()) @@ -619,8 +623,11 @@ pub async fn execute_sql_statement_with_options( match &result { Err(e) if is_connection_error(e) && !is_canceled(&cancel_token) => { let db_opt = if database.is_empty() { None } else { Some(database) }; - let new_key = - state.reconnect_pool_for_session(connection_id, db_opt, options.client_session_id.as_deref()).await?; + let new_key = if database.is_empty() { + state.reconnect_pool(connection_id, db_opt).await? + } else { + state.reconnect_pool_for_session(connection_id, db_opt, options.client_session_id.as_deref()).await? + }; do_execute(state, &new_key, Some(database), sql, schema, cancel_token, options).await } _ => result, @@ -635,7 +642,7 @@ pub async fn close_query_session( client_session_id: Option<&str>, ) -> Result { let pool_key = if database.is_empty() { - state.get_or_create_pool_for_session(connection_id, None, client_session_id).await? + state.get_or_create_pool(connection_id, None).await? } else { state.get_or_create_pool_for_session(connection_id, Some(database), client_session_id).await? }; @@ -683,7 +690,7 @@ pub async fn execute_multi_core_with_options( options: QueryExecutionOptions, ) -> Result, String> { let pool_key = if database.is_empty() { - state.get_or_create_pool_for_session(connection_id, None, options.client_session_id.as_deref()).await? + state.get_or_create_pool(connection_id, None).await? } else { state .get_or_create_pool_for_session(connection_id, Some(database), options.client_session_id.as_deref())