1. Field of the Invention
This invention generally relates to database systems, and more specifically relates to an apparatus and method for optimizing database queries.
2. Background Art
Database systems have been developed that allow a computer to store a large amount of information in a way that allows a user to search for and retrieve specific information in the database. For example, an insurance company may have a database that includes all of its policy holders and their current account information, including payment history, premium amount, policy number, policy type, exclusions to coverage, etc. A database system allows the insurance company to retrieve the account information for a single policy holder among the thousands and perhaps millions of policy holders in its database.
Retrieval of information from a database is typically done using queries. A query usually specifies conditions that apply to one or more columns of the database, and may specify relatively complex logical operations on multiple columns. The database is searched for records that satisfy the query, and those records are returned as the query result.
Queries are typically optimized by generating an access plan that will speed their execution. The work required to generate an access plan is greatly increased for a query to a partitioned database table, where multiple partitions are defined that collectively make up the overall database table. Sometimes the increased work for optimizing a query to a partitioned database table negates the desired performance enhancement that drove the partitioning of the database in the first place. Without a way to improve the efficiency of queries to partitioned database tables, existing database systems will suffer from reduced performance when optimizing queries to partitioned database tables.
According to the preferred embodiments, a query optimizer optimizes a query to a partitioned database table by determining common characteristics of the partitions and generating a virtual maintained temporary index that spans multiple partitions. Using the virtual maintained temporary index allows the query optimizer to generate an access plan based on the virtual maintained temporary index. This relieves the optimizer from having to individually optimize access to each partition for partitions that share common characteristics, or from optimizing the query using a common strategy for all of the partitions.
The foregoing and other features and advantages of the invention will be apparent from the following more particular description of preferred embodiments of the invention, as illustrated in the accompanying drawings.
The preferred embodiments of the present invention will hereinafter be described in conjunction with the appended drawings, where like designations denote like elements, and:
The present invention relates to optimizing database queries to partitioned database tables. For those not familiar with databases, queries, or partitioned database tables, this Overview section will provide background information that will help to understand the present invention.
Known Databases and Database Queries
There are many different types of databases known in the art. The most common is known as a relational database (RDB), which organizes data in tables that have rows that represent individual entries or records in the database, and columns that define what is stored in each entry or record.
To be useful, the data stored in databases must be able to be efficiently retrieved. The most common way to retrieve data from a database is to generate a database query. A database query is an expression that is evaluated by a database manager. The expression may contain one or more predicate expressions that are used to retrieve data from a database. For example, let's assume there is a database for a company that includes a table of employees, with columns in the table that represent the employee's name, address, phone number, gender, and salary. With data stored in this format, a query could be formulated that would retrieve the records for all female employees that have a salary greater than $40,000. Similarly, a query could be formulated that would retrieve the records for all employees that have a particular area code or telephone prefix.
One popular way to define a query uses Structured Query Language (SQL). SQL defines a syntax for generating and processing queries that is independent of the actual structure and format of the database. One sample SQL query is shown in
Known Query Optimizers
In the prior art, a tool known as a query optimizer evaluates expressions in a query. Indexes may be created and used in the access plan to speed the execution of a query. Some database systems allow storing the results of a query, and returning those results when the query is repeated. While this speeds up the execution of the query, the stored results may be stale due to changes in the database that were made since the last time the query was run. As a result, some applications require “live data”, which means the database must be queried each time, thereby eliminating any performance improvement that might otherwise result from using previously-retrieved result sets. The use of indexes becomes even more important when live data is required.
Known Partitioned Database Tables
A partitioned database table is divided into multiple discrete portions referred to as partitions. Each entry in the table is allocated to a respective one of the partitions. A partition is usually a discrete data entry, such as a file, but contains the same definitional structure as all other partitions of the same table. Partitioning may be performed for a variety of reasons, and is usually performed on very large tables as a way to break the data into subsets of some conveniently workable size. By dividing a table into partitions, improved execution efficiency can result by working with a smaller subset of the table instead of the whole table.
The optimization of a query becomes more difficult when the query is to a partitioned database table in live data mode. A query optimizer typically analyzes and constructs an independent access plan for each partition, then performs a UNION operation on those respective access plans to produce an overall access plan for the query. For a partitioned table that includes six partitions, the query optimizer will separately optimize the access plan for each of the six partitions, even if the characteristics of the partitions are similar. The result is substantial overhead for the query optimizer in separately optimizing access to each partition, even when the characteristics of the partitions are similar. In fact, the overhead of constructing a separate and independent access plan for each partition can well outweigh the benefits of improved execution efficiency that results from having the multiple partitions in the first place. In the alternative, the query optimizer may optimize the partitions of the partitioned table as one entity, which means an access plan may work well for some partitions and poorly for others.
A query optimizer generates an access plan for a query to a partitioned database table by determining common characteristics of the partitions and generating a virtual maintained temporary index that spans multiple partitions. Using the virtual maintained temporary index allows the query optimizer to generate an access plan based on the virtual maintained temporary index, which relieves the optimizer from having to individually optimize access to each partition for partitions that share common characteristics, and allows it to avoid grouping partitions better suited for indexing plans into non-indexed groups.
Referring to
Main memory 120 in accordance with the preferred embodiments contains data 121, an operating system 122, a database 123, and a query optimizer 126. Data 121 represents any data that serves as input to or output from any program in computer system 100. Operating system 122 is a multitasking operating system known in the industry as i5/OS; however, those skilled in the art will appreciate that the spirit and scope of the present invention is not limited to any one operating system. Database 123 is any suitable database that includes tables, whether currently known or developed in the future. Database 123 preferably includes a partitioned table 124 that is spread over multiple partitions, shown in
Computer system 100 utilizes well known virtual addressing mechanisms that allow the programs of computer system 100 to behave as if they only have access to a large, single storage entity instead of access to multiple, smaller storage entities such as main memory 120 and DASD device 155. Therefore, while data 121, operating system 122, database 123, and query optimizer 126 are shown to reside in main memory 120, those skilled in the art will recognize that these items are not necessarily all completely contained in main memory 120 at the same time. It should also be noted that the term “memory” is used herein generically to refer to the entire virtual memory of computer system 100, and may include the virtual memory of other computer systems coupled to computer system 100.
Processor 110 may be constructed from one or more microprocessors and/or integrated circuits. Processor 110 executes program instructions stored in main memory 120. Main memory 120 stores programs and data that processor 110 may access. When computer system 100 starts up, processor 110 initially executes the program instructions that make up operating system 122.
Although computer system 100 is shown to contain only a single processor and a single system bus, those skilled in the art will appreciate that the present invention may be practiced using a computer system that has multiple processors and/or multiple buses. In addition, the interfaces that are used in the preferred embodiments each include separate, fully programmed microprocessors that are used to off-load compute-intensive processing from processor 110. However, those skilled in the art will appreciate that the present invention applies equally to computer systems that simply use I/O adapters to perform similar functions.
Display interface 140 is used to directly connect one or more displays 165 to computer system 100. These displays 165, which may be non-intelligent (i.e., dumb) terminals or fully programmable workstations, are used to allow system administrators and users to communicate with computer system 100. Note, however, that while display interface 140 is provided to support communication with one or more displays 165, computer system 100 does not necessarily require a display 165, because all needed interaction with users and other processes may occur via network interface 150.
Network interface 150 is used to connect other computer systems and/or workstations (e.g., 175 in
At this point, it is important to note that while the present invention has been and will continue to be described in the context of a fully functional computer system, those skilled in the art will appreciate that the present invention is capable of being distributed as a program product in a variety of forms, and that the present invention applies equally regardless of the particular type of computer-readable media used to actually carry out the distribution. Examples of suitable computer-readable media include: recordable media such as floppy disks and CD-RW (e.g., 195 of
An example is now presented to illustrate how maintained temporary indexes were used in the prior art to provide a context for understanding the differences between the prior art and the preferred embodiments described herein. Referring to
The disadvantage of the prior art query optimizer in live data mode is that each query to each partition is treated as a separate sub-query that must be separately optimized. Thus, in
We now assume the same query in
One of the important features of the preferred embodiments is the ability to optimize a query to a partitioned database table when live data is required using a virtual maintained temporary index that spans multiple partitions. Once the partition is optimized, the back-end of the optimizer may actually implement the virtual maintained temporary index in different ways. For example, referring to
Note that the term “common characteristics” includes any suitable characteristic of a partition that can be measured and compared with any suitable characteristics of another partition. Suitable characteristics include: number of records, “last updated” timestamp, selectivity when a predicate is applied, etc. The preferred embodiments expressly extend to any suitable characteristics of a partition, and any suitable heuristic for comparing characteristics of different partitions to determine whether or not the partitions share common characteristics.
Referring to
One of the advantages of creating a VMTI is that, once created, the access plans for multiple queries may reference the VMTI. Referring to
The preferred embodiments simplify the work of a query processor by grouping partitions of a partitioned database table according to common characteristics, then creating a virtual maintained temporary index that spans multiple partitions. The virtual maintained temporary index is then referenced in the access plan, which allows the query optimizer to avoid the work of separately optimizing accesses to each of the multiple partitions that share the common characteristics. The result is improved performance for a query optimizer.
One skilled in the art will appreciate that many variations are possible within the scope of the present invention. Thus, while the invention has been particularly shown and described with reference to preferred embodiments thereof, it will be understood by those skilled in the art that these and other changes in form and details may be made therein without departing from the spirit and scope of the invention.
This patent application is a continuation of U.S. Ser. No. 11/388,004 filed on Sep. 23, 2006, which is incorporated herein by reference.
Number | Name | Date | Kind |
---|---|---|---|
6289334 | Reiner et al. | Sep 2001 | B1 |
6990503 | Luo et al. | Jan 2006 | B1 |
7149737 | Luo et al. | Dec 2006 | B1 |
7299239 | Basu et al. | Nov 2007 | B1 |
20030088579 | Brown et al. | May 2003 | A1 |
20040249845 | Das | Dec 2004 | A1 |
20060010170 | Lashley et al. | Jan 2006 | A1 |
20060136368 | Young-Lai et al. | Jun 2006 | A1 |
20060206507 | Dahbour | Sep 2006 | A1 |
20070016588 | Bestgen et al. | Jan 2007 | A1 |
20070250511 | Bestget et al. | Oct 2007 | A1 |
Entry |
---|
S. Hong et al., “Efficient Execution of Range-Aggregate Queries,” http://citeseer.ist.psu.edu/hongO1efficient.html. |
A. Guttman, “R-trees: A Dynamic Index Structure for Spatial Searching,” Proc. ACM SIGMOND Int. Conf. on Management of Data, http://citeseer.ist.psu.edu/context/46230/0. |
A. Guttman, “A Dynamic Index Structure for Spatial Searching,” http://portal.acm.org/citation.cfm?coll=GUIDE&dl=GUIDE&id=48790. |
B. Yormark, “ACM SIGMOND Conference 1984: Boston, Massachusetts,” http://www.informatik.uni-trier.de/%7Eley/db/conf/sigmod/sigmod84.html#Guttman84. |
Number | Date | Country | |
---|---|---|---|
20080215540 A1 | Sep 2008 | US |
Number | Date | Country | |
---|---|---|---|
Parent | 11388004 | Mar 2006 | US |
Child | 12120582 | US |