Datawarehousing - Powerpoint Canadien Cs.sfu.ca 2e Version

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Datawarehousing - Powerpoint Canadien Cs.sfu.ca 2e Version as PDF for free.

More details

  • Words: 2,343
  • Pages: 14
Data Warehousing Instructor: Martin Ester

Database Management Systems, 2nd Edition. R. Ramakrishnan and J. Gehrke

134

Introduction o

o

o

Increasingly, organizations are analyzing current and historical data to identify useful patterns and support business strategies. Emphasis is on complex, interactive, exploratory analysis of very large datasets created by integrating data from across all parts of an enterprise; data is fairly static. Contrast such On-Line Analytic Processing (OLAP) with traditional On-line Transaction Processing (OLTP): mostly long queries, instead of short update transactions. Decision Support

Database Management Systems, 2nd Edition. R. Ramakrishnan and J. Gehrke

135

1

DBS for Decision Support o

o

o

Data Warehousing: Consolidate data from many sources in one large repository.

 Loading, periodic synchronization of replicas.  Semantic integration. OLAP:  Complex SQL queries and views.  Queries based on “multidimensional” view of data and spreadsheet-style operations.  Interactive and “online” (manual) analysis.

Data Mining: Automatic discovery of interesting trends and other patterns. (Next Chapter!)

Database Management Systems, 2nd Edition. R. Ramakrishnan and J. Gehrke

136

Data Warehousing o

o o o

A Data Warehouse is a subject oriented, integrated, time variant, non volatile collection of data for the purpose of decision support. Integrates data from several operational (OLTP) databases. Keeps (relevant part of the) history of the data. Views data at a more abstract level than OLTP systems (aggregate over many detail records).

Database Management Systems, 2nd Edition. R. Ramakrishnan and J. Gehrke

137

2

Data Warehousing EXTERNAL DATA SOURCES

EXTRACT INTEGRATE TRANSFORM LOAD / REFRESH

DATA WAREHOUSE

Metadata Repository

SUPPORTS

OLAP

DATA MINING

Database Management Systems, 2nd Edition. R. Ramakrishnan and J. Gehrke

138

Data Warehousing o o o o

Integrated data spanning long time periods, often augmented with summary information. Data warehouse keeps the history. Therefore, several gigabytes to terabytes common. Interactive response times expected for complex queries. On the other hand, ad-hoc updates uncommon.

Database Management Systems, 2nd Edition. R. Ramakrishnan and J. Gehrke

139

3

Data Warehousing Issues o

o

Semantic Integration: When getting data from multiple sources, must eliminate mismatches, e.g., different currencies, DB schemas. Heterogeneous Sources: Must access data from a variety of source formats and repositories. o Replication capabilities can be exploited here.

o o

Load, Refresh, Purge: Must load data, periodically refresh it, and purge too-old data. Metadata Management: Must keep track of source, loading time, and other information for all data in the warehouse.

Database Management Systems, 2nd Edition. R. Ramakrishnan and J. Gehrke

timeid locid sales

pid

Multidimensional Data Model

140

Collection of dimensions (independent 11 1 1 25 variables) and (numeric) measures 11 2 1 8 (dependent variables). 11 3 1 15

o

E.g., dimensions Product (key: pid), Location (locid), and Time (timeid) and measure Sales.

Slice locid=1 is shown

pid 11 12 13

o

12 1 1 30 12 2 1 20 12 3 1 50

8 30 25 1

10 20

10 50

8 15 2 3 timeid

13 1 1 8 13 2 1 10

locid

Database Management Systems, 2nd Edition. R. Ramakrishnan and J. Gehrke

13 3 1 10 11 1 2 35 141

4

MOLAP vs ROLAP o

o

Multidimensional data can be stored physically in a (disk-resident, persistent) array; called MOLAP systems. Alternatively, can store as a relation; called ROLAP systems. The main relation, which relates dimensions to a measure, is called the fact table. Each dimension can have additional attributes and an associated dimension table. E.g., Products(pid, pname, category, price) Fact tables are much larger than dimensional tables.

Database Management Systems, 2nd Edition. R. Ramakrishnan and J. Gehrke

142

Dimension Hierarchies o

For each dimension, the set of values can be organized in a hierarchy (subset relationship):

PRODUCT

TIME

LOCATION

year quarter category

week

pname Database Management Systems,

month date

2nd

Edition. R. Ramakrishnan and J. Gehrke

country state city 143

5

OLAP Queries o o

Influenced by SQL and by spreadsheets. A common operation is to aggregate a measure over one or more dimensions. Find total sales. Find total sales for each city, or for each state. Find top five products ranked by total sales.

o

Roll-up: Aggregating at different levels of a dimension hierarchy. E.g., given total sales by city, we can roll-up to get sales by state.

Database Management Systems, 2nd Edition. R. Ramakrishnan and J. Gehrke

144

OLAP Queries o

Drill-down: The inverse of roll-up. E.g., given total sales by state, can drill-down to get total sales by city. E.g., can also drill-down on different dimension to get total sales by product for each state.

