Database Query Execution with Hybrid Compilation and Code Reuse

Resolve Bottlenecks,
Find Innovative Solutions
Generate 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

VSEngineering Contradiction Analysis

1Speed

If optimized machine code is compiled before execution, then execution speed is improved, but compilation time increases query latency

Engineering Contradiction:
Improvequery execution speedVSAvoidquery latency
Core Design Contradiction:
SpeedVSLoss of time

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

Inventive Principle:
Principle #10Preliminary action

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

Inventive Principle:
Principle #15Dynamics

2Loss of time

If unoptimized machine code is used for fast compilation, then query start time is improved, but execution speed deteriorates

Engineering Contradiction:
Improvequery start timeVSAvoidquery execution speed
Core Design Contradiction:
Loss of timeVSSpeed

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

Inventive Principle:
Principle #10Preliminary action

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

Inventive Principle:
Principle #20Continuity of useful action

3Speed

If machine code is recompiled for every query, then execution speed is improved, but productivity deteriorates due to redundant compilation

Engineering Contradiction:
Improveexecution speedVSAvoidquery processing throughput
Core Design Contradiction:
SpeedVSProductivity

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

Inventive Principle:
Principle #26Copying

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

Inventive Principle:
Principle #6Universality (Multi-functionality)

Data Source

PatentUS12572540B2Accelerated database query processing with complied code reuse
Publication Date: 2026.03.10 SINGLESTORE INC
  • US12572540B2 patent drawing
  • US12572540B2 patent drawing
  • US12572540B2 patent drawing

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.