fix(postgres): 修复 GaussDB Schema 浏览对象报错 (#2186)

- GaussDB 复用 PostgreSQL 对象浏览查询,但带时间戳的元数据 SQL 依赖 pg_stat_file、pg_xact_commit_timestamp 等函数,在 prepare 阶段失败,导致原有 fallback 无法触发。
- 让 fallback 覆盖 prepare 和 query 阶段。查询失败时降级到无时间戳查询,保证表、视图、函数、序列仍可正常展示。
This commit is contained in:
weihan authored and GitHub committed 2026-06-30 20:06:23 +08:00
1 parent ce72468e5a
commit d3272b4750
1 file changed
+20 -7
+20 -7
View File
@@ -1652,17 +1652,30 @@ async fn postgres_proc_has_prokind(client: &deadpool_postgres::Client) -> Result
Ok(row.get(0)) Ok(row.get(0))
} }
async fn list_objects_rows(
client: &deadpool_postgres::Client,
schema: &str,
include_timestamps: bool,
has_proc_prokind: bool,
) -> Result<Vec<Row>, String> {
let sql = list_objects_sql(include_timestamps, has_proc_prokind);
let stmt = client.prepare_cached(&sql).await.map_err(|e| e.to_string())?;
client.query(&stmt, &[&schema]).await.map_err(|e| e.to_string())
}
pub async fn list_objects(pool: &Pool, schema: &str) -> Result<Vec<ObjectInfo>, String> { pub async fn list_objects(pool: &Pool, schema: &str) -> Result<Vec<ObjectInfo>, String> {
let client = checkout_postgres_client(pool, None, super::connection_timeout()).await?; let client = checkout_postgres_client(pool, None, super::connection_timeout()).await?;
let has_proc_prokind = postgres_proc_has_prokind(&client).await?; let has_proc_prokind = postgres_proc_has_prokind(&client).await?;
let sql = list_objects_sql(true, has_proc_prokind); let rows = match list_objects_rows(&client, schema, true, has_proc_prokind).await {
let stmt = client.prepare_cached(&sql).await.map_err(|e| e.to_string())?;
let rows = match client.query(&stmt, &[&schema]).await {
Ok(rows) => rows, Ok(rows) => rows,
Err(_) => { Err(primary_error) => {
let fallback_sql = list_objects_sql(false, has_proc_prokind); log::debug!("[postgres][list_objects:timestamp-fallback] primary_error={}", primary_error);
let stmt = client.prepare_cached(&fallback_sql).await.map_err(|e| e.to_string())?; match list_objects_rows(&client, schema, false, has_proc_prokind).await {
client.query(&stmt, &[&schema]).await.map_err(|e| e.to_string())? Ok(rows) => rows,
Err(fallback_error) => {
return Err(format!("{primary_error}; timestamp fallback failed: {fallback_error}"));
}
}
} }
}; };