o

Pivoting: Aggregation on selected dimensions. WI CA Total E.g., pivoting on Location and Time yields this cross-tabulation: 1995 63 81 144

o

Slicing and Dicing: Equality and range selections on one or more dimensions.

Database Management Systems, 2nd Edition. R. Ramakrishnan and J. Gehrke

1996 38 107 145 1997 75

35 110

Total 176 223 339

145

6

Comparison with SQL Queries o

The cross-tabulation obtained by pivoting can also be computed using a collection of SQLqueries: SELECT SUM(S.sales) FROM Sales S, Times T, Locations L WHERE S.timeid=T.timeid AND S.timeid=L.timeid GROUP BY T.year, L.state SELECT SUM(S.sales) FROM Sales S, Times T WHERE S.timeid=T.timeid GROUP BY T.year

SELECT SUM(S.sales) FROM Sales S, Location L WHERE S.timeid=L.timeid GROUP BY L.state

SELECT SUM(S.sales) FROM

Sales S

Database Management Systems, 2nd Edition. R. Ramakrishnan and J. Gehrke

146

The CUBE Operator o

o

o

Generalizing the previous example, if there are k dimensions, we have 2k possible SQL GROUP BY queries that can be generated through pivoting on a subset of dimensions. A Data Cube is a multi-dimensional model of a datawarehouse where the domain of each dimension is extended by the special value „ALL“ with the semantics of aggregating over all values of the corresponding dimension. An entry of a data cube is called a cell. The number of cells of a datacube with d dimensions is d

∏ (| Domain i =1

i

| +1)

Database Management Systems, 2nd Edition. R. Ramakrishnan and J. Gehrke

147

7

The CUBE Operator o

o

o

o

The Cube Operator can be much more efficiently processed than the set of all corresponding (independent) SQL GROUP BY queries. Observation: The results of more generalized queries (with fewer GROUP BY attributes) can be derived from more specialized queries (with more GROUP BY attributes). Process more specialised queries first and, based on their results, determine the outcome of more generalised queries. Significant reduction of I/O cost, since intermediate results are much smaller than original table.

Database Management Systems, 2nd Edition. R. Ramakrishnan and J. Gehrke

148

The CUBE Operator o o

Lattice of GROUP-BY queries of a CUBE query w.r.t. derivability of the results Example {pid, locid, timeid} {pid, locid} {pid}

{pid, timeid} {locid}

{locid, timeid} {timeid}

{}

Database Management Systems, 2nd Edition. R. Ramakrishnan and J. Gehrke

149

8

Design Issues

TIMES

timeid date week month quarter year holiday_flag

pid timeid locid sales

SALES

PRODUCTS

LOCATIONS

pid pname category price

o

(Fact table)

locid

city

state

country

Fact table in BCNF; dimension tables un-normalized. Dimension tables are small; updates/inserts/deletes are rare. So, anomalies less important than query performance.

o

This kind of schema is very common in OLAP applications, and is called a star schema; computing the join of all these relations is called a star join.

Database Management Systems, 2nd Edition. R. Ramakrishnan and J. Gehrke

150

Implementation Issues o

o

New indexing techniques: Bitmap indexes, Join indexes, array representations, compression, precomputation of aggregations, etc. Example Bitmap index:

Bit-vector: F 1 bit for each M possible value. Selections can be processed using (efficient!) bit-vector ops.

sex

10 10 01 10

custid name sex rating

112 115 119 112

Joe Ram Sue Woo

M M F M

Database Management Systems, 2nd Edition. R. Ramakrishnan and J. Gehrke

3 5 5 4

rating

00100 00001 00001 00010

151

9

Join Indexes Consider the join of Sales, Products, Times, and Locations,

o

possibly with additional selection conditions (e.g., country=“USA”). A join index can be constructed to speed up such joins (in relatively static databases). The index contains [s,p,t,l] if there are tuples (with sid) s in Sales, p in Products, t in Times and l in Locations that satisfy the join (and selection) conditions.

Problem: Number of join indexes can grow rapidly.

o

A variation addresses this problem: For each column with an additional selection (e.g., country), build an index with [c,s] in it if a dimension table tuple with value c in the selection column joins with a Sales tuple with sid s; if indexes are bitmaps, called bitmapped join index. Database Management Systems, 2nd Edition. R. Ramakrishnan and J. Gehrke

152

Bitmapped Join Index

TIMES

timeid date week month quarter year holiday_flag

pid timeid locid sales

SALES

PRODUCTS

pid pname category price o

o

(Fact table)

LOCATIONS

locid

city

state

country

Consider a query with conditions price=10 and country=“USA”. Suppose tuple (with sid) s in Sales joins with a tuple p with price=10 and a tuple l with country =“USA”. There are two (Bitmap) join indexes; one containing [10,s] and the other [USA,s]. Intersecting these indexes tells us which tuples in Sales are in the join and satisfy the given selection.

Database Management Systems, 2nd Edition. R. Ramakrishnan and J. Gehrke

153

