O VERCOMING L IMITATIONS OF S AMPLING FOR A GGREGATION Q UERIES Surajit ChaudhuriMicrosoft Research...

25
OVERCOMING LIMITATIONS OF SAMPLING FOR AGGREGATION QUERIES Surajit Chaudhuri Microsoft Research Gautam DasMicrosoft Research Mayur Datar Stanford University Rajeev Motwani Stanford University Vivek Narasayya Microsoft Research Presented by :- Vinit Asher 1000570792 Deep Pancholi 1000556121

Transcript of O VERCOMING L IMITATIONS OF S AMPLING FOR A GGREGATION Q UERIES Surajit ChaudhuriMicrosoft Research...

Page 1: O VERCOMING L IMITATIONS OF S AMPLING FOR A GGREGATION Q UERIES Surajit ChaudhuriMicrosoft Research Gautam DasMicrosoft Research Mayur DatarStanford University.

OVERCOMING LIMITATIONS OF SAMPLING FOR AGGREGATION QUERIES

Surajit Chaudhuri Microsoft Research

Gautam Das Microsoft Research

Mayur Datar Stanford University

Rajeev Motwani Stanford University

Vivek Narasayya Microsoft Research

Presented by :-Vinit Asher 1000570792Deep Pancholi 1000556121

Page 2: O VERCOMING L IMITATIONS OF S AMPLING FOR A GGREGATION Q UERIES Surajit ChaudhuriMicrosoft Research Gautam DasMicrosoft Research Mayur DatarStanford University.

INTRODUCTION

Why sampling? Why uniform random sampling? Uniform Random Samples and factors

responsible for significant error introduction Skewed database i.e. characterized by presence

of Outlier values Low selectivity of queries (related to aggregate

queries). How do we overcome the problems?

Page 3: O VERCOMING L IMITATIONS OF S AMPLING FOR A GGREGATION Q UERIES Surajit ChaudhuriMicrosoft Research Gautam DasMicrosoft Research Mayur DatarStanford University.

TECHNIQUES SUGGESTED IN PAPER

For problems due to skew in data, the paper recommends to isolate the values in the dataset that contribute heavily to error in sampling.

Exploit the workload information to overcome limitations in answering queries with low selectivity.

Page 4: O VERCOMING L IMITATIONS OF S AMPLING FOR A GGREGATION Q UERIES Surajit ChaudhuriMicrosoft Research Gautam DasMicrosoft Research Mayur DatarStanford University.

KEY CONTRIBUTIONS OF THE PAPER

Experimental evaluation of the proposed techniques based on implementation on Microsoft SQL Server

Paper also demonstrates that a combination of outlier indexing and weighted sampling results in significant error reduction compared to Uniform Random Sampling.

Page 5: O VERCOMING L IMITATIONS OF S AMPLING FOR A GGREGATION Q UERIES Surajit ChaudhuriMicrosoft Research Gautam DasMicrosoft Research Mayur DatarStanford University.

EXAMPLE OF DATA SKEW AND ITS ADVERSE EFFECT Suppose N=10,000 such that 99% tuples have a value of 1,

remaining 1% have a value of 1000. Hence, Sum of this table is 9900+100,000=109,900 Suppose we take a Uniform Random Sample of size 1%.

Hence, n=100 Now it is possible that all 100 tuples in sample have a value 1

giving us a sum of 100*100=10,000 which is way way less than correct answer.

If we get 99 tuples with value 1 and 1 tuple with 1000, sum is 1099*100=109,900. Similarly for 98 tuples of 1 and 2 tuples of 1000, sum=209,800

This shows that if we get a value of 1000 in sample more than once, we are going to get a huge error. And not getting any 1000 value also causes a huge error.

However, the probability to get just 1 value of 1000 in sample is mere 0.37!!! It means the probability to get an erroneous result is 0.63.

