Skip to content

fix(postgres): 存储过程含 DEFAULT 参数时查看 DDL 报 Object source not found - #8281

Merged
t8y2 merged 1 commit into
t8y2:mainfrom
q396921921:fix/pg-function-default-param-ddl
Sep 6, 2026
Merged

fix(postgres): 存储过程含 DEFAULT 参数时查看 DDL 报 Object source not found#8281
t8y2 merged 1 commit into
t8y2:mainfrom
q396921921:fix/pg-function-default-param-ddl

Conversation

@q396921921

Copy link
Copy Markdown
Contributor

问题

在探测不到 pg_get_function_identity_arguments(真实发生在腾讯 TBase 10.23 等兼容分支)的 PostgreSQL 兼容服务器上,对象列表查询会退回用 pg_get_function_arguments 生成签名——该函数会包含参数的 DEFAULT ... 子句。而查看存储过程/函数 DDL 时无条件用 pg_get_function_identity_arguments 做签名匹配——该函数不包含 DEFAULT 子句。只要routine 带默认参数,两侧签名格式永远对不上,查询返回 0 行,报错 Object source not found

修复

新增 postgres_function_object_source_sql_with_legacy_signature(),构造与对象列表 legacy 兼容模式一致(pg_get_function_arguments)的签名过滤条件;在 postgres_object_source() 中新增一条窄范围 fallback:仅当非 openGauss 家族、类型为 Function/Procedure、带 signature、且主查询恰好报 "Object source not found" 时,用该 legacy 签名查询重试一次。不影响 View/Sequence/Trigger、不影响 openGauss 已有 fallback 链、不影响任何现有成功路径。

复现与验证

共享测试环境是原生 PostgreSQL(探测器返回真,走不到 legacy 分支),本机也没有可用的 TBase 实例,因此复现分两步、均为真实数据库 + 真实运行的应用:

  1. 在真实 PostgreSQL 上创建一个带 DEFAULT 参数的存储过程,验证 pg_get_function_arguments(含 DEFAULT 0)与 pg_get_function_identity_arguments(不含)确实不同——根因坐实。
  2. 用真实运行的 cargo run -p dbx-web 后端 + 真实网络请求,手工传入该库里真实存在的 legacy 格式签名值(模拟探针失败后前端本应传入的值):
  • 修复前:GET /api/schema/object-source?...&signature=IN i_id numeric, IN i_page numeric DEFAULT 0HTTP 500 {"detail":"Object source not found"},与 issue 描述完全一致。
  • 修复后:同一请求 → HTTP 200,正确返回 CREATE OR REPLACE PROCEDURE ... DDL。
  • 回归:不带 signature 的正常路径、以及无默认参数存储过程的正常 identity_arguments 签名路径,均验证仍正常返回,未受影响。
  • cargo test -p dbx-core --lib schema:::184/184 通过(含新增 1 条针对 legacy 签名 SQL 构造的单测)。
  • cargo clippy -p dbx-core --lib -- -D warnings:干净。
  • cargo fmt --check -p dbx-core:改动文件无格式问题。

Fixes #8279

🤖 Generated with Claude Code

Servers without pg_get_function_identity_arguments (e.g. TBase) build
the object list signature with pg_get_function_arguments instead,
which includes DEFAULT clauses. Fetching the DDL always matched with
pg_get_function_identity_arguments (no DEFAULT clauses), so routines
with default-valued parameters always failed with "Object source not
found". Add a narrow fallback that retries with the legacy formatter
when that exact error occurs for a Function/Procedure with a
signature.

Fixes t8y2#8279

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LKS8RLQjueXCwVJov2zWD3
@q396921921

Copy link
Copy Markdown
Contributor Author

复现证据(终端输出,本 bug 为后端 API 逻辑问题,无法通过截图直接验证)

BEFORE(未修复,upstream/main 原始代码)

GET /api/schema/object-source?connection_id=issue8279-pg&database=dbx_test&schema=issue8279
    &table=p_with_default&object_type=PROCEDURE
    &signature=IN i_id numeric, IN i_page numeric DEFAULT 0

{"version":1,"code":"DBX-LEGACY-0001","messageKey":"backendErrors.legacy","messageParams":{},
 "source":"legacyBackend","origin":{"subsystem":"backend","adapter":"legacy"},
 "operationOutcome":"unknown","detail":"Object source not found"}
HTTP:500

AFTER(应用本次修复)

GET /api/schema/object-source?connection_id=issue8279-pg&database=dbx_test&schema=issue8279
    &table=p_with_default&object_type=PROCEDURE
    &signature=IN i_id numeric, IN i_page numeric DEFAULT 0

{"name":"p_with_default","object_type":"PROCEDURE","schema":"issue8279",
 "source":"CREATE OR REPLACE PROCEDURE issue8279.p_with_default(IN i_id numeric, IN i_page numeric DEFAULT 0)\n LANGUAGE plpgsql\nAS $procedure$\nBEGIN\n  NULL;\nEND; $procedure$\n"}
HTTP:200

两次请求针对的是共享测试 PostgreSQL 16.14 上真实创建的存储过程,signature 参数值是该库上 pg_get_function_arguments() 的真实返回值(模拟探测不到 pg_get_function_identity_arguments 的兼容服务器如 TBase 上,对象列表本应产出的签名格式)。

回归验证(AFTER,同一后端):不带 signature 的正常路径、以及无默认参数存储过程的正常 identity_arguments 签名路径,均仍返回 HTTP 200 正确 DDL,未受影响。

@github-actions github-actions Bot added area/core Shared DBX core runtime bug Something isn't working labels Sep 6, 2026
@t8y2
t8y2 merged commit 93a4b58 into t8y2:main Sep 6, 2026
13 of 15 checks passed
@t8y2

t8y2 commented Sep 6, 2026

Copy link
Copy Markdown
Owner

Thanks for the contribution! Merged in 93a4b58, will be released in the next version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Shared DBX core runtime bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] PostgreSQL 存储过程含 DEFAULT 参数时查看 DDL 报 Object source not found

2 participants