Uploaded by BINIYAM KABTAMU

Query Compilation Techniques for Modern Hardware

advertisement
Query Compilation Techniques for Modern Hardware: A Survey
1. Introduction
Query compilation is a technique that transforms high-level queries into executable code that
can run efficiently on modern hardware. Query compilation has been shown to achieve
significant performance improvements over traditional query execution methods, especially for
complex analytical workloads. However, query compilation also poses many challenges, such as
code generation, optimization, and portability across different hardware platforms. In this article,
we survey the state-of-the-art research on query compilation techniques for modern hardware,
such as CPUs, GPUs, FPGAs, and cloud environments. We also discuss the open problems and
future directions for query compilation research.
Query compilation techniques for modern hardware are methods that aim to improve the
performance of query execution by generating custom machine code for each query. These
methods use just-in-time (JIT) compilation to translate a query from a relational query plan to an
intermediate representation (IR), and then from the IR to native machine code for the target
machine. The advantage of this approach is that the compiled code can run very fast and exploit
the features of the modern hardware, such as parallelism, vectorization, and caching. The
disadvantage is that the compilation process introduces an overhead that can be significant for
short-running or complex queries.
There are different levels of intermediate representations that can be used for query
compilation, such as C/C++, OpenCL, CUDA, LLVM IR, or Flounder IR. Each level has its own
advantages and disadvantages in terms of compilation time, execution speed, and portability.
Some query compilers also use adaptive techniques that can choose different implementations
for evaluating relational operators or expressions while executing a query and change the
execution order of filter predicates and joins. These techniques can improve the performance of
data-centric code by more than 2×
2. Background
Query compilation is the process of translating a high-level query language, such as SQL, into an
executable program that can run efficiently on a database system. Query compilation typically
involves the following steps1:

Parsing: The query is checked for syntactic and semantic errors, and converted into a
parse tree that represents the logical structure of the query.

Binding: The parse tree is annotated with metadata, such as data types, column names,
and table references, by accessing the system catalog. This step also resolves any
ambiguities or aliases in the query.

Optimization: The query optimizer applies various rules and heuristics to transform and
rewrite the parse tree into an optimal query plan. A query plan is a tree of physical
operators that implement the query logic. The optimizer also estimates the cost and
cardinality of each operator and chooses the best plan among several alternatives.

Code generation: The query plan is translated into executable code that can run on the
database engine. The code may consist of native machine code, bytecode, or
interpreted instructions. The code may also include calls to external functions or
libraries.
Query compilation can improve performance by transforming high-level queries into executable
code that can run efficiently on modern hardware. Query compilation can achieve significant
performance improvements over traditional query execution methods, especially for complex
analytical workloads. Query compilation can also adapt to different hardware platforms and
query workloads, and leverage the benefits of native code execution, such as parallelism,
vectorization, and caching1.
Some examples of query compilation techniques are:

WebAssembly: This is a binary instruction format that can be executed by web browsers
and other platforms. WebAssembly enables fast compilation and execution of SQL
queries by delegating the execution to the V8 engine.

Flounder IR: This is an intermediate representation (IR) that is specifically designed for
database processing. Flounder IR is lightweight and close to machine assembly, which
simplifies the translation from IR to machine code. Flounder IR enables low-latency
query compilation and execution2.

CompiledQuery: This is a class in .NET Framework that provides compilation and caching
of queries for reuse. CompiledQuery can improve the performance of LINQ to Entities
queries by avoiding repeated parsing and algebrization of the query expression
Query compilation is a complex and challenging task that requires balancing trade-offs
between compilation time and execution time, as well as adapting to different hardware
platforms and query workloads.
Query compilation has been shown to achieve significant performance improvements over
traditional query execution methods, especially for complex analytical workloads. However,
query compilation also poses many challenges, such as:

Code generation: This is the process of translating a query plan into executable code
that can run on the database engine. Code generation requires choosing an appropriate
programming language, data structure, and execution model for the target hardware
platform. Code generation also involves handling complex query features, such as
aggregation, joins, subqueries, and user-defined functions1.

Optimization: This is the process of finding the best query plan among several
alternatives. Optimization requires estimating the cost and cardinality of each query
plan, as well as applying various rules and heuristics to transform and rewrite the query.
Optimization also depends on the availability and accuracy of statistics, indexes, and
other metadata about the data and the system2.

Portability: This is the ability of the generated code to run on different hardware
platforms, such as CPUs, GPUs, FPGAs, and cloud environments. Portability requires
dealing with different architectures, instruction sets, memory models, and performance
characteristics of each platform. Portability also involves adapting to dynamic changes in
the system configuration, such as load balancing, scaling, and migration 1.

Compilation time: This is the time spent on compiling the query before executing it.
Compilation time can be a major bottleneck for interactive or ad hoc queries, where
users expect low latency. Compilation time can be reduced by using lightweight
intermediate representations, fast code generation frameworks, and efficient compiler
backends1.
3. Literarure Review
“Query Compilation Techniques for Modern Hardware: A Survey” based on the following articles:

Efficiently Compiling Efficient Query Plans for Modern Hardware 1

Generating Code for Holistic Query Evaluation 2

CPU and Cache Efficient Management of Memory-Resident Databases 3

Micro Adaptivity in Vectorwise 4

How to Architect a Query Compiler 5

Adaptive Execution of Compiled Queries 6
Query compilation is a technique that transforms high-level queries into executable code that can run
efficiently on modern hardware. Query compilation has been shown to achieve significant performance
improvements over traditional query execution methods, especially for complex analytical workloads.
However, query compilation also poses many challenges, such as code generation, optimization,
portability, and compilation time.
This survey reviews the state-of-the-art research on query compilation techniques for modern
hardware, such as CPUs, GPUs, FPGAs, and cloud environments. We also discuss the open problems and
future directions for query compilation research.
The first article 1 presents a novel compilation strategy that translates a query into compact and efficient
machine code using the LLVM compiler framework. The article shows that the resulting code frequently
rivals the performance of hand-written C++ code, and outperforms existing query execution engines.
The article also discusses the challenges and trade-offs of query compilation, such as memory
management, code size, and caching.
The second article 2 proposes a framework that uses customized code generation to achieve holistic
query evaluation. The idea is to use a collection of highly efficient code templates and dynamically
instantiate them to create query- and hardware-specific source code. The article introduces a prototype
system called HIQUE, which incorporates this approach. The article also presents a detailed
experimental study of the system’s performance, showing that HIQUE surpasses both well-established
and currently-emerging query processing techniques.
The third article 3 focuses on optimizing query processing for memory-resident databases. The article
argues that memory-resident databases have to be optimized for two resources: CPU cycles and
memory bandwidth. To optimize for bandwidth in mixed OLTP/OLAP scenarios, the article suggests
using the hybrid or partially decomposed storage model (PDSM). To optimize for CPU efficiency, the
article combines partially decomposed storage with just-in-time (JiT) compilation of queries. The article
also develops a novel approach to cost modeling and storage layout optimization for JiT-compiled
queries.
The fourth article 4 introduces micro adaptivity, an orthogonal approach to adaptive query execution
that takes adaptivity to the micro level by making the low-level functions of a query executor more
performance-robust. The article shows that micro adaptivity increases performance robustness and
saves development time spent in finding and tuning heuristics and cost model thresholds in query
optimization. The article also describes the software framework for micro adaptivity that is
implemented in the Vectorwise system.
The fifth article 5 studies how to architect a query compiler. The article points out that the state of the
art in query compiler construction is lagging behind that in the compilers field. The article attempts to
remedy this by exploring the key causes of technical challenges in need of well founded solutions, and
by gathering the most relevant ideas and approaches from the PL and compilers communities. The
article proposes to use a stack of multiple DSLs on different levels of abstraction with lowering in
multiple steps to make query compilers easier to build and extend. The article also reports on recreating a well-known query compiler following these ideas.
The sixth article 6 explores adaptive execution of compiled queries. The article observes that compiled
queries are often faster than interpreted queries, but less adaptive to changing conditions. The article
proposes a hybrid approach that combines compiled and interpreted execution modes, and switches
between them at runtime based on feedback from the execution engine. The article also presents an
adaptive execution framework that supports this approach, and evaluates its performance on various
workloads.
These articles provide an overview of the recent advances and challenges in query compilation research.
They demonstrate that query compilation is a promising technique for improving query processing
performance on modern hardware platforms, but also requires careful design and engineering decisions.
They also suggest some directions for future work, such as exploiting parallelism, vectorization, caching,
and specialization in query compilation; developing more accurate and adaptive cost models; integrating
query compilation with other components of data management systems; and applying query
compilation to new domains and applications.
4. Discussion

The first article presents a novel compilation strategy that translates a query into compact and
efficient machine code using the LLVM compiler framework. A possible critique of this article is
that it does not address the issue of portability across different hardware platforms, which may
limit the applicability of the approach. A possible discussion point is how to extend the approach
to support other architectures, such as GPUs or FPGAs, and how to handle the trade-offs
between performance and portability.

The second article proposes a framework that uses customized code generation to achieve
holistic query evaluation. A possible critique of this article is that it relies on a fixed set of code
templates, which may not be able to capture all the possible variations and optimizations of
query plans. A possible discussion point is how to design more flexible and expressive code
templates, and how to generate them automatically or semi-automatically from query plans.

The third article focuses on optimizing query processing for memory-resident databases. A
possible critique of this article is that it assumes a hybrid or partially decomposed storage model
(PDSM), which may not be suitable for all kinds of data and queries. A possible discussion point
is how to adapt the approach to other storage models, such as columnar or row-oriented, and
how to handle the trade-offs between storage layout and query performance.

