This invention relates to
database query execution optimization. Specifically, it describes techniques for optimal execution based on query interpretation translated into
a domain-specific language (DSL) using optimizations such as
partial evaluation,
abstract syntax tree (AST)
rewriting, just-in-time (JIT) compilation, dynamic analysis, speculative logic, and Futamura projection. In an embodiment, a
database management system (DBMS) hosted on a computer generates a
query tree representing a
database query, which contains expressions represented by subtrees of the
query tree. The DBMS generates a sequence of DSL instructions representing the subtrees. During the execution of the
database query, the sequence of DSL instructions is executed to evaluate the expressions. In an embodiment, the AST is generated from the sequence of DSL instructions. In an embodiment, the DSL AST is optimally rewritten based on a runtime
feedback loop that includes dynamic profiling information.