Parameterized IR Catalog for Database JIT Compilation
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Existing database query execution engines face inefficiencies and errors in generating intermediate representations (IRs) for just-in-time (JIT) compilation, particularly due to costly and time-consuming code generation processes, which can be error-prone and do not benefit from JIT compilation if the C/C++ code is not specialized for incoming queries.
Innovation Solution
A method and apparatus that identify CPU-intensive functions in database queries, compile them to parameterized IRs with changeable variables, save these IRs in a catalog, and replace parameters with constant values during query execution to generate optimized machine code, thereby avoiding costly run-time generation and enabling efficient JIT compilation.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Productivity
If LLVM IRBuilder is used to generate intermediate representation at run-time, then JIT compilation can be performed, but the code generation process becomes costly in terms of time and computing resources
Solution Approach 1:
The patent pre-generates and stores parameterized intermediate representations in a catalog before actual query execution. When a query needs JIT compilation, the system retrieves the pre-generated parameterized IR from the catalog and only performs parameter substitution and constant folding, avoiding the costly process of generating complete query-specific IR from scratch at runtime.
2Ease of manufacture
If C/C++ code is compiled to LLVM IR using clang/clang++, then compilation can be performed, but the code does not benefit from JIT compilation if not specialized for incoming queries
Solution Approach 1:
The patent segments the query execution into two parts: a generic parameterized IR template that is pre-compiled, and query-specific parameter values that are substituted at runtime. This allows the system to maintain a reusable compilation infrastructure while achieving query-specific optimization through parameter substitution rather than requiring complete query-specific C/C++ code generation.
3Loss of time
If parameterized IR is pre-compiled and stored in catalog, then run-time generation cost is reduced, but the system complexity increases due to catalog management
Solution Approach 1:
The patent creates a universal parameterized IR template that can serve multiple different query types through parameter substitution. Instead of maintaining separate compiled IRs for each query type, the system uses a single parameterized template that adapts to different queries by substituting parameters with query-specific values, thereby reducing the number of distinct IR versions that need to be managed in the catalog.
Data Source
Figure 1~2
Figure 3
Figure 4
AI summary
Embodiments are provided herein for using parameterized Intermediate Representation (IR) for just-in-time (JIT) compilation in database query execution engines. In an embodiment, a method supporting query JIT compilation and execution in a database management system includes identifying a central processing unit (CPU) intensive function in a query, and identifying, in the CPU intensive function, one or more parameters. The one or more parameters represent variables with values changeable at different query instances. The CPU intensive function is compiled to a parameterized IR including the one or more parameters. The parameterized IR of the CPU intensive function is saved in a catalog of parameterized IRs.