IP Library › Granted Patent US 9,063,973
Granted Patent B2
US 9,063,973 · App. 13/721,585 · Granted Jun 23, 2015

Method and apparatus for optimizing access path in database

Inventors: Patrick D. Bossman (Sarasota, FL); You-Chin Fuh (San Jose, CA); Ke W. Wei (Beijing, CN); Jing Zhou (Beijing, CN); Xiang Zhou (Beijing, CN)
Assignee: INTERNATIONAL BUSINESS MACHINES CORPORATION
G06F17/30424G06F17/30463
View Patent ↗
Loading inventors, assignments & file history…
Monitor This Case
Get email alerts when status or documents change.
Order Certified Copies
Most orders are placed with the USPTO same day — all within 24 business hours.
Order via The Patent Place →
Pre-filled with this patent's details
Quick Facts
Patent No.
US 9,063,973
App. No.
13/721,585
Granted
Jun 23, 2015
Kind
B2
Abstract

Apparatuses and methods for optimizing access path are provided. Execution of a query statement is sampled to obtain the information about a plurality of executing instances, the information about each executing instance comprises the literal value of the query statement in the instance and the filter factor corresponding to the literal value. The plurality of instances are grouped into a plurality of groups based on the filter factors corresponding to the literal values. The average filter factor of each group and the occurrence frequency of the group are obtained. The candidate access path created for the average filter factor of each group is accordingly obtained, and by taking the occurrence frequencies as weights, the weighted execution cost of each candidate access path is calculated for each group. The candidate access path with the minimum sum of the weighted execution costs for all groups is determined as the optimal access path.

Claims (68)

1. A method for optimizing an access path in a database, comprising:

sampling execution of a query statement to obtain information about a plurality of executing instances, wherein the information about each executing instance comprises a literal value of the query statement in the executing instance and a filter factor corresponding to the literal value;

grouping the plurality of executing instances into a plurality of groups based on the filter factors corresponding to the literal values, and obtaining an average filter factor of each group and an occurrence frequency of the group;

obtaining a candidate access path created for the average filter factor of each group; and

by taking the occurrence frequencies as weights, calculating a weighted execution cost of each candidate access path for each group, and determining the candidate access path with a minimum sum of the weighted execution costs for all groups as an optimal access path,

wherein said grouping the plurality of executing instances into a plurality of groups based on the filter factors corresponding to the literal values and obtaining the average filter factor of each group and the occurrence frequency of the group comprises:

classifying the plurality of obtained executing instances into a plurality of classes based on the literal values, and obtaining the filter factor and the occurrence frequency of each class; and

clustering the plurality of classes into a plurality of groups based on the filter factor of each class in the plurality of classes, and obtaining the average filter factor and the occurrence frequency of each group based on the filter factor and the occurrence frequency of every class, and

wherein said clustering the plurality of classes into a plurality of groups based on the filter factor of every class comprises one of the following steps:

clustering a portion of the plurality of classes for which distances among the filter factors are within a predetermined threshold into a same group; and

dividing values of the filter factors into a plurality of intervals, and clustering the portion of the plurality of classes whose filter factors belong to a same interval into the same group.

2. The method according to claim 1 , wherein said obtaining the information about a plurality of executing instances comprises obtaining the literal value of the query statement in each executing instance, and obtaining the filter factor corresponding to the literal value by at least one of:

referring to statistics information of a table that the query statement is directed to, and obtaining the filter factor according to the statistics information; and

executing a count statement for the query statement, and calculating the filter factor according to a result of executing the count statement.

3. The method according to claim 1 , wherein said classifying the plurality of obtained executing instances into a plurality of classes based on the literal values, and obtaining the filter factor and the occurrence frequency of each class, comprises:

classifying the plurality of obtained executing instances having the same literal value into a same class, regarding the filter factor corresponding to the same literal value as the filter factor of the class, and obtaining a usage frequency of the literal value as the occurrence frequency of the class.

4. The method according to claim 1 , wherein said grouping the plurality of executing instances into a plurality of groups based on the filter factors corresponding to the literal values, and obtaining the average filter factor of each group and the occurrence frequency of the group, comprises:

while scanning each executing instance, directly determining which group the executing instance should be put into based on the filter factor corresponding to the literal value;

during the process of putting the executing instances into corresponding groups, counting the number of executing instances in each group, and accumulating the filter factors; and

obtaining the occurrence frequency of the group based on the counting of the executing instances in each group, and obtaining the average filter factor of the group based on the accumulation of the filter factors.

5. The method according to claim 1 , wherein said calculating the weighted execution cost of each candidate access path for each group comprises:

obtaining the execution cost of each candidate access path for each group; and

multiplying the execution cost by the occurrence frequency of the corresponding group as a weight factor, thus obtaining the weighted execution cost of each candidate access path for each group.

6. The method according to claim 1 , further comprising: obtaining total execution costs of a combination of multiple candidate access paths, and comparing the total execution costs with other total execution costs of said optimal access path, thereby determining a most preferred access path.

7. The method according to claim 1 , wherein the query statement comprises two or more filter conditions, the literal value comprises a set of literal values, and the filter factor comprises a set of filter factors.

8. A method for optimizing an access path in a database, comprising:

sampling execution of a query statement to obtain information about a plurality of executing instances, wherein the information about each executing instance comprises a literal value of the query statement in the executing instance and a filter factor corresponding to the literal value;

grouping the plurality of executing instances into a plurality of groups based on the filter factors corresponding to the literal values, and obtaining an average filter factor of each group and an occurrence frequency of the group;

