Pull Request已成功合入, 合并人@opengauss_bot
(感谢 zjj_sc 的贡献)openGauss pipeline is running. Please wait a moment...


Welcome To openGauss Community
Hey @m0_57849461 , thanks for your contribution to the community.
Bot Usage Manual
I'm the Bot here serving you. You can find the instructions on how to interact with me at Here . That means you can comment below every pull request or issue to trigger Bot Commands. You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
Contact Guide
If you have any questions, please contact the SIG: StorageEngine, AI, CM, CloudNative, SecurityTechnology, SQLEngine ,
and any of the maintainers: @CarrotGo, @chendong76, @chenxiaobin19, @congzhou2603, @dodders, @hwworkholic, @jemappellehc, @muyulinzhong, @quemingjian, @shenzheng4, @shirley_zhengx, @superlchf, @totaj, @wlff234, @wofanzheng, @ywzq1161327784 ,
and any of the committers: @Igali, @bihua111, @cailei19, @h_ray, @levy53071, @libiao2024, @lihaixiao, @mrzack, @wangfeihuo, @wuyuechuan, @xiong_xjun, @zhangfengzhi123, @zhangxubo, @zhangzq131, @zjh_hw .


【标题】
修复 EXPLAIN VERBOSE 反解析被优化掉的 RECORD 子查询时报错
【实现内容】:
EXPLAIN VERBOSE生成执行计划文本时,反解析 RECORD 字段可能报错的问题。RTE_SUBQUERY和RTE_CTE场景下,当对应的inner_planstate不存在时,使用f1、f2等默认字段名作为兜底。ruleutils_record回归测试,并加入单节点和多节点回归测试调度。【根因分析】:
当子查询或 CTE 被优化器证明结果恒为空时,原执行节点可能被优化成没有子节点的
Result。在执行EXPLAIN VERBOSE时,get_name_for_var_field()需要通过inner_planstate恢复匿名 RECORD 的真实字段名。由于对应子计划已经被优化掉,
inner_planstate为NULL,原有代码会直接抛出failed to find plan for subquery或failed to find plan for CTE,导致 SQL 本身能够正常规划,但无法生成执行计划文本。详见文章:https://mp.weixin.qq.com/s/Y5PsLdxDmvoDPHZI0jQqag【实现方案】:
参考 PostgreSQL 上游 修复方案https://www.postgresql.org/message-id/18576-9feac34e132fea9e@postgresql.org ,在无法从计划树恢复真实 RECORD 字段名时,按照 RowExpr 默认字段命名规则回退为
fN:palloc分配字段名内存。snprintf_s生成f1、f2等字段名,并通过securec_check_ss检查结果。RTE_SUBQUERY和RTE_CTE分支。PlanState、向量化及扩展执行节点的兼容性,不引入上游新版本的 Plan 类型断言。information_schema.parameters构造稳定复现,验证修复后执行计划输出((ss.x).f2),定向回归测试通过。上游参考提交:https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=b919a97a6c 、https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=7408772de5 。
【关联需求或issue】:
#8424
【开发自验报告】:
【当前PR是否有AI参与】:
[x] 否
[ ] 是
__1. AI Agent 平台:
__2. AI 模型:
__3. Prompt上下文 :
【其他说明】: