Skip to main content
QUICK REVIEW

[Paper Review] Database Theory in Action: Search-Based Program Optimization

Yisu Remy Wang, Mahmoud Abo Khamis|arXiv (Cornell University)|Feb 21, 2022
Advanced Database Systems and QueriesComputer Science1 citations
TL;DR

This paper introduces a novel program synthesis-based framework for optimizing recursive Datalog queries using a new rewrite rule called the FGH-rule, which enables significant performance improvements by transforming recursive programs into more efficient equivalents. The method leverages counterexample-guided inductive synthesis (CEGIS) and equality saturation to explore a large optimization space efficiently, achieving up to 4 orders of magnitude speedup on optimized Datalog systems.

ABSTRACT

Most work on query optimization has concentrated on loop-free queries. However, data science and machine learning workloads today typically involve recursive or iterative computation. In this work, we propose a novel framework for optimizing recursive queries using methods from program synthesis. In particular, we introduce a simple yet powerful optimization rule called the "FGH-rule" which aims to find a faster way to evaluate a recursive program. The solution is found by making use of powerful tools, such as a program synthesizer, an SMT-solver, and an equality saturation system. We demonstrate the strength of the optimization by showing that the FGH-rule can lead to speedups up to 4 orders of magnitude on three, already optimized Datalog systems.

Motivation & Objective

  • To address the lack of systematic optimization for recursive queries in modern database systems, especially in data science and machine learning workloads.
  • To develop a general-purpose optimization framework that rewrites entire recursive programs—not just their bodies—for improved efficiency.
  • To enable automatic discovery of semantic and structural optimizations, including loop invariant inference and global constraint utilization.
  • To reduce the search space for query rewriting while maintaining expressiveness and correctness through CEGIS and SMT-based verification.

Proposed method

  • The FGH-rule is introduced as a novel, simple rewrite rule that proves equivalence between recursive programs with different loop bodies.
  • A source-to-source optimizer uses counterexample-guided inductive synthesis (CEGIS) to explore candidate query rewrites, guided by a verifier (Z3) that checks correctness and generates counterexamples.
  • The system integrates an SMT-solver and equality saturation to verify semantic equivalence and infer loop invariants automatically.
  • The grammar generator is carefully designed to limit the search space to no more than 132 candidates, enabling sub-second optimization times.
  • Global constraints on data are used to enable domain-specific semantic optimizations, extending the reach of the FGH-rule.
  • The framework optimizes one stratum at a time, focusing on critical 'basic blocks' to improve performance without requiring full program rewrites.

Experimental results

Research questions

  • RQ1Can a general-purpose rewrite rule be designed to optimize recursive Datalog programs beyond traditional body-level optimizations?
  • RQ2How can program synthesis techniques be adapted to discover efficient recursive query transformations automatically?
  • RQ3To what extent can CEGIS and SMT-based verification reduce the search space while enabling complex optimizations like loop invariant inference?
  • RQ4Can semantic optimizations using global data constraints be systematically applied to recursive queries via the FGH-rule?
  • RQ5What performance gains are achievable when applying the FGH-rule to already-optimized Datalog systems?

Key findings

  • The FGH-rule can express and generalize known optimizations such as semi-naive evaluation and magic sets, while enabling new, more efficient transformations.
  • The framework achieved speedups of up to 4 orders of magnitude (10,000x) on three optimized Datalog systems, even when those systems already applied advanced optimizations.
  • Synthesis times were under 1 second for all benchmarks, with the search space limited to no more than 132 candidates, demonstrating high efficiency.
  • The optimization was effective across diverse workloads, including graph algorithms (e.g., connected components), centrality computation, and gradient descent-like iterative processes.
  • The optimizer reduced asymptotic space complexity from O(n²) to O(n) in the connected components example, significantly improving scalability.
  • The system outperformed rule-based synthesis and demonstrated that even complex queries with global constraints could be optimized rapidly using CEGIS.

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.