Relational database management system (RDBMS) use queries to aggregate huge amounts of data in order to present a relatively small result. One use of an RDBMS can be found in a business warehouse (BW) data storage and processing system on which business intelligence (BI) queries are received and processed. In RDBMS queries employing system query language (SQL), for example, two parameters can be identified that generally characterize such queries:
QDBSEL: represents the number of rows that contribute to the result; initially, these are all rows from tables listed in the FROM clause, but then restricted by the WHERE clause of the SQL query.
QBTRANS: represents the number of rows in the query result. QDBTRANS≦QDBSEL holds in general, but typically QDBTRANS is far less than QDBSEL because the rows identified through the FROM and WHERE clauses are usually aggregated by a GROUP BY function.
Consider the data in table T in
SELECT Division, SUM(Quantity) AS “Quan”
FROM T
WHERE Country=‘IT’
GROUP BY Division (Q1)
For some queries, it may be sufficient to get a rough estimate rather than a precise result, particularly if trends and estimates are the focus of the query instead of exact values. To that end, rather than operating on the full set of data, such queries can run on a sample of the data which is typically much smaller.
SELECT Division, SUM(Quantity)*100 AS “Quan”
FROM T
WHERE Country=‘IT’ AND Sample=1
GROUP BY Division (Q2)
This transformation assumes that the sample involves 1% of the rows of T. Thus this query would return values in the result column “Quan” that are an approximation of the actual values which might be sufficient for the purpose of the query. The difference is that QDBSEL(Q2)≈QDBSEL(Q1)/100, while QDBTRANS(Q2)≈QDBTRANS(Q1). One challenge is to translate the lower value for QDBSEL(Q2) into improved performance for the user.
Such performance improvements are not always realized for a number of reasons. Typically, the physical storage of commercial a RDBMS is managed based on blocks or pages. Accordingly, in a worst case each block of T holds a row that is part of the sample (i.e. with Sample=1). This means that all blocks (i.e. all rows) of T are read from the disk which provides a query run time for Q2 that is approximately the same as for Q1. At the other extreme is a situation in which the sample is spread over a few blocks. In this case, a significantly better run time can be expected.
Recently, however, many commercial RDBMSs have introduced a functionality to allow row-level or block-level sampling at query run time. As such, the following queries Q3 and Q4 can be expressed as follows to be substantially equivalent to Q2 above:
SELECT Division, SUM(Quantity)*100 AS “Quan”
FROM T TABLESAMPLE BERNOULLI (1.0)
WHERE Country=‘T’
GROUP BY Division (Q3)
SELECT Division, SUM(Quantity)*100 AS “Quan”
FROM T TABLESAMPLE SYSTEM (1.0)
WHERE Country=‘IT’
GROUP BY Division (Q4)
While Q3 calculates a result based on a row-level sample, Q4 provides a result based on a block-level sample. Typically, the result of Q3 gives a better approximation than the result of Q4; however, Q3 is likely to run longer than Q4 because of more input/output (I/O) operations to and from the disk.
This document discloses systems and methods for optimizing queries on a relational database, particularly in a business intelligence system. In one embodiment, a system includes table T stored in the database. The table T can have X number of columns and Y number of rows, or any number of dimensions. The system further includes a sample generator configured to generate a sampling column having Y cells. Each cell includes a sampling value for each of the Y rows in the table T. The sample generator is further configured to append the sampling column to the table T in the database.
In accordance with another embodiment, a method includes providing a table T in the database, the table T having X number of columns and Y number of rows. The method further includes generating a sampling column having Y cells, wherein each cell includes a sampling value for each of the Y rows in the table T. The method further includes appending the sampling column to the table T in the database.
The details of one or more embodiments are set forth in the accompanying drawings and the description below. Other features and advantages will be apparent from the description and drawings, and from the claims.
These and other aspects will now be described in detail with reference to the following drawings.
Like reference symbols in the various drawings indicate like elements.
A system and method are disclosed for improved queries of a relational databases. The system and method combine the advantages, among others, of row-level and block-level sampling to achieve faster query results and other improved performance.
At 304, a column Sample is physically added to the table T. This column can hold various values, such as “0” (i.e. the associated row is not part of the sample) or “1” (i.e. the associated row is part of the sample). Any data type and/or range of values may be used. For instance, in one exemplary embodiment, more than two values can be used in order to create a set of samples, e.g. “0”=not part of any sample, “1” =part of a first sample, “2”=part of second sample. Alternatively, a bitwise encoding scheme can be used to allow a row to form a part of more than one sample.
At 306, a decision may be made whether to add new rows to table T. If rows are added to T at 308, the rows will hold a value in column Sample that has been set either by the user or by the system. For example, the system may automatically set a value of an added row through a trigger or through some application code such as update rules in a BW system.
At 310, table T is clustered along column Sample according to a process in which rows with the same value in column Sample are physically stored in close proximity on a storage medium. This can be achieved by several mechanisms in commercial RDBMSs. For example, in one type of RDBMS, the table T can be partitioned along column Sample, such as by using a range, list, or composite partitioning. Another type of RDBMS offers a multidimensional clustering (MDC) tool. At 312, a decision may be made whether to add an index for column Sample, or incorporate the column Sample into an existing index or indices. In an alternative embodiment, at 314, an index for the column Sample can be added, or the column Sample can be incorporated into one or more existing indices.
At 316, a decision is made whether to use a sample (or in the presence of a variety of samples, which sample) for the query. The decision can be executed by asking the user whether the sample is to be used. In a system employing two or more samples, the user may also designate which sample to use. In an exemplary embodiment, e.g. within an SAP BW BEX query designer, a user interface is provided to request the input from the user. In the case in which a specific sample should be used, the underlying WHERE clause of the query is extended in the fashion shown in query Q2. In a non-SQL-based approach, like MDX (multi-dimensional expressions) or XML/A (XML (extensible markup language) for analysis), a corresponding filter condition is added for the column Sample, where the “column” is represented as a dimension or dimension level. If a sample is to be used, at 318 the query is executed using the column Sample, whether or not the column Sample is indexed. Otherwise, at 320 the query is executed without sampling.
The query system 410 includes a query engine 412 configured to receive and process queries from the user interface 402, and aggregate and report results based on the query back to the user interface 402. The query engine 412 operates on data stored in the database 420, provided in a table T 422. Table T 422 can have any number of rows and columns, where the intersection of each row and each column represents a cell containing a data object.
In accordance with an embodiment, the query system 410 includes a sample generator 414 configured to generate a column Sample 424 as described above, and physically add the column Sample 424 to the table T 422 in the database. The query system 410 also includes a clustering tool 416 configured to cluster the rows in the table T 422 according to an ordered arrangement of values assigned to each cell in the column Sample 424, such that rows with the same value in column Sample 424 are stored together. Example clustering tools 416 can include a multidimensional clustering (MDC) or composite partitioning, although various other clustering tools can be used. The query system 410 further includes an index generator 418 for generating an index for the column Sample 424, or for incorporating the column Sample 424 into an existing index, if desired.
In operation, the query engine 412 executes a query according to block-level sampling of the clustered table T 422, arranged according to the column Sample 424. Accordingly, I/O communications to database for access to the data in table T 422 are minimized to a level commensurate with the sampling. The materialized sample in column Sample 424 also allows new rows to be added to table T 422 and automatically associated with the clustering schema in the column Sample 424.
Although a few embodiments have been described in detail above, other modifications are possible. The logic flow depicted in
Number | Name | Date | Kind |
---|---|---|---|
5537589 | Dalal | Jul 1996 | A |
5781896 | Dalal | Jul 1998 | A |
5850522 | Wlaschin | Dec 1998 | A |
5878426 | Plasek et al. | Mar 1999 | A |
5890150 | Ushijima et al. | Mar 1999 | A |
5950189 | Cohen et al. | Sep 1999 | A |
6029163 | Ziauddin | Feb 2000 | A |
6064999 | Dalal | May 2000 | A |
6112197 | Chatterjee et al. | Aug 2000 | A |
6163775 | Wlaschin et al. | Dec 2000 | A |
6182121 | Wlaschin | Jan 2001 | B1 |
6263334 | Fayyad et al. | Jul 2001 | B1 |
6289334 | Reiner et al. | Sep 2001 | B1 |
6411951 | Galindo-Legaria et al. | Jun 2002 | B1 |
6513029 | Agrawal et al. | Jan 2003 | B1 |
6633882 | Fayyad et al. | Oct 2003 | B1 |
6721727 | Chau et al. | Apr 2004 | B2 |
6732085 | Mozes | May 2004 | B1 |
6993516 | Haas et al. | Jan 2006 | B2 |
7328221 | Chaudhuri et al. | Feb 2008 | B2 |
20020123993 | Chau et al. | Sep 2002 | A1 |
20020178151 | Chaudhuri et al. | Nov 2002 | A1 |
20040002956 | Chaudhuri et al. | Jan 2004 | A1 |
20040193629 | Mozes | Sep 2004 | A1 |
20040225639 | Jakobsson et al. | Nov 2004 | A1 |
20050033739 | Chaudhuri et al. | Feb 2005 | A1 |
20050033759 | Chaudhuri et al. | Feb 2005 | A1 |
Number | Date | Country | |
---|---|---|---|
20060116984 A1 | Jun 2006 | US |