ChatPaper.aiChatPaper

運用大型語言模型實現數據庫原生函數代碼的自動生成

Automating Database-Native Function Code Synthesis with LLMs

April 2, 2026
作者: Wei Zhou, Xuanhe Zhou, Qikang He, Guoliang Li, Bingsheng He, Quanqing Xu, Fan Wu
cs.AI

摘要

数据库系统为支持新应用场景和业务迁移,其内核持续集成日益增多的原生函数。这种增长催生了对自动化数据库原生函数合成的迫切需求。尽管基于大语言模型的代码生成技术(如Claude Code)近期取得进展,但其通用性难以满足数据库特定开发需求。由于函数合成本身具有高度复杂性和易错性——单个函数的实现可能涉及注册多个功能单元、链接内部引用及正确实现逻辑,通用模型常产生幻觉或忽略关键上下文。为此,我们提出DBCooker,基于大语言模型的数据库原生函数自动合成系统。该系统包含三大组件:首先,函数特征分析模块聚合多源声明,识别需要专门编码的功能单元并追踪跨单元依赖关系;其次,我们设计了三项核心操作应对主要合成挑战:(1)基于伪代码的编码计划生成器,通过识别可复用参考函数等关键元素构建结构化实现框架;(2)融合概率先验与组件感知的混合填空模型,将核心逻辑与可复用例程相集成;(3)包含语法检查、标准符合性验证及大语言模型引导语义核查的三级渐进式验证机制。最后,自适应编排策略将这些操作与现有工具相统一,并依据相似函数的编排历史进行动态调度。实验表明,DBCooker在SQLite、PostgreSQL和DuckDB上均优于其他方法(平均准确率提升34.55%),并能合成最新版SQLite(v3.50)中尚未包含的新函数。
English
Database systems incorporate an ever-growing number of functions in their kernels (a.k.a., database native functions) for scenarios like new application support and business migration. This growth causes an urgent demand for automatic database native function synthesis. While recent advances in LLM-based code generation (e.g., Claude Code) show promise, they are too generic for database-specific development. They often hallucinate or overlook critical context because database function synthesis is inherently complex and error-prone, where synthesizing a single function may involve registering multiple function units, linking internal references, and implementing logic correctly. To this end, we propose DBCooker, an LLM-based system for automatically synthesizing database native functions. It consists of three components. First, the function characterization module aggregates multi-source declarations, identifies function units that require specialized coding, and traces cross-unit dependencies. Second, we design operations to address the main synthesis challenges: (1) a pseudo-code-based coding plan generator that constructs structured implementation skeletons by identifying key elements such as reusable referenced functions; (2) a hybrid fill-in-the-blank model guided by probabilistic priors and component awareness to integrate core logic with reusable routines; and (3) three-level progressive validation, including syntax checking, standards compliance, and LLM-guided semantic verification. Finally, an adaptive orchestration strategy unifies these operations with existing tools and dynamically sequences them via the orchestration history of similar functions. Results show that DBCooker outperforms other methods on SQLite, PostgreSQL, and DuckDB (34.55% higher accuracy on average), and can synthesize new functions absent in the latest SQLite (v3.50).
PDF92April 11, 2026