Database Query Execution with Hybrid Compilation and Code Reuse
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Existing database management systems face challenges in efficiently processing user queries due to the trade-off between fast compilation and execution times, leading to noticeable delays in result retrieval, especially for large or complex queries.
Innovation Solution
A hybrid approach is employed where user queries are initially executed using unoptimized machine code for fast compilation, followed by parallel compilation of optimized machine code, with a switching mechanism to switch execution to optimized code once it is ready, along with a mechanism to reuse previously compiled machine code through bytecode conversion and LLVM IR hashing.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Speed
If optimized machine code is compiled before execution, then execution speed is improved, but compilation time increases query latency
Solution Approach 1:
The system performs preliminary compilation of optimized machine code in parallel with query execution using unoptimized code. The compiler thread prepares optimized code ahead of time, and once ready, the system switches to using the optimized version, thereby reducing future query latencies without delaying the current query response
Solution Approach 2:
The system dynamically switches between unoptimized and optimized machine code execution paths based on availability. Initially, unoptimized code is executed immediately, then the system transitions to optimized code once compilation completes, adapting the execution path to minimize overall query latency across multiple queries
2Loss of time
If unoptimized machine code is used for fast compilation, then query start time is improved, but execution speed deteriorates
Solution Approach 1:
While executing unoptimized machine code to achieve fast query start time, the system simultaneously performs preliminary compilation of optimized machine code in a parallel thread. This ensures that the faster optimized code will be ready for subsequent queries without delaying the current query's start time
Solution Approach 2:
The system maintains continuous useful action by executing queries using unoptimized code while the compiler thread continuously works on generating optimized code. This parallel processing ensures that query processing never stops while optimization is being prepared, maximizing resource utilization
3Speed
If machine code is recompiled for every query, then execution speed is improved, but productivity deteriorates due to redundant compilation
Solution Approach 1:
The system creates a copy of the optimized machine code and stores it in a code cache. Subsequent queries with similar execution plans can reuse this cached optimized code instead of recompiling, significantly reducing redundant compilation overhead while maintaining fast execution speed
Solution Approach 2:
The compiled optimized machine code serves multiple queries with similar execution plans. The code cache stores optimized code that can be universally applied to various queries that share common execution patterns, making the compilation effort beneficial for multiple operations rather than single-use
Data Source
AI summary
In an example there is provided a computer-implemented method which comprises generating an execution plan for a received user query, converting the execution plan into bytecode, compiling to unoptimized machine code using the bytecode and beginning execution of the execution plan by executing the unoptimized machine code, compiling optimized machine code using the bytecode whilst executing the unoptimized machine code; and switching to executing the optimized machine code in order to execute the execution plan, when the optimized machine code has been compiled.


