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.


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

0
下载
关闭预览

相关内容

LLM/智能体作为数据分析师:综述
专知会员服务
38+阅读 · 2025年9月30日
利用多个大型语言模型:关于LLM集成的调研
专知会员服务
35+阅读 · 2025年2月27日
基于MySQL Binlog的Elasticsearch数据同步实践
DBAplus社群
15+阅读 · 2019年9月3日
工行基于MySQL构建分布式架构的转型之路
炼数成金订阅号
15+阅读 · 2019年5月16日
亿级订单数据的访问与储存,怎么实现与优化
ImportNew
11+阅读 · 2019年4月22日
亿级订单数据的访问与存储,怎么实现与优化?
码农翻身
16+阅读 · 2019年4月17日
放弃 RNN/LSTM 吧,因为真的不好用!望周知~
人工智能头条
19+阅读 · 2018年4月24日
【迁移学习】简述迁移学习在深度学习中的应用
产业智能官
15+阅读 · 2018年1月9日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
3+阅读 · 2015年12月31日
国家自然科学基金
31+阅读 · 2015年12月31日
VIP会员
最新内容
定向能反无人机系统最新发展动态
专知会员服务
0+阅读 · 31分钟前
从燃煤战舰到算法战争:水面指挥的永恒要求
专知会员服务
1+阅读 · 48分钟前
《通过小型无人机系统将情报能力“作战化”》
消耗优势:美军的“精确规模化”概念
专知会员服务
8+阅读 · 6月15日
相关VIP内容
相关基金
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
3+阅读 · 2015年12月31日
国家自然科学基金
31+阅读 · 2015年12月31日
Top
微信扫码咨询专知VIP会员