Page 6: O VERCOMING L IMITATIONS OF S AMPLING FOR A GGREGATION Q UERIES Surajit ChaudhuriMicrosoft Research Gautam DasMicrosoft Research Mayur DatarStanford University.

EFFECT OF DATA SKEW (CONTINUED)

Similar arguments also hold for the aggregate average.

Tuples deviant from the rest of the values in terms of their contributions to aggregrate are known as outliers.

Page 7: O VERCOMING L IMITATIONS OF S AMPLING FOR A GGREGATION Q UERIES Surajit ChaudhuriMicrosoft Research Gautam DasMicrosoft Research Mayur DatarStanford University.

EFFECT OF DATA SKEW (CONTINUED)

Theorem 1: For a relation R with elements {y1, y2,…,yN}, let U be the uniform random sample of size n. Then actual sum will be and the unbiased estimate of the actual sum will be Ye=(N╱n)∑yi∈Uyi with a standard error as follows:

Where S is the standard deviation of the values in the relation defined as

This shows that if there are outliers in the data, then S could be very large. In this case, for a given error bound, we will need to increase the sample size n.

Page 8: O VERCOMING L IMITATIONS OF S AMPLING FOR A GGREGATION Q UERIES Surajit ChaudhuriMicrosoft Research Gautam DasMicrosoft Research Mayur DatarStanford University.

EFFECT OF LOW SELECTIVITY AND SMALL GROUPS What happens if the selectivity of a query is low?

It adversely impacts the accuracy of the sampling based estimation

A selection query partitions the relation into two sub-relations as follows: Tuples that satisfy the condition of select query Tuples that don’t satisfy the condition.

When we sample uniformly, the number of tuples that are sampled from the relevant sub-relation are proportional to its size.

Hence, if the relevant sample size is low, it can lead to huge errors.

For Uniform random sampling to perform well, the relevant sub-relation should be large in size, which is not the case in general.

Page 9: O VERCOMING L IMITATIONS OF S AMPLING FOR A GGREGATION Q UERIES Surajit ChaudhuriMicrosoft Research Gautam DasMicrosoft Research Mayur DatarStanford University.

HANDLING DATA SKEW: OUTLIER INDEXES

Outliers/deviants in data Large Variance High errors

Hence we identify tuples with outlier values and store them in separate sub relation.

The proposed technique would result in a very accurate estimation of the aggregate.

In Outlier indexing method, a given relation R is partitioned as RO (Outliers) and RNO (no-outliers). The Query Q now can be run as a union of two sub-queries one on RO and another on RNO.

Page 10: O VERCOMING L IMITATIONS OF S AMPLING FOR A GGREGATION Q UERIES Surajit ChaudhuriMicrosoft Research Gautam DasMicrosoft Research Mayur DatarStanford University.

HANDLING DATA SKEW: OUTLIER INDEXES (EXAMPLE)

Preprocessing steps Determine Outliers – Specify sub-relation R0 of R

to be the set of outliers Sample Non-Outliers – Select a uniform random

sample T of the relation RNO

Query processing steps Aggregate outliers – Apply the query to outliers

in R0

Aggregate non-outliers – Apply the query to sample T and extrapolate to obtain an estimate of the query result for RNO

Combine Aggregates – Combine the appoximate result for RNO with the exact result for R0 to obtain an appoximate result for R

Page 11: O VERCOMING L IMITATIONS OF S AMPLING FOR A GGREGATION Q UERIES Surajit ChaudhuriMicrosoft Research Gautam DasMicrosoft Research Mayur DatarStanford University.

SELECTION OF OUTLIERS

In this method of Outlier-indexing, query error is solely because of error in estimating non-outlier aggregation.

However, there is additional overhead for maintaining and accessing an outlier index.

Theorem 2: Consider a multiset R = {y1, y2,…,yN} in sorted order. Let RO R be the subset such that

Here is the allocated memory for outlier indexing.

