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。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
perf(gaussdb): skip doomed modern metadata tier
Xsyl.way326ee4f96d8b
diff --git a/crates/dbx-core/src/schema/mod.rs b/crates/dbx-core/src/schema/mod.rsindex 450f18aac1..02b27a337e 100644--- a/crates/dbx-core/src/schema/mod.rs+++ b/crates/dbx-core/src/schema/mod.rs@@ -8446,6 +8446,12 @@ async fn get_columns_core_for_session_inner_with_pool({db::postgres::get_redshift_columns(p, schema, table).await.map(deduplicate_column_infos)}+ // GaussDB / openGauss kernels cannot run the modern catalog tier, so+ // skip the destined-to-fail probe instead of paying it per relation+ // (issue #12324).+ PoolKind::Postgres(p) if db_config.as_ref().is_some_and(is_opengauss_family_config) => {+ db::postgres::get_columns_compat_first(p, schema, table).await.map(deduplicate_column_infos)+ }PoolKind::Postgres(p) => db::postgres::get_columns(p, schema, table).await.map(deduplicate_column_infos),PoolKind::Sqlite(p) => db::sqlite::get_columns(p, schema, table).await.map(deduplicate_column_infos),PoolKind::Rqlite(client) => {@@ -8733,6 +8739,10 @@ async fn list_indexes_core_for_session({Ok(vec![])}+ // See `get_columns`: GaussDB / openGauss skip the modern index tier.+ PoolKind::Postgres(p) if db_config.as_ref().is_some_and(is_opengauss_family_config) => {+ db::postgres::list_indexes_compat_first(p, schema, table).await+ }PoolKind::Postgres(p) => db::postgres::list_indexes(p, schema, table).await,PoolKind::Sqlite(p) => db::sqlite::list_indexes(p, schema, table).await,PoolKind::Rqlite(client) => db::rqlite_driver::list_indexes(client, schema, table).await,diff --git a/crates/dbx-driver-postgres/src/postgres.rs b/crates/dbx-driver-postgres/src/postgres.rsindex 79bbb81c35..3e35b9d3fd 100644--- a/crates/dbx-driver-postgres/src/postgres.rs+++ b/crates/dbx-driver-postgres/src/postgres.rs@@ -8297,7 +8297,40 @@ async fn get_columns_with_sql(Ok(rows.iter().map(column_info_from_row).collect())}+/// Catalog tiers a server can actually execute for column metadata.+///+/// GaussDB and openGauss kernels do not implement `pg_sequence`,+/// `attgenerated` or `LATERAL`, so the modern `primary` probe fails on every+/// relation and only adds a round trip before the compat tier succeeds+/// (issue #12324). Those servers start at the compat tier instead.+fn column_metadata_tiers(modern_tier_supported: bool) -> Vec<(&'static str, &'static str)> {+ if modern_tier_supported {+ vec![+ ("primary", POSTGRES_COLUMNS_SQL),+ ("compat", POSTGRES_COLUMNS_COMPAT_SQL),+ ("information_schema", POSTGRES_COLUMNS_INFORMATION_SCHEMA_SQL),+ ]+ } else {+ vec![("compat", POSTGRES_COLUMNS_COMPAT_SQL), ("information_schema", POSTGRES_COLUMNS_INFORMATION_SCHEMA_SQL)]+ }+}+pub async fn get_columns(pool: &Pool, schema: &str, table: &str) -> Result<Vec<ColumnInfo>, String> {+ get_columns_with_tiers(pool, schema, table, true).await+}++/// [`get_columns`] for GaussDB / openGauss, whose kernel cannot run the modern+/// tier: the doomed probe is skipped instead of paid per relation.+pub async fn get_columns_compat_first(pool: &Pool, schema: &str, table: &str) -> Result<Vec<ColumnInfo>, String> {+ get_columns_with_tiers(pool, schema, table, false).await+}++async fn get_columns_with_tiers(+ pool: &Pool,+ schema: &str,+ table: &str,+ modern_tier_supported: bool,+) -> Result<Vec<ColumnInfo>, String> {let diagnostics_enabled = log::log_enabled!(log::Level::Debug);let total_started = diagnostics_enabled.then(Instant::now);let client = match checkout_postgres_client(pool, None, super::connection_timeout()).await {@@ -8313,11 +8346,7 @@ pub async fn get_columns(pool: &Pool, schema: &str, table: &str) -> Result<Vec<Creturn Err(error);}};- let tiers = [- ("primary", POSTGRES_COLUMNS_SQL),- ("compat", POSTGRES_COLUMNS_COMPAT_SQL),- ("information_schema", POSTGRES_COLUMNS_INFORMATION_SCHEMA_SQL),- ];+ let tiers = column_metadata_tiers(modern_tier_supported);query_with_column_metadata_fallback(&tiers,|sql| get_columns_with_sql(&client, sql, schema, table),@@ -9849,10 +9878,33 @@ async fn list_indexes_with_sql(.collect())}+/// Index catalog tiers, mirroring [`column_metadata_tiers`].+fn index_metadata_tiers(modern_tier_supported: bool) -> Vec<&'static str> {+ if modern_tier_supported {+ vec![POSTGRES_INDEXES_SQL, POSTGRES_INDEXES_COMPAT_SQL]+ } else {+ vec![POSTGRES_INDEXES_COMPAT_SQL]+ }+}+pub async fn list_indexes(pool: &Pool, schema: &str, table: &str) -> Result<Vec<IndexInfo>, String> {+ list_indexes_with_tiers(pool, schema, table, true).await+}++/// [`list_indexes`] for GaussDB / openGauss (skip the doomed modern probe).+pub async fn list_indexes_compat_first(pool: &Pool, schema: &str, table: &str) -> Result<Vec<IndexInfo>, String> {+ list_indexes_with_tiers(pool, schema, table, false).await+}++async fn list_indexes_with_tiers(+ pool: &Pool,+ schema: &str,+ table: &str,+ modern_tier_supported: bool,+) -> Result<Vec<IndexInfo>, String> {let client = checkout_postgres_client(pool, None, super::connection_timeout()).await?;let client = &EncodingClient::new(&client);- let tiers = [POSTGRES_INDEXES_SQL, POSTGRES_INDEXES_COMPAT_SQL];+ let tiers = index_metadata_tiers(modern_tier_supported);query_with_compat_fallback("list_indexes", &tiers, |sql| list_indexes_with_sql(client, sql, schema, table)).await}@@ -14799,6 +14851,30 @@ mod tests {));}+ #[test]+ fn gaussdb_column_tiers_skip_the_modern_probe() {+ let modern = column_metadata_tiers(true);+ assert_eq!(+ modern.iter().map(|(tier, _)| *tier).collect::<Vec<_>>(),+ vec!["primary", "compat", "information_schema"]+ );++ // GaussDB / openGauss cannot execute the modern tier, so the doomed+ // probe must not be attempted at all (issue #12324).+ let compat_first = column_metadata_tiers(false);+ assert_eq!(+ compat_first.iter().map(|(tier, _)| *tier).collect::<Vec<_>>(),+ vec!["compat", "information_schema"]+ );+ assert_eq!(compat_first[0].1, POSTGRES_COLUMNS_COMPAT_SQL);+ }++ #[test]+ fn gaussdb_index_tiers_skip_the_modern_probe() {+ assert_eq!(index_metadata_tiers(true), vec![POSTGRES_INDEXES_SQL, POSTGRES_INDEXES_COMPAT_SQL]);+ assert_eq!(index_metadata_tiers(false), vec![POSTGRES_INDEXES_COMPAT_SQL]);+ }+#[tokio::test]async fn get_columns_tier_diagnostics_preserve_empty_fallback_result() {let tiers = [("primary", "primary-sql"), ("compat", "compat-sql"), ("information_schema", "info-sql")];