Query optimization by sub-plan memoization
First Claim
1. An iterative process for optimizing a query to produce an optimized query execution plan for a database comprising the steps of:
- a) initializing a sub-plan memo data structure for storing data concerning multiple sub-plans that form parts of potential query execution plans;
b) optimizing an input query to produce a first set of sub-plans, which when executed produce result record sets from the database;
c) forming a sub-plan query statement for each of the sub-plans that make up the first set of query execution sub-plans;
d) executing each of the sub-plan query statements on the database and storing a result of said execution in the sub-plan memo data structure for use in producing a final query execution plan for answering the input query; and
e) creating a different set of query sub-plans using a result stored in the sub-plan memo data structure and using said query sub-plans to create one or more additional sub-plan query statements which are then executed over the database.
2 Assignments
0 Petitions
Accused Products
Abstract
Database system query optimizers use several techniques such as histograms and sampling to estimate the result sizes of operators and sub-plans (operator trees) and the number of distinct values in their outputs. Instead of estimates, the invention uses the exact actual values of the result sizes and the number of distinct values in the outputs of sub-plans encountered by the optimizer. This is achieved by optimizing the query in phases. In each phase, newly encountered sub-plans are recorded for which result size and/or distinct value estimates are required. These sub-plans are executed at the end of the phase to determine their actual result sizes and the actual number of distinct values in their outputs. In subsequent phases, the optimizer uses these actual values when it encounters the same sub-plan again.
-
Citations
26 Claims
-
1. An iterative process for optimizing a query to produce an optimized query execution plan for a database comprising the steps of:
-
a) initializing a sub-plan memo data structure for storing data concerning multiple sub-plans that form parts of potential query execution plans;
b) optimizing an input query to produce a first set of sub-plans, which when executed produce result record sets from the database;
c) forming a sub-plan query statement for each of the sub-plans that make up the first set of query execution sub-plans;
d) executing each of the sub-plan query statements on the database and storing a result of said execution in the sub-plan memo data structure for use in producing a final query execution plan for answering the input query; and
e) creating a different set of query sub-plans using a result stored in the sub-plan memo data structure and using said query sub-plans to create one or more additional sub-plan query statements which are then executed over the database. - View Dependent Claims (2, 3, 4, 5, 6, 7)
-
-
8. Computer apparatus for executing a query comprising:
-
a) a computer input for receiving a user query;
b) a computer memory containing a sub-plan memo data structure for storing data concerning multiple sub-plans that form parts of potential query execution plans for answering the user query;
c) an optimizer component for evaluating an input query to produce a first set of sub-plans, which when executed produce result record sets from the database;
d) said optimizer component including means for forming a sub-plan query statement for each of the sub-plans that make up the first set of query execution sub-plans;
e) a query execution component for executing each of the sub-plan query statements on the database and storing a result of said execution in the sub-plan memo data structure for use in producing a final query execution plan for answering the input query; and
f) said optimizer component including means to create a different set of query sub-plans using the results stored in the sub-plan memo data structure. - View Dependent Claims (9, 10, 11, 12, 13)
-
-
14. The apparatus of claim wherein the optimizer uses data from the catalog to produce a sub-plan execution solution for at least some of the sub-plans in said first set of sub-plans.
-
15. A computer readable medium containing instructions for optimizing a query execution plan for a database comprising instructions for:
-
a) initializing a sub-plan memo data structure for storing data concerning multiple sub-plans that form parts of potential query execution plans;
b) evaluating an input query to produce a first set of sub-plans, which when executed produce result record sets from the database;
c) forming a sub-plan query statement for each of the sub-plans that make up the first set of query execution sub-plans;
d) executing each of the sub-plan query statements on the database and storing a result of said execution in the sub-plan memo data structure for use in producing a final query execution plan for answering the input query; and
e) creating a different set of query sub-plans using a result stored in the sub-plan memo data structure and using said query sub-plans to create one or more additional sub-plan query statements which are then executed over the database. - View Dependent Claims (16, 17, 18, 19, 20, 21, 22)
-
-
23. An iterative process for optimizing a query to produce an optimized query execution plan for a database comprising the steps of:
-
a) initializing a sub-plan memo data structure for storing data concerning multiple sub-plans that form parts of potential query execution plans;
b) optimizing an input query to produce a first set of sub-plans, which when executed produce result record sets from the database;
c) forming a sub-plan query statement for each of the sub-plans that make up the first set of query execution sub-plans;
d) executing each of the sub-plan query statements on the database and storing a result of said execution in the sub-plan memo data structure for use in producing a final query execution plan for answering the input query; and
e) performing a series of optimization iterations in which additional sub-plans are added to the first set of query execution sub-plans until the number of optimization iterations reaches a specified number or until no sub-plan query statements are added to the sub-plan memo data structure.
-
-
24. A computer readable medium having instructions for optimizing a query to produce an optimized query execution plan for a database comprising instructions for:
-
a) initializing a sub-plan memo data structure for storing data concerning multiple sub-plans that form parts of potential query execution plans;
b) optimizing an input query to produce a first set of sub-plans, which when executed produce result record sets from the database;
c) forming a sub-plan query statement for each of the sub-plans that make up the first set of query execution sub-plans;
d) executing each of the sub-plan query statements on the database and storing a result of said execution in the sub-plan memo data structure for use in producing a final query execution plan for answering the input query; and
e) performing a series of optimization iterations in which additional sub-plans are added to the first set of query execution sub-plans until the number of optimization iterations reaches a specified number or until no sub-plan query statements are added to the sub-plan memo data structure.
-
-
25. A process for optimizing a query to produce a query execution plan for a database comprising the steps of:
-
a) initializing a sub-plan memo data structure for storing data concerning multiple sub-plans that form parts of potential query execution plans;
b) optimizing an input query to produce a first set of sub-plans, which when executed produce result record sets from the database;
c) forming a sub-plan query statement for each of the sub-plans that make up the first set of query execution sub-plans; and
d) executing each of the sub-plan query statements on the database and storing a result of said execution in the sub-plan memo data structure including a hash table wherein the query for a given sub-plan is a key for accessing contents of said hash table relating to result size and number of distinct values from execution of the query for said sub-plan for use in producing a final query execution plan for answering the input query.
-
-
26. A computer readable medium having instructions for optimizing a query to produce a query execution plan for a database comprising instructions for:
-
a) initializing a sub-plan memo data structure for storing data concerning multiple sub-plans that form parts of potential query execution plans;
b) optimizing an input query to produce a first set of sub-plans, which when executed produce result record sets from the database;
c) forming a sub-plan query statement for each of the sub-plans that make up the first set of query execution sub-plans; and
d) executing each of the sub-plan query statements on the database and storing a result of said execution in the sub-plan memo data structure including a hash table wherein the query for a given sub-plan is a key for accessing contents of said hash table relating to result size and number of distinct values from execution of the query for said sub-plan for use in producing a final query execution plan for answering the input query.
-
Specification