arXiv:2605.28557cs.LOcs.AI2026-05被引 3

优化大模型迁移Oracle到PostgreSQL的令牌消耗,提升效率与准确性。

Token Optimization Strategies for LLM-Based Oracle-to-PostgreSQL Migration

  • 提出12种令牌优化策略,从上下文压缩到结构重写
  • 自适应路由降低8.72%输入、5.49%输出令牌,保持88.40%语义匹配
  • 强调优化需平衡成本、语法正确性与语义保真度

大模型在软件现代化、代码翻译和数据库迁移中应用日益广泛。然而,基于大模型的Oracle到PostgreSQL迁移仍受限于高令牌消耗、长上下文退化、方言语义差异及查询转换中的语义漂移风险。直接将大型Oracle SQL/PL-SQL代码、模式定义、过程逻辑和迁移指令纳入模型上下文会增加成本并降低生成质量。本文将令牌优化视为大模型迁移中的约束转化问题,形式化并评估了十二种策略:基线表示、上下文剪枝、精简、基于领域语言的语义压缩、元数据增强、上下文重构、模式提炼、自适应路由、基于抽象语法树的精简、标识符掩码、输出约束强化及混合优化。在10个和100个Oracle SQL查询样本上,使用有效语法率、精确匹配、语义匹配、CodeBLEU和令牌效率进行评估。结果表明,适度上下文剪枝可近乎保持基线语义质量,100个查询样本下语义匹配达89.75%,仅比基线(89.80%)略低。自适应路由表现最佳,输入令牌减少8.72%,输出令牌减少5.49%,维持88.40%语义匹配,并提升6.67%令牌效率。激进的模式提炼使令牌效率提升132.22%,但语义匹配下降44.50个百分点。研究证实,令牌优化不能简单视为提示缩短,而需作为多目标迁移问题,权衡成本、语法有效性、语义保留与结构保真度。

原文摘要 · Abstract (English)

LLMs are increasingly used for software modernization, code translation, and database migration. However, LLM-based Oracle2PostgreSQL migration remains constrained by high token consumption, long-context degradation, dialect-specific semantic differences, and the risk of semantic drift during query transformation. Direct inclusion of large Oracle SQL/PL-SQL artefacts, schema definitions, procedural logic, and migration instructions into the model context increases cost and may reduce generation quality. This paper shows token optimization as a constrained transformation problem in LLM-based Oracle2PostgreSQL migration. The study formalizes and evaluates twelve token optimization strategies: baseline representation, context pruning, minification, DSL-based semantic compression, metadata augmentation, context refactoring, schema distillation, adaptive routing, AST-based minification, identifier masking, output constraint enforcement, and hybrid optimization. The strategies are evaluated on samples of 10 and 100 Oracle SQL queries using Valid Syntax Rate, Exact Match, Semantic Match, CodeBLEU, and Token Efficiency. The results show that mild context pruning preserves semantic quality almost at the baseline level, achieving 89.75% Semantic Match on the 100-query sample compared with 89.80% for the unoptimized baseline. Adaptive routing provides the best practical trade-off, reducing input tokens by 8.72% and output tokens by 5.49% while maintaining 88.40% Semantic Match and increasing Token Efficiency by 6.67%. Aggressive schema distillation increases Token Efficiency by 132.22% but results in a 44.50-percentage-point decrease in Semantic Match. The findings demonstrate that token optimization cannot be treated as simple prompt shortening; it must be evaluated as a multi-objective migration problem balancing cost, syntactic validity, semantic preservation, and structural fidelity.

大模型迁移令牌优化数据库SQL转换

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。