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:
parent
ce72468e5a
commit
d3272b4750
|
|
@ -1652,17 +1652,30 @@ async fn postgres_proc_has_prokind(client: &deadpool_postgres::Client) -> Result
|
|||
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> {
|
||||
let client = checkout_postgres_client(pool, None, super::connection_timeout()).await?;
|
||||
let has_proc_prokind = postgres_proc_has_prokind(&client).await?;
|
||||
let sql = list_objects_sql(true, has_proc_prokind);
|
||||
let stmt = client.prepare_cached(&sql).await.map_err(|e| e.to_string())?;
|
||||
let rows = match client.query(&stmt, &[&schema]).await {
|
||||
let rows = match list_objects_rows(&client, schema, true, has_proc_prokind).await {
|
||||
Ok(rows) => rows,
|
||||
Err(_) => {
|
||||
let fallback_sql = list_objects_sql(false, has_proc_prokind);
|
||||
let stmt = client.prepare_cached(&fallback_sql).await.map_err(|e| e.to_string())?;
|
||||
client.query(&stmt, &[&schema]).await.map_err(|e| e.to_string())?
|
||||
Err(primary_error) => {
|
||||
log::debug!("[postgres][list_objects:timestamp-fallback] primary_error={}", primary_error);
|
||||
match list_objects_rows(&client, schema, false, has_proc_prokind).await {
|
||||
Ok(rows) => rows,
|
||||
Err(fallback_error) => {
|
||||
return Err(format!("{primary_error}; timestamp fallback failed: {fallback_error}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue