Skip to main content
QUICK REVIEW

[Paper Review] Optimization of Imperative Programs in a Relational Database

Karthik Ramachandra, Kwanghyun Park|arXiv (Cornell University)|Dec 1, 2017
Advanced Database Systems and QueriesComputer Science20 references5 citations
TL;DR

Froid is an extensible, language-agnostic framework that automatically transforms User-Defined Functions (UDFs) in relational databases into equivalent relational algebraic expressions, enabling cost-based optimization and eliminating the performance overhead of traditional iterative UDF execution. This results in set-oriented, parallel query plans and performance improvements of multiple orders of magnitude on real-world workloads.

ABSTRACT

For decades, RDBMSs have supported declarative SQL as well as imperative functions and procedures as ways for users to express data processing tasks. While the evaluation of declarative SQL has received a lot of attention resulting in highly sophisticated techniques, the evaluation of imperative programs has remained naive and highly inefficient. Imperative programs offer several benefits over SQL and hence are often preferred and widely used. But unfortunately, their abysmal performance discourages, and even prohibits their use in many situations. We address this important problem that has hitherto received little attention. We present Froid, an extensible framework for optimizing imperative programs in relational databases. Froid's novel approach automatically transforms entire User Defined Functions (UDFs) into relational algebraic expressions, and embeds them into the calling SQL query. This form is now amenable to cost-based optimization and results in efficient, set-oriented, parallel plans as opposed to inefficient, iterative, serial execution of UDFs. Froid's approach additionally brings the benefits of many compiler optimizations to UDFs with no additional implementation effort. We describe the design of Froid and present our experimental evaluation that demonstrates performance improvements of up to multiple orders of magnitude on real workloads.

Motivation & Objective

  • To address the long-ignored performance bottleneck of imperative User-Defined Functions (UDFs) in relational databases, which are widely used despite being notoriously slow.
  • To eliminate the impedance mismatch between declarative SQL and imperative programming by automatically transforming UDFs into relational algebraic forms.
  • To enable cost-based optimization of UDFs by embedding them as relational expressions within the main query plan.
  • To bring the benefits of compiler optimizations—like dead code elimination and constant folding—automatically to UDFs without additional implementation effort.
  • To build a scalable, extensible framework that supports various imperative languages and integrates seamlessly into existing RDBMS query processing pipelines.

Proposed method

  • Froid models imperative code blocks as relational expressions and composes them using the Apply operator to form a single, optimized relational expression.
  • It performs static analysis to detect and transform imperative constructs (e.g., loops, conditionals, assignments) into equivalent relational algebraic operations.
  • The framework applies relational algebraic simplifications and transformations that semantically match common compiler optimizations, such as constant folding and dead code elimination.
  • Froid operates as a pre-optimizer, transforming UDFs before the main query optimizer, avoiding the need for query optimizer extensions or new operators.
  • It supports language-agnostic transformation through abstract syntax tree (AST) analysis, enabling extension to multiple imperative languages beyond T-SQL.
  • The system integrates into Microsoft SQL Server and leverages existing subquery optimization techniques to generate efficient, set-oriented, parallel execution plans.

Experimental results

Research questions

  • RQ1How can imperative UDFs in relational databases be automatically transformed into relational algebraic expressions to enable efficient optimization?
  • RQ2Can relational algebraic transformations express the same optimizations as traditional compiler techniques like dead code elimination and constant folding?
  • RQ3What performance improvements can be achieved by replacing iterative UDF execution with set-oriented, parallel plans via relational rewriting?
  • RQ4How can the impedance mismatch between declarative SQL and imperative programming be resolved without requiring changes to the query optimizer?
  • RQ5To what extent can Froid scale to large UDFs with thousands of statements while maintaining low transformation time?

Key findings

  • Froid achieves performance improvements of multiple orders of magnitude on real customer workloads by transforming UDFs into efficient, set-oriented, parallel query plans.
  • The framework can transform UDFs with thousands of statements in under 10 seconds, significantly outperforming QBS-based approaches in scalability and speed.
  • Relational algebraic transformations in Froid achieve the same optimization outcomes as traditional compiler optimizations, such as dead code elimination and constant folding, without requiring additional implementation.
  • Froid’s approach eliminates the need for costly UDF execution by inlining and rewriting them as relational expressions, avoiding the performance penalties of iterative, serial execution.
  • The framework is extensible to multiple imperative languages and integrates seamlessly into existing RDBMS query processing pipelines without modifying the optimizer.
  • Evaluation shows that Froid effectively handles complex real-world workloads, including those with multiple return statements and redundant predicate computations, which previous approaches failed to address.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.