JIT Query Execution Infrastructure for Database Performance
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Interpretive approaches to database queries introduce execution overhead due to expensive virtual function calls and unnecessary CPU cycles, which can be improved by combining just-in-time compilation with block-wise query execution.
Innovation Solution
Implementing a JIT query execution infrastructure that uses an LLVM compiler framework to generate optimized native machine code for query plan fragments, caching compiled objects for reuse, and normalizing function nodes into string keys for efficient retrieval and compilation.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Ease of manufacture
If interpretive approach is used for query execution, then ease of implementation is improved, but execution overhead increases
Solution Approach 1:
The system performs preliminary compilation of query execution plans into native machine code before actual query execution. The query optimizer generates an execution plan that is then compiled by a JIT compiler into optimized native code, which is cached and executed directly. This preliminary compilation action eliminates the need for repeated interpretation during query execution, thereby reducing execution overhead while maintaining implementation feasibility.
2Speed
If JIT compilation is implemented for query execution, then execution speed is improved, but system complexity increases
Solution Approach 1:
The system introduces an intermediary JIT compilation layer between the query optimizer and the execution engine. The query optimizer generates execution plans in an intermediate representation, which is then passed to the JIT compiler that translates it into native machine code. This intermediary compilation step enables execution speed improvement by producing optimized native code, while the modular architecture of the intermediary layer helps manage system complexity through clear separation of concerns.
Solution Approach 2:
The query execution system is segmented into distinct modular components: query parser, query optimizer, JIT compiler, and execution engine. Each component handles a specific aspect of query processing independently. The JIT compiler is further segmented to handle different types of execution plans and generate specialized native code for each. This segmentation allows the system to achieve high execution speed through targeted optimization while managing complexity through modular design.
3Productivity
If query-specific compilation is performed, then query execution performance is improved, but compilation time increases
Solution Approach 1:
The system performs preliminary compilation of query execution plans into native machine code before actual query execution. The query optimizer generates an execution plan that is then compiled by a JIT compiler into optimized native code, which is cached and executed directly. This preliminary compilation action eliminates the need for repeated interpretation during query execution, thereby reducing execution overhead while maintaining implementation feasibility.
Solution Approach 2:
The system creates and caches compiled execution plans as reusable templates for similar queries. When a query execution plan is compiled into native machine code, the resulting compiled object is stored in a cache. Subsequent queries with similar execution plans can reuse these cached compiled objects, avoiding redundant compilation and reducing overall compilation time while maintaining high query execution performance.
Data Source
Figure 1~3
Figure 2
Figure 4~5
AI summary
A method includes receiving, by a database system, a query statement and forming a runtime plan tree in accordance with the query statement. The method also includes traversing the runtime plan tree including determining whether a function node of the runtime plan tree is qualified for just-in-time (JIT) compilation. Additionally, the method includes, upon determining that the function node is a qualified for JIT compilation producing a string key in accordance with a function of the function node and determining whether a compiled object corresponding to the string key is stored in a compiled object cache.