Database Query IR Caching and Parameterization

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Traditional database systems face inefficiencies due to the need for repeated parsing and execution of queries, which leads to high CPU usage and overhead, especially with JIT compilation, as they lack effective mechanisms for caching and reusing intermediate representation (IR) code.

Innovation Solution

The method involves generating node intermediate representations (IRs) for plan nodes in a database query execution plan tree, caching these IRs, and parameterizing them to create reusable modules that can be executed efficiently, reducing the need for repeated IR generation and JIT compilation.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Productivity

If JIT compilation is used to generate query-specific code, then query execution efficiency is improved by avoiding repeated parsing, but CPU resource consumption increases due to the overhead of code generation and compilation

Engineering Contradiction:
Improvequery execution efficiencyVSAvoidCPU resource consumption
Core Design Contradiction:
ProductivityVSUse of energy by moving object

Solution Approach 1:

The system performs preliminary actions by pre-generating and caching IR code for common query patterns before actual query execution. When a query matches a cached pattern, the pre-generated IR is reused instead of performing full JIT compilation, thus reducing CPU resource consumption while maintaining query execution efficiency.

Inventive Principle:
Principle #10Preliminary action

Solution Approach 2:

The system creates copies of successfully compiled IR code and stores them in a cache. When the same or similar queries are executed, these cached copies are reused rather than regenerating the IR code through JIT compilation, significantly reducing CPU resource consumption while preserving execution efficiency.

Inventive Principle:
Principle #26Copying

2Adaptability or versatility

If queries are parsed and executed anew each time, then query flexibility and adaptability are maintained, but CPU processing power consumption increases due to repeated parsing and iterative execution

Engineering Contradiction:
Improvequery flexibilityVSAvoidCPU processing power
Core Design Contradiction:
Adaptability or versatilityVSPower

Solution Approach 1:

The system uses parameterization to transform query-specific IR code into generic parameterized IR code. By replacing concrete values with parameters (placeholders), the same IR can be reused for multiple queries with different parameters, maintaining query flexibility while reducing CPU processing power consumption through code reuse.

Inventive Principle:
Principle #35Parameter changes

Solution Approach 2:

The system creates universal IR code that can serve multiple query types by using parameterized representations. A single parameterized IR module can handle multiple specific queries by substituting parameters with actual values at execution time, thus maintaining adaptability while reducing redundant processing.

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

3Speed

If node IRs are generated and cached for reuse, then subsequent query execution is accelerated by avoiding regeneration, but memory storage requirements increase to accommodate the cache

Engineering Contradiction:
Improvequery execution speedVSAvoidcache memory usage
Core Design Contradiction:
SpeedVSVolume of stationary object

Solution Approach 1:

The system extracts only the essential IR code for query execution plans and stores them in the cache, separating the execution-critical components from redundant information. By taking out only the necessary IR representations and caching those, the system minimizes memory usage while still achieving execution speedup.

Inventive Principle:
Principle #2Taking out (Extraction)

Solution Approach 2:

The system applies partial caching by only caching IR code for query patterns that are likely to be reused, rather than caching everything. This selective approach balances memory consumption with the benefit of faster execution for relevant queries, avoiding unnecessary memory usage for queries that won be repeated.

Inventive Principle:
Principle #16Partial or excessive action

Data Source

PatentUS10339137B2System and method for caching and parameterizing IR
Publication Date: 2019.07.02 FUTUREWEI TECHNOLOGIES INC
  • US10339137B2 patent drawing
  • US10339137B2 patent drawing
  • US10339137B2 patent drawing

AI summary

A system and method of caching and parameterizing intermediate representation code includes receiving, by a database, a query, parsing, by the database, the query to obtain a plan tree comprising a plurality of plan nodes arranged in hierarchical order descending from a top plan node, generating, by the database, node intermediate representations (IRs) for the plan nodes, executing, by the database, a first query using the node IRs, and reusing, by the database, the node IRs to execute subsequent queries.