Page 263 - 《软件学报》2026年第3期
P. 263

1226                                                       软件学报  2026  年第  37  卷第  3  期


                 (solid  state  drives),  the  performance  bottleneck  in  disk-based  databases  has  shifted  towards  optimizing  CPU  utilization  and  memory
                 management.  However,  current  database  query  execution  often  relies  on  interpreted  methods,  leading  to  numerous  virtual  function  calls,
                 context  switches,  and  cache  misses.  This  limits  the  ability  of  modern  CPUs  to  fully  utilize  their  pipelines  and  cache  mechanisms,  resulting
                 in  inefficient  query  execution,  particularly  in  scenarios  involving  large  datasets  and  complex  queries.  To  address  these  issues,  this  study
                 proposes  several  just-in-time  (JIT)  compilation  optimization  strategies  for  traditional  interpreted  database  execution,  validated  through
                 experiments  on  MySQL.  First,  an  approach  is  presented  wherein  the  LLVM  (low  level  virtual  machine)  compiler  is  used  to  convert  SQL
                 predicates  into  machine  code  at  runtime,  replacing  the  interpretation  method  to  reduce  the  overhead  of  virtual  function  calls  and  context
                 switching.  Next,  a  hybrid  compilation  and  interpretation  approach  is  introduced  to  extend  the  applicability  of  JIT  execution.  Finally,  a
                 query  pushdown  strategy  is  designed  for  pluggable  database  system  architectures,  enabling  the  transfer  of  JIT-compiled  machine  code  to
                 the  storage  engine  layer  to  reduce  unnecessary  data  transfer  and  computational  overhead.  Experimental  results  show  that  enabling  JIT
                 compilation  significantly  enhances  MySQL’s  query  performance.  Notably,  for  complex  queries  and  large  datasets,  the  JIT-compiled  system
                 reduces  CPU  load  and  memory  usage,  leading  to  substantial  improvements  in  system  response  speed  and  throughput.  In  TPC-H-like  tests,
                 compared to the native MySQL version, the optimized system shows performance gains of up to 148%.
                 Key words:  just-in-time (JIT) compilation; hybrid compilation and execution; query optimization; predicate pushdown; pluggable architecture
                         optimization
                    随着信息技术的迅猛发展, 数据的规模与复杂性呈现出指数级增长, 尤其是在大数据、人工智能和物联网等
                 领域, 数据的生成与处理已成为技术革新的核心. 数据库作为数据存储与处理的核心, 其性能和效率直接关系到信
                 息化社会的运行效率. 在数据处理过程中, 磁盘              I/O  往往是系统性能瓶颈. 得益于近些年来存储技术的飞速发展,
                 内存容量显著提升, SSD (solid state drive) 固态硬盘价格大幅下降从而逐渐替代传统硬盘, 从根本上缓解了                    I/O  带
                 来的问题. 因此, 数据库的性能瓶颈逐渐转向了              CPU  利用和内存管理方面的效率问题. 现代数据库系统要应对这
                 一挑战, 需要更高效地利用计算资源、优化数据访问和处理方式. 目前数据库的查询执行大多仍采用                                 Volcano  模
                 型  [1] 的解释执行方式. 系统将查询语句转换成由操作算子通过               GetNext 方法组合形成的查询执行树, 执行器采用
                 迭代器机制, 通过     GetNext 方法按需从当前方法获取下一批数据. 每个运算符会向下游的子节点请求数据, 直到获
                 取到满足条件的数据或子节点返回“无数据”. 这个查询处理机制导致了大量的虚函数调用、上下文切换和高速缓
                 存未命中   [2] . 在现代硬件环境中, 特别是在处理复杂查询时, 其性能瓶颈愈发明显. 每次执行查询时, 系统会频繁地
                 递归调用    GetNext 方法拉取数据, 执行相关计算. 频繁的虚函数调用带来的上下文切换使得系统无法充分利用现
                 代  CPU  的流水线和缓存机制, 造成查询执行效率的低下, 尤其在大规模数据集上, 性能问题尤为突出. 因此, 如何
                 减少虚函数调用, 优化计算过程, 成为现代数据库引擎亟待解决的问题之一.
                    近些年, JIT (just-in-time) 编译技术在数据库中愈发流行        [3−7] . JIT  编译通过将查询操作转化为机器码, 在查询
                 执行过程中动态生成优化后的可执行代码, 避免了传统解释执行带来的指令开销和函数调用开销. 与静态编译不
                 同, JIT  编译能够根据代码实际执行路径和硬件环境的特点进行针对性优化, 如选择最优查询执行计划、内存优化、
                 提升跨平台兼容等, 从而在查询执行时提升代码的执行效率. 这种优化方式不仅能有效减少解释执行带来的开销,
                 还能针对具体的查询逻辑和硬件特性进行定制化优化, 显著提高复杂查询的处理性能                            [8] . JIT  编译技术尤其适用于
                 内存数据库和计算密集型任务, 能大幅提高数据库系统的吞吐量和响应速度.
                    鉴于以上研究背景, 本文针对传统           Volcano  引擎数据库提出若干     JIT  编译优化方案. 并在    MySQL  数据库  [9] 上
                 验证了技术可行性. 主要贡献如下.
                    (1) 基于  LLVM (low level virtual machine) 编译器  [10] , 提出一种非侵入式  JIT  实时代码生成技术, 并保留系统
                 原有的解释执行机制, 使得解释执行与            JIT  编译能够共存. 优化器根据查询执行代价自动选择最合适的执行方式,
                 为事务型与分析型场景融合提供一个可行的解决方案.
                    (2) 提出一种混合执行模式, 允许在同一个查询中同时存在编译与解释执行模式. 对不支持的查询树子树以函
                 数调用的方式嵌入到生成代码中, 规避朴素              JIT  代码生成机制在子节点包含不支持的函数或数据类型的时候切换
                 回解释执行模式, 浪费前置查询树节点的代码生成时间.
                    (3) 可插拔特性为数据库系统提供了灵活的数据存储选择, 但额外引入的中间层接口给数据传输带来不可忽
   258   259   260   261   262   263   264   265   266   267   268