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(db2): release locks between query pages

t8y2f8fb682aefce
diff --git a/crates/dbx-sql-data/src/query_result_sql.rs b/crates/dbx-sql-data/src/query_result_sql.rs
index ce8c1f33e4..76d5575b35 100644
--- a/crates/dbx-sql-data/src/query_result_sql.rs
+++ b/crates/dbx-sql-data/src/query_result_sql.rs
@@ -197,14 +197,14 @@ pub fn build_query_pagination_execution_plan(
}
let can_use_first_page_cursor = options.use_agent_cursor && options.pagination.offset == 0;
- // HighGo, OceanBase Oracle, and Xugu can spend substantially more time
+ // DB2, HighGo, OceanBase Oracle, and Xugu can spend substantially more time
// executing an unbounded query before the Agent exposes its first cursor
// page. Prefer a bounded SQL query whenever it can be rewritten safely.
// Independent pages of an unordered query do not have a stable row order;
// callers should add ORDER BY when that matters.
// Kingbase keeps the cursor for unordered queries to preserve its behavior.
let prefer_server_pagination = match options.database_type {
- Some(DatabaseType::Highgo | DatabaseType::OceanbaseOracle | DatabaseType::Xugu) => true,
+ Some(DatabaseType::Db2 | DatabaseType::Highgo | DatabaseType::OceanbaseOracle | DatabaseType::Xugu) => true,
Some(DatabaseType::Kingbase) => kingbase_server_pagination_is_stable(&options.query_base_sql),
_ => false,
};
@@ -5109,6 +5109,53 @@ WHERE u.id = picked.id;
assert!(!second_page.use_agent_result_session);
}
+ #[test]
+ fn db2_prefers_server_pagination_over_agent_cursor() {
+ let first_page = build_query_pagination_execution_plan(QueryPaginationExecutionPlanOptions {
+ sql: "SELECT * FROM events".to_string(),
+ query_base_sql: "SELECT * FROM events".to_string(),
+ database_type: Some(DatabaseType::Db2),
+ pagination: QueryPagination { limit: 500, offset: 0, session_id: None },
+ use_agent_cursor: true,
+ first_page_uses_actual_sql: false,
+ });
+
+ assert_eq!(first_page.sql_to_execute, "SELECT * FROM events FETCH FIRST 500 ROWS ONLY;");
+ assert_eq!(first_page.page_sql, Some(first_page.sql_to_execute.clone()));
+ assert_eq!(first_page.page_limit, Some(500));
+ assert_eq!(first_page.page_offset, Some(0));
+ assert!(!first_page.use_agent_result_session);
+
+ let second_page = build_query_pagination_execution_plan(QueryPaginationExecutionPlanOptions {
+ sql: "SELECT * FROM events".to_string(),
+ query_base_sql: "SELECT * FROM events".to_string(),
+ database_type: Some(DatabaseType::Db2),
+ pagination: QueryPagination { limit: 500, offset: 500, session_id: None },
+ use_agent_cursor: true,
+ first_page_uses_actual_sql: false,
+ });
+
+ assert_eq!(second_page.sql_to_execute, "SELECT * FROM events OFFSET 500 ROWS FETCH FIRST 500 ROWS ONLY;");
+ assert_eq!(second_page.page_sql, Some(second_page.sql_to_execute.clone()));
+ assert_eq!(second_page.page_limit, Some(500));
+ assert_eq!(second_page.page_offset, Some(500));
+ assert!(!second_page.use_agent_result_session);
+
+ let sql = "SELECT * FROM events; SELECT 1";
+ let fallback = build_query_pagination_execution_plan(QueryPaginationExecutionPlanOptions {
+ sql: sql.to_string(),
+ query_base_sql: sql.to_string(),
+ database_type: Some(DatabaseType::Db2),
+ pagination: QueryPagination { limit: 500, offset: 0, session_id: None },
+ use_agent_cursor: true,
+ first_page_uses_actual_sql: false,
+ });
+
+ assert_eq!(fallback.sql_to_execute, sql);
+ assert!(fallback.page_sql.is_none());
+ assert!(fallback.use_agent_result_session);
+ }
+
#[test]
fn xugu_prefers_server_pagination_over_agent_cursor() {
let first_page = build_query_pagination_execution_plan(QueryPaginationExecutionPlanOptions {