Adaptive interpretation and compilation of database queries
Abstract
A method executes at a computer system to retrieve data from a database. Upon receiving a database query, the computer system translates the query into an intermediate representation, and estimates a compilation time to compile the intermediate representation into machine executable code. The query execution time to retrieve a result set is also estimated. In accordance with a determination that the query execution time and compilation time satisfy an interpretation criterion, the computer system invokes a byte code interpreter to interpret the intermediate representation and retrieve the result set from the database. In accordance with a determination that the query execution and compilation times satisfy one of a plurality of compilation criteria, the computer system compiles the intermediate representation to form machine code and executes the machine code to retrieve the result set from the database. In some cases, the query intermediate representation is optimized prior to compilation.
Interactive Citation Constellation Global Citation Ranking
Interactive SVG Citation Constellation renders in Rust/WebAssembly. Prior art cited: 46 · Forward citations: 0.
Claims (20 — 3 Independent, 17 Dependent)
- Claim 1Independent Claim
A method for retrieving data from a database, comprising: at a computer system having one or more processors and memory storing one or more programs configured for execution by the one or more processors: receiving a database query from a client; translating the database query into an intermediate representation; computing an estimated query execution time according to an estimated number of rows that will be accessed to retrieve a result set corresponding to the database query; computing an estimated compilation time to compile the intermediate representation into machine executable code according to characteristics of the intermediate representation; in accordance with a determination that the estimated query execution time and the estimated compilation time satisfy a first optimized compilation criterion: performing one or more optimization passes of a first type on the intermediate representation to form an optimized intermediate representation of a first type; compiling the optimized intermediate representation of the first type to form optimized executable machine code of a first type; and executing the optimized executable machine code of the first type to retrieve the result set from the database; in accordance with a determination that the estimated query execution time and the estimated compilation time satisfy a second optimized compilation criterion: performing one or more optimization passes of a second type on the intermediate representation to form an optimized intermediate representation of a second type; compiling the optimized intermediate representation of the second type to form optimized executable machine code of a second type, wherein the optimized executable machine code of the second type has a lower execution time than the optimized executable machine code of the first type; and executing the optimized executable machine code of the second type to retrieve the result set from the database; and returning the result set.
- Claim 2Depends on #1
The method of claim 1, wherein computing the estimated compilation time is based on at least one of: a number of instructions in the intermediate representation; types of instructions in the intermediate representation; and a number of functions in the intermediate representation.
- Claim 3Depends on #1
The method of claim 1, wherein computing the estimated compilation time is based on a number of execution blocks in the intermediate representation, wherein each block comprises a maximal contiguous sequence of instructions without a jump instruction.
- Claim 4Depends on #1
The method of claim 1, wherein: the first optimized compilation criterion is satisfied when the estimated number of rows that will be accessed to retrieve the result set is greater than a first threshold but less than a second threshold; and the second optimized compilation criterion is satisfied when the estimated number of rows that will be accessed to retrieve the result set is greater than the second threshold.
- Claim 5Depends on #1
The method of claim 1, further comprising computing a ratio of the estimated query execution time and the estimated compilation time, wherein: the first optimized compilation criterion comprises a rule that the ratio is greater than a first threshold but less than a second threshold; and the second optimized compilation criterion comprises a rule that the ratio is greater than the second threshold.
- Claim 6Depends on #1
The method of claim 1, wherein the first optimized compilation criterion and the second optimized compilation criterion partition a set of all pairs (e, c) of estimated query execution time, that are greater than a minimum estimated query execution time, and estimated compilation time into two disjoint regions.
- Claim 7Depends on #1
The method of claim 1, wherein in accordance with a determination that the database query includes a join operation for a first dataset and a second dataset, the estimated query execution time is adjusted by summing a first cardinality of the first data set and a second cardinality of the second dataset.
- Claim 8Depends on #1
The method of claim 1, further comprising: in accordance with a determination that the optimized executable machine code of the first type is executed: determining a compilation time for the optimized executable machine code of the first type; and in accordance with a determination that the compilation time for the optimized executable machine code of the first type and the estimated compilation time are different, adjusting the estimated compilation time based on the compilation time for the optimized executable machine code of the first type.
- Claim 9Depends on #8
The method of claim 8, wherein, in accordance with a determination that the estimated compilation time has been adjusted, adjusting the first optimized compilation criterion and/or the second optimized compilation criterion.
- Claim 10Depends on #1
The method of claim 1, further comprising: in accordance with a determination that the optimized executable machine code of the first type is executed: determining a query execution time for the optimized executable machine code of the first type; and in accordance with a determination that the query execution time for the optimized executable machine code of the first type and the estimated query execution time are different, adjusting the estimated query execution time based on the query execution time for the optimized executable machine code of the first type.
- Claim 11Depends on #10
The method of claim 10, wherein, in accordance with a determination that the estimated query execution time has been adjusted, adjusting the first optimized compilation criterion and/or the second optimized compilation criterion.
- Claim 12Depends on #1
The method of claim 1, further comprising: in accordance with a determination that the optimized executable machine code of the second type is executed: determining a compilation time for the optimized executable machine code of the second type; and in accordance with a determination that the compilation time for the optimized executable machine code of the second type and the estimated compilation time are different, adjusting the estimated compilation time based on the compilation time for the optimized executable machine code of the second type.
- Claim 13Depends on #12
The method of claim 12, wherein, in accordance with a determination that the estimated compilation time has been adjusted, adjusting the first optimized compilation criterion and/or the second optimized compilation criterion.
- Claim 14Depends on #1
The method of claim 1, further comprising: in accordance with a determination that the optimized executable machine code of the second type is executed: determining a query execution time for the optimized executable machine code of the second type; and in accordance with a determination that the query execution time for the optimized executable machine code of the second type and the estimated query execution time are different, adjusting the estimated query execution time based on the query execution time for the optimized executable machine code of the second type.
- Claim 15Depends on #14
The method of claim 14, wherein, in accordance with a determination that the estimated query execution time has been adjusted, adjusting the first optimized compilation criterion and/or the second optimized compilation criterion.
- Claim 16Independent Claim
A computer system having one or more computing devices, each computing device having one or more processors and memory, wherein the memory stores one or more programs configured for execution by the one or more processors, the one or more programs comprising instructions for: receiving a database query from a client; translating the database query into an intermediate representation; computing an estimated query execution time according to an estimated number of rows that will be accessed to retrieve a result set corresponding to the database query; computing an estimated compilation time to compile the intermediate representation into machine executable code according to characteristics of the intermediate representation; in accordance with a determination that the estimated query execution time and the estimated compilation time satisfy a first optimized compilation criterion: performing one or more optimization passes of a first type on the intermediate representation to form an optimized intermediate representation of a first type; compiling the optimized intermediate representation of the first type to form optimized executable machine code of a first type; and executing the optimized executable machine code of the first type to retrieve the result set from a database; in accordance with a determination that the estimated query execution time and the estimated compilation time satisfy a second optimized compilation criterion: performing one or more optimization passes of a second type on the intermediate representation to form an optimized intermediate representation of a second type; compiling the optimized intermediate representation of the second type to form optimized executable machine code of a second type, wherein the optimized executable machine code of the second type has a lower execution time than the optimized executable machine code of the first type; and executing the optimized executable machine code of the second type to retrieve the result set from the database; and returning the result set.
- Claim 17Depends on #16
The computer system of claim 16, wherein computing the estimated compilation time is based on a number of execution blocks in the intermediate representation, wherein each block comprises a maximal contiguous sequence of instructions without a jump instruction.
- Claim 18Depends on #16
The computer system of claim 16, wherein: the first optimized compilation criterion is satisfied when the estimated number of rows that will be accessed to retrieve the result set is greater than a first threshold but less than a second threshold; and the second optimized compilation criterion is satisfied when the estimated number of rows that will be accessed to retrieve the result set is greater than the second threshold.
- Claim 19Depends on #16
The computer system of claim 16, the one or more programs further comprising instructions for computing a ratio of the estimated query execution time and the estimated compilation time, wherein: the first optimized compilation criterion comprises a rule that the ratio is greater than a first threshold but less than a second threshold; and the second optimized compilation criterion comprises a rule that the ratio is greater than the second threshold.
- Claim 20Independent Claim
A non-transitory computer readable storage medium storing one or more programs configured for execution by a computer system having one or more processors and memory, the one or more programs comprising instructions for: receiving a database query from a client; translating the database query into an intermediate representation; computing an estimated query execution time according to an estimated number of rows that will be accessed to retrieve a result set corresponding to the database query; computing an estimated compilation time to compile the intermediate representation into machine executable code according to characteristics a size of the intermediate representation; in accordance with a determination that the estimated query execution time and the estimated compilation time satisfy a first optimized compilation criterion: performing one or more optimization passes of a first type on the intermediate representation to form an optimized intermediate representation of a first type; compiling the optimized intermediate representation of the first type to form optimized executable machine code of a first type; and executing the optimized executable machine code of the first type to retrieve the result set from a database; in accordance with a determination that the estimated query execution time and the estimated compilation time satisfy a second optimized compilation criterion: performing one or more optimization passes of a second type on the intermediate representation to form an optimized intermediate representation of a second type; compiling the optimized intermediate representation of the second type to form optimized executable machine code of the second type, wherein the optimized executable machine code of the second type has a lower execution time than the optimized executable machine code of the first type; and executing the optimized executable machine code of the second type to retrieve the result set from the database; and returning the result set.
Technical Overview & Description
RELATED APPLICATIONS This application is a continuation of U.S. patent application Ser. No. 17/371,023, filed Jul. 8, 2021, titled “ Optimizing Database Query Execution by Extending the Relational Algebra to Include Non-Standard Join Operators, ” which is a continuation of U.S. patent application Ser. No. 15/890,277, filed on Feb. 6, 2018, titled “ Optimizing Database Query Execution by Extending the Relational Algebra to Include Non-Standard Join Operators, ” now U.S. Pat. No. 11,068,520, which is a continuation-in-part of U.S. patent application Ser. No. 15/700,023, filed on Sep. 8, 2017, titled “ Adaptive Interpretation and Compilation of Database Queries, ” now U.S. Pat. No. 11,055,331, which claims priority to U.S. Provisional Application Ser. No. 62/532,959, filed on Jul. 14, 2017, titled “ Generating Adaptively Optimized Code for Database Queries, ” and also claims priority to U.S. Provisional Application Ser. No. 62/418,246, filed on Nov. 6, 2016, titled “ High Performance Relational Database System, ” each of which is incorporated by reference herein in its entirety. TECHNICAL FIELD The disclosed implementations relate generally to database systems, and more specifically to system features that improve query execution performance. BACKGROUND Data is commonly stored in a relational database and accessed by queries using a prescribed syntax (e.g., Structured Query Language (SQL)). SQL database query engines are normally designed to translate a database query into a relational algebra. In this relational algebra, joins are among the important relational operators and come in a number of variants, including inner joins; left, right, and full outer joins; semi joins; and anti-semi joins. These join variants are sufficient to express most database queries. However, subqueries can occur almost everywhere in a database query, and how a subquery is translated can have a significant impact on execution performance. A conventional approach is to model a database query
Cited By — Indexed Forward Citations (0 of 0 total)
No indexed citing patents in this generation yet. Ingest USPTO/PatentsView bulk citation tables via patents-ingest to expand the local forward citation graph.
References Cited — Backward Prior Art (46)
| Patent | Title | Year | Citations |
|---|
Non-Patent Literature (10)
- Neumann, Office Action, U.S. Appl. No. 15/700,023,.
- Neumann, Notice of Allowance, U.S. Appl. No. 15/700,023, Mar. 15, 2021, 9 pgs.
- Neumann, Office Action, U.S. Appl. No. 15/719,479, Feb. 20, 2018, 8 pgs.
- Neumann, Notice of Allowance, U.S. Appl. No. 15/719,479, Jul. 24, 2018, 10 pgs.
- Neumann, Pre-Interview First Office Action, U.S. Appl. No. 15/885,646, May 3, 2018, 5 pgs.
- Neumann, Notice of Allowance, U.S. Appl. No. 15/885,646, Jul. 18, 2018, 10 pgs.
- Neumann, Office Action, U.S. Appl. No. 16/134,919, Jan. 24, 2019, 12 pgs.
- Neumann, Notice of Allowance, U.S. Appl. No. 16/445,139, Sep. 17, 2019, 9 pgs.
- Neumann, Office Action, U.S. Appl. No. 16/726,737, Feb. 18, 2020, 9 pgs.
- Neumann, Notice of Allowance, U.S. Appl. No. 16/726,737, May 29, 2020, 9 pgs.