# US 2021/0334298 A1 · Adaptive Interpretation and Compilation of Database Queries

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 2021/0334298 A1
- Document ID: US20210334298A1
- Status: Published application
- Kind: A1
- Application number: 17/368,767
- Filed: 2021-07-06
- Published: 2021-10-28
- Earliest claimed: 2016-11-06
- Assignees: Tableau Software, Inc.
- Applicants: Tableau Software, Inc.
- Inventors: Thomas NEUMANN; Viktor Leis; Alfons Kemper; Tobias MUEHLBAUER; Jan Finis
- Web page: https://patentgrep.com/patent/US20210334298A1

## CPC

- G06F 16/24534: {Query rewriting; Transformation}
- G06F 16/3332: Query translation
- G06F 16/23: Updating
- G06F 16/334: Query execution (filtering based on additional data G06F16/335)
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## 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.

## Claims

### Claim 1

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;
determining an estimated query execution time for executing the database query and an estimated compilation time for at least partially compiling the database query;
in accordance with a determination that the estimated query execution time and the estimated compilation time satisfy an interpretation criterion, invoking a byte code interpreter to retrieve a result set from the database;
in accordance with a determination that the estimated query execution time and the estimated compilation time satisfy a compilation criterion, compiling an intermediate representation of the database query, and executing a compiled representation 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 an optimized compilation criterion, optimizing and compiling the intermediate representation of the database query, and executing an optimized and compiled representation to retrieve the result set from the database.

### Claim 2 (depends on 1)

The method of claim 1, further comprising translating the database query into the intermediate representation, wherein the intermediate representation is specified in low level virtual machine (LLVM) code.

### Claim 3 (depends on 1)

The method of claim 1, wherein computing the estimated compilation time is based on at least one of a number of instructions, types of instructions, a number of functions, and a number of execution blocks in the intermediate representation, wherein each block comprises a maximal contiguous sequence of instructions without a jump instruction.

### Claim 4 (depends on 1)

The method of claim 1, wherein the interpretation criterion, the compilation criterion, and the optimized compilation criterion are determined using one or more test databases and a plurality of test database queries prior to receiving the database query.

### Claim 5 (depends on 1)

The method of claim 1, wherein the estimated query execution time is determined according to an estimated number of rows that will be accessed to retrieve the result set corresponding to the database query, and the interpretation criterion is satisfied when the estimated number of rows that will be accessed to retrieve the result set is less than or equal to a first threshold.

### Claim 6 (depends on 5)

The method of claim 5, wherein the compilation criterion is satisfied when the estimated number of rows that will be accessed to retrieve the result set is greater than the first threshold but less than a second threshold.

### Claim 7 (depends on 6)

The method of claim 6, wherein the 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 8 (depends on 1)

The method of claim 1, wherein the interpretation criterion, the compilation criterion, and the optimized compilation criterion are mutually exclusive.

### Claim 9 (depends on 1)

The method of claim 1, wherein, when the interpretation criterion is satisfied, the compilation criterion and the optimized compilation criterion are not evaluated.

### Claim 10 (depends on 1)

The method of claim 1, further comprising computing a ratio of the estimated execution time and the estimated query compilation time, wherein:
the interpretation criterion comprises a rule that the ratio is less than a first threshold;
the compilation criterion comprises a rule that the ratio is greater than a first threshold but less than a second threshold; and
the optimized compilation criterion comprises a rule that the ratio is greater than the second threshold.

### Claim 11 (depends on 1)

The method of claim 1, wherein the interpretation criterion, the compilation criterion, and the optimized compilation criterion partition a set of all pairs (e, c) of estimated query execution time and estimated compilation time into three disjoint regions.

### Claim 12 (depends on 1)

The method of claim 1, wherein the database query is written in SQL.

### Claim 13

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;
determining an estimated query execution time for executing the database query and an estimated compilation time for at least partially compiling the database query;
in accordance with a determination that the estimated query execution time and the estimated compilation time satisfy an interpretation criterion, invoking a byte code interpreter to retrieve a result set from the database;
in accordance with a determination that the estimated query execution time and the estimated compilation time satisfy a compilation criterion: compiling an intermediate representation of the database query, and executing a compiled representation 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 an optimized compilation criterion: optimizing and compiling the intermediate representation of the database query, and executing an optimized and compiled representation to retrieve the result set from the database.

### Claim 14 (depends on 13)

The computer system of claim 13, 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 15 (depends on 13)

The computer system of claim 13, wherein:
the estimated query execution time is determined according to an estimated number of rows that will be accessed to retrieve the result set corresponding to the database query;
the interpretation criterion is satisfied when the estimated number of rows that will be accessed to retrieve the result set is less than or equal to a first threshold;
the compilation criterion is satisfied when the estimated number of rows that will be accessed to retrieve the result set is greater than the first threshold but less than a second threshold; and
the 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 16 (depends on 13)

The computer system of claim 13, further comprising computing a ratio of the estimated execution time and the estimated query compilation time, wherein:
the interpretation criterion comprises a rule that the ratio is less than a first threshold;
the compilation criterion comprises a rule that the ratio is greater than a first threshold but less than a second threshold; and
the optimized compilation criterion comprises a rule that the ratio is greater than the second threshold.

### Claim 17

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;
determining an estimated query execution time for executing the database query and an estimated compilation time for at least partially compiling the database query;
in accordance with a determination that the estimated query execution time and the estimated compilation time satisfy an interpretation criterion, invoking a byte code interpreter to retrieve a result set from the database;
in accordance with a determination that the estimated query execution time and the estimated compilation time satisfy a compilation criterion: compiling an intermediate representation of the database query, and executing a compiled representation 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 an optimized compilation criterion: optimizing and compiling the intermediate representation of the database query, and executing an optimized and compiled representation to retrieve the result set from the database.

### Claim 18 (depends on 17)

The non-transitory computer readable storage medium of claim 17, wherein the one or more programs comprise instructions for translating the database query into the intermediate representation, and the estimated compilation time is determined for compiling the intermediate representation into machine executable code according to a size of the intermediate representation.

### Claim 19 (depends on 17)

The non-transitory computer readable storage medium of claim 17, wherein the instructions for optimizing and compiling the intermediate representation of the database query further comprise instructions for:
performing one or more optimization passes on the intermediate representation to form an optimized intermediate representation; and
compiling the optimized intermediate representation to the compiled and optimized representation.

### Claim 20 (depends on 17)

The non-transitory computer readable storage medium of claim 17, wherein the one or more programs comprise instructions for translating the database query into the intermediate representation, and the byte code interpreter is invoked to interpret the intermediate representation.