The fourth article introduces micro adaptivity, an orthogonal approach to adaptive query
execution that takes adaptivity to the micro level by making the low-level functions of a query
executor more performance-robust. A possible critique of this article is that it does not provide
a formal model or analysis of micro adaptivity, which may make it difficult to reason about its
correctness and effectiveness. A possible discussion point is how to formalize and measure
micro adaptivity, and how to compare it with other forms of adaptivity, such as re-optimization
or re-partitioning.

The fifth article studies how to architect a query compiler. A possible critique of this article is
that it does not provide a concrete implementation or evaluation of the proposed architecture,
which may make it hard to assess its feasibility and practicality. A possible discussion point is
how to implement and evaluate the proposed architecture, and how to compare it with existing
query compilers, such as HyPer or Vectorwise.

The sixth article explores adaptive execution of compiled queries. A possible critique of this
article is that it does not consider the overhead and complexity of switching between compiled
and interpreted execution modes, which may affect the performance and stability of the
system. A possible discussion point is how to minimize and optimize the switching cost, and how
to balance the benefits and drawbacks of each execution mode.
Here are some possible open problems and future directions for query compilation

Exploiting parallelism, vectorization, caching, and specialization in query compilation: Modern
hardware platforms offer various features that can improve the performance of query
processing, such as parallel cores, vector instructions, cache hierarchies, and specialized units.
However, query compilation techniques need to be aware of and exploit these features to
achieve optimal performance. For example, how to generate code that can leverage parallelism
and vectorization without introducing synchronization or alignment overheads? How to
generate code that can utilize caching and prefetching without causing cache thrashing or
memory contention? How to generate code that can take advantage of specialized hardware
units, such as GPUs or FPGAs, without sacrificing portability or generality? These are some of the
questions that need to be addressed by future query compilation research.

Developing more accurate and adaptive cost models: Query optimization is a crucial step in
query compilation, as it determines the quality of the generated code. Query optimization relies
on cost models that estimate the performance of different query plans and operators. However,
cost models are often inaccurate or outdated, as they may not reflect the actual characteristics
of the data, the system, or the hardware. Moreover, cost models are often static, as they do not
adapt to changing conditions, such as data skew, workload variation, or system configuration.
Therefore, future query compilation research needs to develop more accurate and adaptive cost
models that can capture the dynamics of query processing and guide the optimization and
execution of compiled queries.

Integrating query compilation with other components of data management systems: Query
compilation is not an isolated technique that can be applied independently of other aspects of
data management systems. Query compilation interacts with and depends on other
components, such as storage management, transaction management, concurrency control,
recovery management, security management, and metadata management. Therefore, future
query compilation research needs to consider how to integrate query compilation with these
components, and how to ensure the correctness, consistency, robustness, and scalability of the
system as a whole. For example, how to handle updates and transactions in compiled queries?
How to support concurrency control and recovery mechanisms in compiled queries? How to
enforce security policies and access control in compiled queries? How to manage metadata and
statistics for compiled queries? These are some of the challenges that need to be tackled by
future query compilation research.

Applying query compilation to new domains and applications: Query compilation is not limited
to relational databases or SQL queries. Query compilation can be applied to other domains and
applications that involve data processing and analysis, such as graph databases, stream
processing, machine learning, natural language processing, image processing, and more.
Therefore, future query compilation research needs to explore how to adapt and extend query
compilation techniques to these domains and applications, and how to address the specific
requirements and challenges of each domain and application. For example, how to compile
graph queries that involve complex traversal patterns and algorithms? How to compile stream
queries that involve temporal and spatial constraints and windows? How to compile machine
learning queries that involve high-dimensional data and complex models? How to compile
natural language queries that involve semantic analysis and natural language generation? How
to compile image queries that involve pixel manipulation and image transformation? These are
some of the opportunities that need to be pursued by future query compilation research.
5. Conclusion
Query compilation is a technique that transforms high-level queries into executable code that can run
efficiently on modern hardware. Query compilation has been shown to achieve significant performance
improvements over traditional query execution methods, especially for complex analytical workloads.
However, query compilation also poses many challenges, such as code generation, optimization,
portability, and compilation time.
This survey reviewed the state-of-the-art research on query compilation techniques for modern
hardware, such as CPUs, GPUs, FPGAs, and cloud environments. We also discussed the open problems
and future directions for query compilation research. We found that query compilation is a promising
technique for improving query processing performance on modern hardware platforms, but also
requires careful design and engineering decisions. We also suggested some directions for future work,
such as exploiting parallelism, vectorization, caching, and specialization in query compilation; developing
more accurate and adaptive cost models; integrating query compilation with other components of data
management systems; and applying query compilation to new domains and applications.
We hope that this survey provides a comprehensive and up-to-date overview of the query compilation
research field, and inspires new ideas and collaborations among researchers and practitioners. We also
hope that this survey helps readers to understand the benefits and challenges of query compilation, and
to appreciate the complexity and beauty of this technique.
Download