基于LLM的Oracle到PostgreSQL迁移的Token优化策略
Token Optimization Strategies for LLM-Based Oracle-to-PostgreSQL Migration
AI总结:
本文形式化并评估了十二种Token优化策略,在Oracle到PostgreSQL迁移中平衡成本、语法有效性、语义保持和结构保真度。
摘要:
LLM越来越多地用于软件现代化、代码翻译和数据库迁移。然而,基于LLM的Oracle2PostgreSQL迁移仍然受到高Token消耗、长上下文退化、方言特定的语义差异以及查询转换过程中语义漂移风险的限制。将大型Oracle SQL/PL-SQL工件、模式定义、过程逻辑和迁移指令直接包含到模型上下文中会增加成本并可能降低生成质量。本文将Token优化视为基于LLM的Oracle2PostgreSQL迁移中的一个约束转换问题。研究形式化并评估了十二种Token优化策略:基线表示、上下文剪枝、最小化、基于DSL的语义压缩、元数据增强、上下文重构、模式蒸馏、自适应路由、基于AST的最小化、标识符掩码、输出约束强制和混合优化。这些策略在10和100个Oracle SQL查询样本上使用有效语法率、精确匹配、语义匹配、CodeBLEU和Token效率进行评估。结果表明,轻度上下文剪枝几乎保持了基线水平的语义质量,在100个查询样本上实现了89.75%的语义匹配,而未优化基线为89.80%。自适应路由提供了最佳的实际权衡,输入Token减少8.72%,输出Token减少5.49%,同时保持88.40%的语义匹配,并将Token效率提高6.67%。激进的模式蒸馏将Token效率提高了132.22%,但导致语义匹配下降44.50个百分点。研究结果表明,Token优化不能简单地视为提示缩短;它必须作为一个多目标迁移问题来评估,平衡成本、语法有效性、语义保持和结构保真度。
英文摘要:
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.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。