obtaining a candidate access path created for the average filter factor of each group; and

by taking the occurrence frequencies as weights, calculating a weighted execution cost of each candidate access path for each group, and determining the candidate access path with a minimum sum of the weighted execution costs for all groups as an optimal access path,

wherein said grouping the plurality of executing instances into a plurality of groups based on the filter factors corresponding to the literal values and obtaining the average filter factor of each group and the occurrence frequency of the group comprises:

classifying the plurality of obtained executing instances into a plurality of classes based on the literal values, and obtaining the filter factor and the occurrence frequency of each class; and

clustering the plurality of classes into a plurality of groups based on the filter factor of each class in the plurality of classes, and obtaining the average filter factor and the occurrence frequency of each group based on the filter factor and the occurrence frequency of every class, and

wherein said obtaining the average filter factor and the occurrence frequency of each group based on the filter factor and the occurrence frequency of each class comprises:

calculating the sum of the occurrence frequencies of the classes as the occurrence frequency of the group; and

calculating the average filter factor of the group by at least one of:

calculating an arithmetic mean of the filter factors of the classes as the average filter factor of the group; and

calculating a weighted mean of the filter factors of the classes as the average filter factor of the group by taking the relative occurrence frequencies of the classes in the group as weights.

9. An apparatus for optimizing an access path in a database, comprising:

an instance information obtaining unit configured to sample execution of a query statement to obtain information about a plurality of executing instances, wherein the information about each executing instance comprises a literal value of the query statement in the executing instance and a filter factor corresponding to the literal value;

a grouping unit configured to group the plurality of executing instances into a plurality of groups based on the filter factors corresponding to the literal values, and obtain an average filter factor of each group and an occurrence frequency of the group;

a candidate path obtaining unit configured to obtain a candidate access path created for the average filter factor of each group; and

an optimal path determining unit configured to, by taking the occurrence frequencies as weights, calculate a weighted execution cost of each candidate access path for each group, and determine the candidate access path with a minimum sum of the weighted execution costs for all groups as an optimal access path and

wherein the grouping unit comprises:

a classifying module configured to classify the plurality of obtained executing instances into a plurality of classes based on the literal values, and obtain the filter factor and the occurrence frequency of each class; and

a clustering module configured to cluster the plurality of classes into a plurality of groups based on the filter factor of each class in the plurality of classes, and obtain the average filter factor and the occurrence frequency of each group based on the filter factor and the occurrence frequency of every class, and

wherein the clustering module is configured to perform one of the following:

clustering a portion of the plurality of classes for which distances among the filter factors are within a predetermined threshold into a same group; and

dividing values of the filter factors into a plurality of intervals, and clustering the portion of the plurality of classes whose filter factors belong to a same interval into the same group.

10. The apparatus according to claim 9 , wherein the instance information obtaining unit is configured to obtain the literal value of the query statement in each executing instance, and obtain the filter factor corresponding to the literal value by at least one of:

referring to statistics information of a table that the query statement is directed to, and obtaining the filter factor according to the statistics information; and

executing a count statement for the query statement, and calculating the filter factor according to a result of executing the count statement.

11. The apparatus according to claim 9 , wherein the classifying module is configured to:

classify the plurality of obtained executing instances having the same literal value into a same class, regard the filter factor corresponding to the same literal value as the filter factor of the class, and obtain the usage frequency of the literal value as the occurrence frequency of the class.

12. The apparatus according to claim 9 , wherein the clustering module is configured to:

calculate a sum of the occurrence frequencies of the classes as the occurrence frequency of the group; and

calculate an average filter factor of the group by at least one of:

calculating an arithmetic mean of the filter factors of the classes as the average filter factor of the group; and

calculating a weighted mean of the filter factors of the classes as the average filter factor of the group by taking the relative occurrence frequencies of the classes in the group as weights.

13. The apparatus according to claim 9 , wherein the grouping unit is configured to:

while scanning each executing instance, directly determine which group the executing instance should be put into based on the filter factor corresponding to the literal value;

during the process of putting the executing instances into corresponding groups, count the number of executing instances in each group, and accumulate the filter factors; and

obtain the occurrence frequency of the group based on the counting of the executing instances in each group, and obtain the average filter factor of the group based on the accumulation of the filter factors.

14. The apparatus according to claim 9 , wherein the optimal path determining unit is configured to:

obtain the execution cost of each candidate access path for each group; and

multiply the execution cost by the occurrence frequency of the corresponding group as a weight factor, thus obtaining the weighted execution cost of each candidate access path for each group.

15. The apparatus according to claim 9 , further comprising: a multiple-paths determining unit configured to obtain the total execution costs of a combination of multiple candidate access paths, and compare the total execution costs with other total execution costs of said optimal access path, thereby determining a most preferred access path.

16. The apparatus according to claim 9 , wherein the query statement comprises two or more filter conditions, the literal value comprises a set of literal values, and the filter factor comprises a set of filter factors.

Assignments (1)
ASSIGNMENT OF ASSIGNOR'S INTEREST Recorded Dec 20, 2012
From: BOSSMAN, PATRICK D.; FUH, YOU-CHIN; WEI, KE W.; ZHOU, JING; ZHOU, XIANG
To: INTERNATIONAL BUSINESS MACHINES CORPORATION
Reel/Frame 029509/0301 →
Priority Claims (1)
CN 2011 1 0430263 · Dec 20, 2011 · national
Continuity (1)
Related Publication 20130159321A1 · Jun 20, 2013