10

Querying Sequences in SQL:1999 o o

o

SQL-92 supports only (unordered) sets of tuples. Trend analysis is difficult to do in SQL-92, e.g.: Find the % change in monthly sales Find the top 5 product by total sales Find the trailing n-day moving average of sales The first two queries can be expressed with difficulty, but the third cannot even be expressed in SQL-92 if n is a parameter of the query. The WINDOW clause in SQL:1999 allows us to formulate such queries over a table viewed as a sequence (implicitly, based on user-specified sort keys).

Database Management Systems, 2nd Edition. R. Ramakrishnan and J. Gehrke

154

The WINDOW Clause o o o o

o

A window is an ordered group of tuples around each (reference) tuple of a table. The order within a window is determined based on an attribute specified by the SQL statement. The width of the window is also specified by the SQL statement. The tuples of the window can be aggregated using the standard (set-oriented) SQL aggregate functions (SUM, AVG, COUNT, . . .). SQL:1999 introduces some new (sequence-oriented) aggregate functions, in particular RANK, DENSE_RANK, PERCENT_RANK.

Database Management Systems, 2nd Edition. R. Ramakrishnan and J. Gehrke

155

11

The WINDOW Clause SELECT L.state, T.month, AVG(S.sales) OVER W AS movavg FROM Sales S, Times T, Locations L WHERE S.timeid=T.timeid AND S.locid=L.locid WINDOW W AS (PARTITION BY L.state ORDER BY T.month RANGE BETWEEN INTERVAL `1’ MONTH PRECEDING AND INTERVAL `1’ MONTH FOLLOWING); o o

Let the result of the FROM and WHERE clauses be “Temp”. Conceptually, Temp is partitioned according to the PARTITION BY clause. Similar to GROUP BY, but the answer has one tuple for each tuple in a partition, not one tuple per partition!

o

Each partition is sorted according to the ORDER BY clause.

Database Management Systems, 2nd Edition. R. Ramakrishnan and J. Gehrke

156

The WINDOW Clause SELECT L.state, T.month, AVG(S.sales) OVER W AS movavg FROM Sales S, Times T, Locations L WHERE S.timeid=T.timeid AND S.locid=L.locid WINDOW W AS (PARTITION BY L.state ORDER BY T.month RANGE BETWEEN INTERVAL `1’ MONTH PRECEDING AND INTERVAL `1’ MONTH FOLLOWING) o

For each tuple in a partition, the WINDOW clause creates a “window” of nearby (preceding or succeeding) tuples. Definition of window width can be value-based, as in example, using RANGE. Can also be based on number of tuples to include in the window, using ROWS clause.

o

The aggregate function is evaluated for each tuple in the partition based on the corresponding window.

Database Management Systems, 2nd Edition. R. Ramakrishnan and J. Gehrke

157

12

Top N Queries o o

o

o o

Sometimes, want to find only the „best“ answers (e.g., web search engines). If you want to find the 10 (or so) cheapest cars, it would be nice if the DB could avoid computing the costs of all cars before sorting to determine the 10 cheapest. Idea: Guess a cost c such that the 10 cheapest cars all cost less than c, and that not too many other cars cost less than c. Then add the selection cost
Database Management Systems, 2nd Edition. R. Ramakrishnan and J. Gehrke

158

Top N Queries SELECT P.pid, P.pname, S.sales FROM Sales S, Products P WHERE S.pid=P.pid AND S.locid=1 AND S.timeid=3 ORDER BY S.sales DESC OPTIMIZE FOR 10 ROWS SELECT P.pid, P.pname, S.sales FROM Sales S, Products P WHERE S.pid=P.pid AND S.locid=1 AND S.timeid=3

AND S.sales > c ORDER BY S.sales DESC o

OPTIMIZE FOR construct is not in SQL:1999.

o

Cut-off value c is chosen by optimizer.

Database Management Systems, 2nd Edition. R. Ramakrishnan and J. Gehrke

159

13

Online Aggregation o

o o

Consider an aggregate query, e.g., finding the average sales by state. Can we provide the user with some information before the exact average is computed for all states? Can show the current “running average” for each state as the computation proceeds. Even better, if we use statistical techniques and sample tuples to aggregate instead of simply scanning the aggregated table, we can provide bounds such as “the average for Wisconsin is 2000±102 with 95% probability. Should also use nonblocking algorithms!

Database Management Systems, 2nd Edition. R. Ramakrishnan and J. Gehrke

160

Summary o o o

o

Decision support is an emerging, rapidly growing subarea of database systems. Involves the creation of large, consolidated data repositories called data warehouses. Warehouses exploited using sophisticated analysis techniques: complex SQL queries and OLAP “multidimensional” queries (or automatic data mining methods). New techniques for database design, indexing, view maintenance, and interactive querying need to be developed.

Database Management Systems, 2nd Edition. R. Ramakrishnan and J. Gehrke

161

14

Related Documents

Datawarehousing
November 2019 13
2e
April 2020 21
2e
April 2020 24
2e
October 2019 38