# US 2022/0284023 A1 · Estimating computational cost for database queries

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

- Number: US 2022/0284023 A1
- Document ID: US20220284023A1
- Status: Published application
- Kind: A1
- Application number: 17/192,946
- Filed: 2021-03-05
- Published: 2022-09-08
- Earliest claimed: 2021-03-05
- Assignees: International Business Machines Corporation
- Applicants: International Business Machines Corporation
- Inventors: Shuo Li; Xiaobo Wang; Sheng Yan Sun; Li Cao; Xin Peng Liu
- Web page: https://patentgrep.com/patent/US20220284023A1

## CPC

- G06F 16/24542: {Plan optimisation}
- G06F 11/3419: {by assessing time}
- G06F 16/24537: {of operators}
- G06N 20/00: Machine learning
- G06F 11/3447: {Performance evaluation by modeling}
- G06F 2201/80: Database-specific techniques
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)
- G06N: COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS

## Abstract

A computer-implemented method to estimate computing cost of database queries. The method includes receiving a query. The method also includes generating one or more access plans for the query. The method further includes dynamically generating a learning model based on each of the generated access plans. The method includes estimating, by the learning model and for each of the one or more access plans, a predicted cost to execute the query. The method includes selecting, based on the predicted cost, a first access path associated with a lowest cost of the predicted costs and executing the query according the selected access path.

## Claims

### Claim 1

A computer-implemented method comprising:
receiving a query;
generating one or more access plans for the query;
dynamically generating, for each of the one or more access plans, a learning model based on each access plan;
estimating, by the learning model, for each of the one or more access plans, a predicted resource cost to execute the query;
selecting, based on the predicted resource cost, a first access path associated with a lowest resource cost of the predicted resource costs; and
executing the query according to the first access path.

### Claim 2 (depends on 1)

The method of claim 1, further comprising:
extracting, for each of the one or more access plans, a set of mini plans, wherein each mini plan has an associated command in the query and each mini plan is associated with at least one mini model.

### Claim 3 (depends on 2)

The method of claim 2, wherein each mini plan is associated with a first mini model configured to estimate a resource cost to perform the associated command, and a second mini model configured to estimate a number of qualified rows for the associated command.

### Claim 4 (depends on 3)

The method of claim 3, wherein the generating of the learning model includes stacking each mini model for each mini plan of the access path.

### Claim 5 (depends on 4)

The method of claim 4, wherein the learning model is a nested layer model.

### Claim 6 (depends on 3)

The method of claim 3, wherein each mini plan is associated with a command selected from the group consisting of a database access, an index scan, a join command, a delete command, an insert command, and an update command.

### Claim 7 (depends on 3)

The method of claim 3, wherein the estimating further comprises:
obtaining an estimated resource cost from the first mini model of each mini plan of an access path; and
adding each estimated resource cost to obtain a total estimated resource cost.

### Claim 8 (depends on 3)

The method of claim 3, wherein an output of the second mini model for a first mini plan is an input to the first mini model of a second mini plan.

### Claim 9 (depends on 1)

The method of claim 1, further comprising:
building a plurality of mini models, wherein each mini model of the plurality of mini models is associated with a query command;
training each model of the plurality of models; and
deploying each model of the plurality of models.

### Claim 10 (depends on 1)

The method of claim 1, further comprising:
selecting a second access path;
executing the second access path;
storing, for the first access path and for the second access path, a set of execution data; and
updating, based on each set of execution data, the plurality of mini models.

### Claim 11

A system comprising:
a processor; and
a computer-readable storage medium communicatively coupled to the processor and storing program instructions which, when executed by the processor, are configured to cause the processor to:
receive a query;
generate one or more access plans for the query;
dynamically generate, for each of the one or more access plans, a learning model based on each access plan;
estimate, by the learning model, for each of the one or more access plans, a predicted resource cost to execute the query;
select, based on the predicted resource cost, a first access path associated with a lowest resource cost of the predicted resource costs; and
execute the query according to the first access path.

### Claim 12 (depends on 11)

The system of claim 11, wherein the program instructions are further configured to cause the processor to:
extract, for each of the one or more access plans; a set of mini plans, wherein each mini plan has an associated command in the query and each mini plan is associated with at least one mini model.

### Claim 13 (depends on 12)

The system of claim 12, wherein each mini plan is associated with a first mini model configured to estimate a resource cost to perform the associated command, and a second mini model configured to estimate a number of qualified rows for the associated command.

### Claim 14 (depends on 13)

The system of claim 13, wherein the generation of the learning model includes stacking each mini model for each mini plan of the access path.

### Claim 15 (depends on 14)

The system of claim 14, wherein the learning model is a nested layer model.

### Claim 16

A computer program product, the computer program product comprising a computer readable storage medium having program instructions embodied therewith, the program instructions executable by a processing unit to cause the processing unit to:
receive a query;
generate one or more access plans for the query;
dynamically generate, for each of the one or more access plans, a learning model based on each access plan;
estimate, by the learning model, for each of the one or more access plans, a predicted resource cost to execute the query;
select, based on the predicted resource cost, a first access path associated with a lowest resource cost of the predicted resource costs; and
execute the query according to the first access path.

### Claim 17 (depends on 16)

The computer program product of claim 16, wherein the program instructions are further configured to cause the processing unit to:
extract, for each of the one or more access plans; a set of mini plans, wherein each mini plan has an associated command in the query and each mini plan is associated with at least one mini model.

### Claim 18 (depends on 17)

The computer program product of claim 17, wherein each mini plan is associated with a first mini model configured to estimate a resource cost to perform the associated command, and a second mini model configured to estimate a number of qualified rows for the associated command.

### Claim 19 (depends on 18)

The computer program product of claim 18, wherein the generation of the learning model includes stacking each mini model for each mini plan of the access path.

### Claim 20 (depends on 19)

The computer program product of claim 19, wherein the learning model is a nested layer model.
