# US 2008/0301085 A1 · Dynamic Database File Column Statistics for Arbitrary Union Combination

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

- Number: US 2008/0301085 A1
- Document ID: US20080301085A1
- Status: Published application
- Kind: A1
- Application number: 11/755,954
- Filed: 2007-05-31
- Published: 2008-12-04
- Earliest claimed: 2007-05-31
- Inventors: Michael S. Faunce; Wei Hu; Shantan Kethireddy; Andrew Peter Passe; Ulrich Thiemann
- Web page: https://patentgrep.com/patent/US20080301085A1

## CPC

- G06F 16/24544: {Join order optimisation}
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

Embodiments of the invention provide techniques for generating database statistics for optimizing union queries. In general, working sets including samples of values in database columns are persistently maintained in a database. To optimize a union query, the working sets describing the columns included in the union query are combined to generate an ad hoc working set. The ad hoc working set is then used to generate a database statistic describing the combined columns. In another embodiment, working sets may also be maintained for generating statistics for optimizing non-union queries, thus enabling statistics to be refreshed more frequently.

## Claims

### Claim 1

A computer-implemented method for generating a database statistic for optimizing union queries, comprising:
receiving a union query for joining data from at least two data columns;
identifying at least two working sets, each comprising data values sampled from a different column of the at least two columns, wherein the at least two working sets are maintained persistently in a database;
generating an ad hoc working set comprising data values of the at least two working sets;
generating a database statistic based on the ad hoc working set, wherein the database statistic represents anticipated characteristics of query results to be returned for the union query; and
outputting the database statistic.

### Claim 2 (depends on 1)

The computer-implemented method of claim 1, further comprising:
selecting, based on the database statistic, a query plan for executing the union query;
executing the selected query plan; and
returning a set of query results.

### Claim 3 (depends on 1)

The computer-implemented method of claim 1, wherein each of the at least two working sets comprises a pre-determined number of data values based on a desired level of statistical accuracy.

### Claim 4 (depends on 1)

The computer-implemented method of claim 1, wherein the database statistic is a list of the most frequent values included in the query results to be returned for the union query.

### Claim 5 (depends on 1)

The computer-implemented method of claim 1, wherein the database statistic is a cardinality number for the query results to be returned for the union query.

### Claim 6 (depends on 1)

The computer-implemented method of claim 1, wherein generating the ad hoc working set comprises a union of the data values of the at least two working sets.

### Claim 7 (depends on 1)

The computer-implemented method of claim 1, wherein generating the ad hoc working set comprises a random combination of the data values of the at least two working sets, wherein the ad hoc working set comprises the same number of data values as contained in either of the at least two working sets.

### Claim 8

A computer readable storage medium containing a program which, when executed, performs an operation, comprising:
receiving a union query for joining data from at least two data columns;
identifying at least two working sets, each comprising data values sampled from a different column of the at least two columns, wherein the at least two working sets are maintained persistently in a database;
generating an ad hoc working set comprising data values of the at least two working sets;
generating a database statistic based on the ad hoc working set, wherein the database statistic represents anticipated characteristics of query results to be returned for the union query; and
outputting the database statistic.

### Claim 9 (depends on 8)

The computer readable storage medium of claim 8, further comprising:
selecting, based on the database statistic, a query plan for executing the union query;
executing the selected query plan; and
returning a set of query results.

### Claim 10 (depends on 8)

The computer readable storage medium of claim 8, wherein each of the at least two working sets comprises a pre-determined number of data values based on the desired level of statistical accuracy.

### Claim 11 (depends on 8)

The computer readable storage medium of claim 8, wherein the database statistic is a list of the most frequent values included in the query results to be returned for the union query.

### Claim 12 (depends on 8)

The computer readable storage medium of claim 8, wherein the database statistic is a cardinality number for the query results to be returned for the union query.

### Claim 13 (depends on 8)

The computer readable storage medium of claim 8, wherein generating the ad hoc working set comprises a union of the data values of the at least two working sets.

### Claim 14 (depends on 8)

The computer readable storage medium of claim 8, wherein generating the ad hoc working set comprises a random combination of the data values of the at least two working sets, wherein the ad hoc working set comprises the same number of data values as contained in either of the at least two working sets.

### Claim 15

A system, comprising:
a database;
a group of working sets maintained persistently in the database; and
a processor configured to:
receive a union query for joining data from at least two data columns;
identify at least two working sets from the group of working sets, each of the at least two working sets comprising data values sampled from a different column of the at least two columns;
generate an ad hoc working set comprising data values of the at least two working sets;
generate a database statistic based on the ad hoc working set, wherein the database statistic represents anticipated characteristics of query results to be returned for the union query; and
output the database statistic.

### Claim 16 (depends on 15)

The system of claim 15, wherein the processor is further configured to:
select, based on the database statistic, a query plan for executing the union query;
execute the selected query plan; and
return a set of query results.

### Claim 17 (depends on 15)

The system of claim 15, wherein each of the at least two working sets comprises a pre-determined number of data values based on the desired level of statistical accuracy.

### Claim 18 (depends on 15)

The system of claim 15, wherein the database statistic is a list of the most frequent values included in the query results to be returned for the union query.

### Claim 19 (depends on 15)

The system of claim 15, wherein the database statistic is a cardinality number for the query results to be returned for the union query.

### Claim 20 (depends on 15)

The system of claim 15, wherein generating the ad hoc working set comprises a union of the data values of the at least two working sets.

### Claim 21 (depends on 15)

The system of claim 15, wherein generating the ad hoc working set comprises a random combination of the data values of the at least two working sets, wherein the ad hoc working set comprises the same number of data values as contained in either of the at least two working sets.