Page 12: O VERCOMING L IMITATIONS OF S AMPLING FOR A GGREGATION Q UERIES Surajit ChaudhuriMicrosoft Research Gautam DasMicrosoft Research Mayur DatarStanford University.

ALGORITHM FOR OUTLIER INDEX (R,C, ) Alogirithm Outlier-Index(R,C, τ): Let the values in column C be sorted in relation R For i = 1 to τ+1, compute

E(i) = S({yi, yi+1,…yN- τ+i-1}) Let i’ be the value of i where E(i) is minimum. Outlier-index is the tuples that correspond to the set of

values {yj|1 ≤ j≤ τ’ }U{yj|(N+ τ’ +1- τ) ≤j ≤N} i.e. lowest 1 to τ’ values and highest τ - τ’ values.

where τ’ = i’ - 1 It is possible to give standard error (probabilistic)

guarantee of our estimated answer using Theorem1.

Page 13: O VERCOMING L IMITATIONS OF S AMPLING FOR A GGREGATION Q UERIES Surajit ChaudhuriMicrosoft Research Gautam DasMicrosoft Research Mayur DatarStanford University.

STORAGE ALLOCATION FOR OUTLIER INDEXING

Given sufficient space to store m tuples, how do we allocate storage between samples and outlier-index so as to get minimum error?

Suppose S(t) denotes standard deviation in non-outliers for optimal outlier index of size t.

From Theorem 1, error is proportional towhere t tuples are in outlier index and m-t tuples in the sample.

Page 14: O VERCOMING L IMITATIONS OF S AMPLING FOR A GGREGATION Q UERIES Surajit ChaudhuriMicrosoft Research Gautam DasMicrosoft Research Mayur DatarStanford University.

EXTENSION OF OUTLIER INDEXING TO OTHER AGGREGATES

For count aggregate the outlier indexing is not beneficial since there is no variance among the data values.

In case of aggregate avg (average), during query processing, an avg query is estimated as sum/count

Outlier-indexing is also not beneficial for the aggregates that depend upon the rank of tuples rather that their actual values (such as min, max or median)

Page 15: O VERCOMING L IMITATIONS OF S AMPLING FOR A GGREGATION Q UERIES Surajit ChaudhuriMicrosoft Research Gautam DasMicrosoft Research Mayur DatarStanford University.

FINAL NOTES ON OUTLIER INDEXING

Outlier indexing technique works best for aggregations on a single table that don’t involve foreign-key joins.

It is beneficial for sum and average aggregations but doesn’t work for rank-order based queries such as max, min or count.

As future work, investigation is going on whether to create separate outlier indexes for frequently occurring functions depending on the workload information.

Page 16: O VERCOMING L IMITATIONS OF S AMPLING FOR A GGREGATION Q UERIES Surajit ChaudhuriMicrosoft Research Gautam DasMicrosoft Research Mayur DatarStanford University.

HANDLING LOW SELECTIVITY AND SMALL GROUPS

In this case, we want to use weighted sampling. In other words, we want to sample more from subsets of data that are small in size but are important (i.e. having high usage).

We select a representative workload (i.e. a set of queries) and tune the sample so that we can answer the queries posed to database more accurately.

The technique mentioned in the paper is for precomputed samples only. However, research is being done to apply this solution to online sampling.

Page 17: O VERCOMING L IMITATIONS OF S AMPLING FOR A GGREGATION Q UERIES Surajit ChaudhuriMicrosoft Research Gautam DasMicrosoft Research Mayur DatarStanford University.

EXPLOITING WORKLOAD INFORMATION

Workload Collection: It means obtaining a workload consisting of representative queries that are posed to the database. Tools like profiler component in the Microsoft SQL Server allow logging of queries posed to the Database.

Tracing Query Patterns: It basically involves analyzing the workload to obtain parsed information.

Tracing Tuple Usage: It involves tracing number of times a tuple was accessed, number of times it satisfies the query, number of times tuple didn’t satisfy the condition, etc.

Weighted Sampling: It involves sampling by taking into account weights of tuples into consideration.

Page 18: O VERCOMING L IMITATIONS OF S AMPLING FOR A GGREGATION Q UERIES Surajit ChaudhuriMicrosoft Research Gautam DasMicrosoft Research Mayur DatarStanford University.

WEIGHTED SAMPLING: DEEPER INSIGHT Same as stratified sampling done in class. All the

tuple are assigned some weightage depending on traces tuple usage

Whenever we want to get a sample, a tuple is associated in the sample with probability pi=n*wi’

Now, as discussed in class, the inverse of pi is the multiplication factor. Each aggregate computed over this tuple gets multiplied by the multiplication factor to answer the query. As the uniform random sample has equal probability, the multiplication factor is (N/n).

This method works well only if we have a workload that is a good representation of the actual queries posed in future and also if access pattern of the queries is local in nature.

Page 19: O VERCOMING L IMITATIONS OF S AMPLING FOR A GGREGATION Q UERIES Surajit ChaudhuriMicrosoft Research Gautam DasMicrosoft Research Mayur DatarStanford University.

IMPLEMENTATION AND EXPERIMENTAL SETUP

Databases: The database used for experimentation is the TPC-R benchmark database. The data generation was modified a bit to get varying degrees of skew. The modified program generates data based on Zipfian distribution.

Parameters: Skew of the data (z) varied over 1, 1.5, 2, 2.5

and 3 Sampling fraction (f) varied from 1% to 100% Storage for Outlier index varies 1%, 5%, 10%

and 20%.

Page 20: O VERCOMING L IMITATIONS OF S AMPLING FOR A GGREGATION Q UERIES Surajit ChaudhuriMicrosoft Research Gautam DasMicrosoft Research Mayur DatarStanford University.

IMPLEMENTATION AND EXPERIMENTAL SETUP (2)

The comparisons were done on three options: 1) Uniform Sampling 2) Weighted Sampling 3) Weighted Sampling + Outlier Indexing

The results depicted here are for which the storage size for outlier-indexing was only 10% of the size of the data set.

Page 21: O VERCOMING L IMITATIONS OF S AMPLING FOR A GGREGATION Q UERIES Surajit ChaudhuriMicrosoft Research Gautam DasMicrosoft Research Mayur DatarStanford University.

EXPERIMENTAL RESULTS

Page 22: O VERCOMING L IMITATIONS OF S AMPLING FOR A GGREGATION Q UERIES Surajit ChaudhuriMicrosoft Research Gautam DasMicrosoft Research Mayur DatarStanford University.

EXPERIMENTAL RESULTS (2)

Page 23: O VERCOMING L IMITATIONS OF S AMPLING FOR A GGREGATION Q UERIES Surajit ChaudhuriMicrosoft Research Gautam DasMicrosoft Research Mayur DatarStanford University.

EXPERIMENTAL RESULTS (3)

Page 24: O VERCOMING L IMITATIONS OF S AMPLING FOR A GGREGATION Q UERIES Surajit ChaudhuriMicrosoft Research Gautam DasMicrosoft Research Mayur DatarStanford University.

CONCLUSION

We can easily conclude that skew in the data can lead to considerable large errors. However, Outlier indexing addresses this problem at a small additional overhead. The problem lies in creating a single outlier index that works for any query on the database.

Low selectivity of queries is addressed by the weighted load of sampling.

Some important references: http://www.cs.sfu.ca/~wangk/standards.pdf - for

more info on TPC-R standard database.

Page 25: O VERCOMING L IMITATIONS OF S AMPLING FOR A GGREGATION Q UERIES Surajit ChaudhuriMicrosoft Research Gautam DasMicrosoft Research Mayur DatarStanford University.

DIRECTION OF FUTURE WORK

Building of a single outlier-index for different aggregates and aggregate expressions

Tuning the selection of outlier-index using workload information

Extension of the techniques discussed to a wider class of join queries