Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Data Warehousing Overview
CS245 Notes 11
Hector Garcia-Molina
Stanford University
CS 245
Notes11
1
Warehousing
Growing industry: $8 billion in 1998
Range from desktop to huge:
Walmart:
900-CPU, 2,700 disk, 23TB
Teradata system
Lots of buzzwords, hype
slice
CS 245
& dice, rollup, MOLAP, pivot, ...
Notes11
2
Outline
What is a data warehouse?
Why a warehouse?
Models & operations
Implementing a warehouse
Future directions
CS 245
Notes11
3
What is a Warehouse?
Collection of diverse data
subject
oriented
aimed at executive, decision maker
often a copy of operational data
with value-added data (e.g., summaries, history)
integrated
time-varying
non-volatile
more
CS 245
Notes11
4
What is a Warehouse?
Collection of tools
gathering
data
cleansing, integrating, ...
querying, reporting, analysis
data mining
monitoring, administering warehouse
CS 245
Notes11
5
Warehouse Architecture
Client
Client
Query & Analysis
Metadata
Warehouse
Integration
Source
CS 245
Source
Notes11
Source
6
Motivating Examples
Forecasting
Comparing performance of units
Monitoring, detecting fraud
Visualization
CS 245
Notes11
7
Why a Warehouse?
Two Approaches:
Query-Driven
(Lazy)
Warehouse (Eager)
?
Source
CS 245
Notes11
Source
8
Query-Driven Approach
Client
Client
Mediator
Wrapper
Source
CS 245
Wrapper
Wrapper
Source
Source
Notes11
9
Advantages of Warehousing
High query performance
Queries not visible outside warehouse
Local processing at sources unaffected
Can operate when sources unavailable
Can query data not stored in a DBMS
Extra information at warehouse
Modify,
summarize (store aggregates)
Add historical information
CS 245
Notes11
10
Advantages of Query-Driven
No need to copy data
less
storage
no need to purchase data
More up-to-date data
Query needs can be unknown
Only query interface needed at sources
May be less draining on sources
CS 245
Notes11
11
OLTP vs. OLAP
OLTP: On Line Transaction Processing
Describes
processing at operational sites
OLAP: On Line Analytical Processing
Describes
CS 245
processing at warehouse
Notes11
12
OLTP vs. OLAP
OLTP
OLAP
Mostly updates
Many small transactions
Mb-Tb of data
Raw data
Clerical users
Up-to-date data
Consistency,
recoverability critical
CS 245
Notes11
Mostly reads
Queries long, complex
Gb-Tb of data
Summarized,
consolidated data
Decision-makers,
analysts as users
13
Data Marts
Smaller warehouses
Spans part of organization
e.g.,
marketing (customers, products, sales)
Do not require enterprise-wide consensus
but
CS 245
long term integration problems?
Notes11
14
Warehouse Models & Operators
Data Models
relations
stars
& snowflakes
cubes
Operators
slice
& dice
roll-up, drill down
pivoting
other
CS 245
Notes11
15
Star
product
prodId
p1
p2
name price
bolt
10
nut
5
sale oderId date
o100 1/7/97
o102 2/7/97
105 3/8/97
customer
CS 245
custId
53
81
111
custId
53
53
111
prodId
p1
p2
p1
name
joe
fred
sally
Notes11
storeId
c1
c1
c3
address
10 main
12 main
80 willow
store
storeId
c1
c2
c3
qty
1
2
5
amt
12
11
50
city
nyc
sfo
la
city
sfo
sfo
la
16
Star Schema
product
prodId
name
price
sale
orderId
date
custId
prodId
storeId
qty
amt
customer
custId
name
address
city
store
storeId
city
CS 245
Notes11
17
Terms
Fact table
Dimension tables
Measures
product
prodId
name
price
sale
orderId
date
custId
prodId
storeId
qty
amt
customer
custId
name
address
city
store
storeId
city
CS 245
Notes11
18
Dimension Hierarchies
sType
store
store storeId
s5
s7
s9
city
cityId
sfo
sfo
la
tId
t1
t2
t1
mgr
joe
fred
nancy
region
sType tId
t1
t2
city
snowflake schema
constellations
CS 245
size
small
large
cityId pop
sfo
1M
la
5M
location
downtown
suburbs
regId
north
south
region regId
name
north cold region
south warm region
Notes11
19
Cube
Fact table view:
sale
prodId storeId
p1
c1
p2
c1
p1
c3
p2
c2
Multi-dimensional cube:
amt
12
11
50
8
p1
p2
c1
12
11
c2
c3
50
8
dimensions = 2
CS 245
Notes11
20
3-D Cube
Fact table view:
sale
prodId
p1
p2
p1
p2
p1
p1
storeId
c1
c1
c3
c2
c1
c2
Multi-dimensional cube:
date
1
1
1
1
2
2
amt
12
11
50
8
44
4
day 2
day 1
p1
p2 c1
p1
12
p2
11
c1
44
c2
4
c2
c3
c3
50
8
dimensions = 3
CS 245
Notes11
21
ROLAP vs. MOLAP
ROLAP:
Relational On-Line Analytical Processing
MOLAP:
Multi-Dimensional On-Line Analytical
Processing
CS 245
Notes11
22
Aggregates
• Add up amounts for day 1
• In SQL: SELECT sum(amt) FROM SALE
WHERE date = 1
sale
CS 245
prodId storeId
p1
c1
p2
c1
p1
c3
p2
c2
p1
c1
p1
c2
date
1
1
1
1
2
2
amt
12
11
50
8
44
4
Notes11
81
23
Aggregates
• Add up amounts by day
• In SQL: SELECT date, sum(amt) FROM SALE
GROUP BY date
sale
prodId storeId
p1
c1
p2
c1
p1
c3
p2
c2
p1
c1
p1
c2
CS 245
date
1
1
1
1
2
2
amt
12
11
50
8
44
4
Notes11
ans
date
1
2
sum
81
48
24
Another Example
• Add up amounts by day, product
• In SQL: SELECT date, sum(amt) FROM SALE
GROUP BY date, prodId
sale
prodId storeId
p1
c1
p2
c1
p1
c3
p2
c2
p1
c1
p1
c2
date
1
1
1
1
2
2
amt
12
11
50
8
44
4
sale
prodId
p1
p2
p1
date
1
1
2
amt
62
19
48
rollup
drill-down
CS 245
Notes11
25
Aggregates
Operators: sum, count, max, min,
median, ave
“Having” clause
Using dimension hierarchy
average
by region (within store)
maximum by month (within date)
CS 245
Notes11
26
Cube Aggregation
day 2
day 1
p1
p2 c1
p1
12
p2
11
p1
p2
c1
56
11
c1
44
c2
4
c2
c3
c3
50
8
c2
4
8
rollup
drill-down
CS 245
Example: computing sums
...
c3
50
sum
c1
67
c2
12
c3
50
129
p1
p2
Notes11
sum
110
19
27
Cube Operators
day 2
day 1
p1
p2 c1
p1
12
p2
11
c1
56
11
p1
p2
c1
44
c2
4
c2
...
c3
50
sale(c1,*,*)
8
c2
4
8
c3
50
sale(c2,p2,*)
CS 245
c3
sum
c1
67
c2
12
c3
50
129
p1
p2
Notes11
sum
110
19
sale(*,*,*)
28
Extended Cube
c2
4
8
c312
p1
p2
c1
*
12
p1
p2
c1*
44
c1
56
11
c267
4
c2
44
c3
4
50
11
23
8
8
50
*
62
19
81
*
day 2
day 1
CS 245
p1
p2
*
Notes11
c3
50
* 50
48
48
*
110
19
129
sale(*,p2,*)
29
Aggregation Using Hierarchies
day 2
day 1
p1
p2 c1
p1
12
p2
11
c1
44
c2
4
c2
c3
c3
50
customer
region
8
country
p1
p2
CS 245
region A region B
56
54
11
8
(customer c1 in Region A;
customers c2, c3 in Region B)
Notes11
30
Pivoting
Fact table view:
sale
prodId storeId
p1
c1
p2
c1
p1
c3
p2
c2
p1
c1
p1
c2
Multi-dimensional cube:
date
1
1
1
1
2
2
amt
12
11
50
8
44
4
day 2
day 1
p1
p2 c1
p1
12
p2
11
p1
p2
CS 245
Notes11
c1
56
11
c1
44
c2
4
c2
c3
c3
50
8
c2
4
8
c3
50
31
Query & Analysis Tools
Query Building
Report Writers (comparisons, growth, graphs,…)
Spreadsheet Systems
Web Interfaces
Data Mining
CS 245
Notes11
32
Other Operations
Time functions
e.g.,
Computed Attributes
e.g.,
time average
commission = sales * rate
Text Queries
e.g.,
find documents with words X AND B
e.g., rank documents by frequency of
words X, Y, Z
CS 245
Notes11
33
Data Mining
Decision Trees
Clustering
Association Rules
CS 245
Notes11
34
Decision Trees
Example:
• Conducted survey to see what customers were
interested in new model car
• Want to select customers for advertising campaign
sale
CS 245
custId
c1
c2
c3
c4
c5
c6
car
taurus
van
van
taurus
merc
taurus
age
27
35
40
22
50
25
Notes11
city newCar
sf
yes
la
yes
sf
yes
sf
yes
la
no
la
no
training
set
35
One Possibility
sale
custId
c1
c2
c3
c4
c5
c6
age<30
Y
N
city=sf
Y
CS 245
age
27
35
40
22
50
25
city newCar
sf
yes
la
yes
sf
yes
sf
yes
la
no
la
no
car=van
N
likely
car
taurus
van
van
taurus
merc
taurus
unlikely
Y
likely
N
unlikely
Notes11
36
Another Possibility
sale
custId
c1
c2
c3
c4
c5
c6
car=taurus
Y
N
city=sf
Y
CS 245
age
27
35
40
22
50
25
city newCar
sf
yes
la
yes
sf
yes
sf
yes
la
no
la
no
age<45
N
likely
car
taurus
van
van
taurus
merc
taurus
unlikely
Y
likely
N
unlikely
Notes11
37
Issues
Decision tree cannot be “too deep”
would not have statistically significant amounts of
data for lower decisions
Need to select tree that most reliably
predicts outcomes
CS 245
Notes11
38
Clustering
income
education
age
CS 245
Notes11
39
Another Example: Text
Each document is a vector
e.g.,
<100110...> contains words 1,4,5,...
Clusters contain “similar” documents
Useful for understanding, searching
documents
sports
international
news
business
CS 245
Notes11
40
Issues
Given desired number of clusters?
Finding “best” clusters
Are clusters semantically meaningful?
e.g.,
“yuppies’’ cluster?
Using clusters for disk storage
CS 245
Notes11
41
Association Rule Mining
sales
records:
tran1
tran2
tran3
tran4
tran5
tran6
cust33
cust45
cust12
cust40
cust12
cust12
p2,
p5,
p1,
p5,
p2,
p9
p5, p8
p8, p11
p9
p8, p11
p9
market-basket
data
• Trend: Products p5, p8 often bough together
• Trend: Customer 12 likes product p9
CS 245
Notes11
42
Association Rule
Rule: {p1, p3, p8}
Support: number of baskets where these
products appear
High-support set: support threshold s
Problem: find all high support sets
CS 245
Notes11
43
Finding High-Support Pairs
Baskets(basket, item)
SELECT I.item, J.item, COUNT(I.basket)
FROM Baskets I, Baskets J
WHERE I.basket = J.basket AND
I.item < J.item
WHY?
GROUP BY I.item, J.item
HAVING COUNT(I.basket) >= s;
CS 245
Notes11
44
Example
basket item
t1
p2
t1
p5
t1
p8
t2
p5
t2
p8
t2
p11
...
...
CS 245
basket item1 item2
t1
p2
p5
t1
p2
p8
t1
p5
p8
t2
p5
p8
t2
p5
p11
t2
p8
p11
...
...
...
Notes11
check if
count s
45
Issues
Performance for size 2 rules
big
basket
t1
t1
t1
t2
t2
t2
...
item
p2
p5
p8
p5
p8
p11
...
basket
t1
t1
t1
t2
t2
t2
...
item1
p2
p2
p5
p5
p5
p8
...
item2
p5
p8
p8
p8
p11
p11
...
even
bigger!
Performance for size k rules
CS 245
Notes11
46
Implementing a Warehouse
Monitoring: Sending data from sources
Integrating: Loading, cleansing,...
Processing: Query processing, indexing, ...
Managing: Metadata, Design, ...
CS 245
Notes11
47
Monitoring
Source Types: relational, flat file, IMS,
VSAM, IDMS, WWW, news-wire, …
Incremental vs. Refresh
customer
CS 245
id
53
81
111
name
joe
fred
sally
address
10 main
12 main
80 willow
Notes11
city
sfo
sfo
la
new
48
Periodic snapshots
Database triggers
Log shipping
Data shipping (replication service)
Transaction shipping
Polling (queries to source)
Screen scraping
Application level monitoring
CS 245
Notes11
Advantages & Disadvantages!!
Monitoring Techniques
49
Monitoring Issues
Frequency
periodic:
daily, weekly, …
triggered: on “big” change, lots of changes, ...
Data transformation
convert
data to uniform format
remove & add fields (e.g., add date to get history)
Standards (e.g., ODBC)
Gateways
CS 245
Notes11
50
Integration
Data Cleaning
Data Loading
Derived Data
Client
Client
Query & Analysis
Metadata
Warehouse
Integration
Source
CS 245
Notes11
Source
Source
51
Data Cleaning
Migration (e.g., yen dollars)
Scrubbing: use domain-specific knowledge (e.g.,
social security numbers)
Fusion (e.g., mail list, customer merging)
billing DB
customer1(Joe)
merged_customer(Joe)
service DB
customer2(Joe)
Auditing: discover rules & relationships
(like data mining)
CS 245
Notes11
52
Loading Data
Incremental vs. refresh
Off-line vs. on-line
Frequency of loading
At
night, 1x a week/month, continuously
Parallel/Partitioned load
CS 245
Notes11
53
Derived Data
Derived Warehouse Data
indexes
aggregates
materialized
views (next slide)
When to update derived data?
Incremental vs. refresh
CS 245
Notes11
54
Materialized Views
sale
Define new warehouse relations using
SQL expressions
prodId storeId
p1
c1
p2
c1
p1
c3
p2
c2
p1
c1
p1
c2
joinTb
CS 245
date
1
1
1
1
2
2
prodId
p1
p2
p1
p2
p1
p1
amt
12
11
50
8
44
4
name
bolt
nut
bolt
nut
bolt
bolt
product
price
10
5
10
5
10
10
Notes11
storeId
c1
c1
c3
c2
c1
c2
date
1
1
1
1
2
2
id
p1
p2
amt
12
11
50
8
44
4
name price
bolt
10
nut
5
does not exist
at any source
55
Processing
ROLAP servers vs. MOLAP servers
Index Structures
What to Materialize?
Algorithms
Client
Client
Query & Analysis
Metadata
Warehouse
Integration
Source
CS 245
Notes11
Source
Source
56
ROLAP Server
Relational OLAP Server
sale
prodId
p1
p2
p1
date
1
1
2
sum
62
19
48
tools
utilities
ROLAP
server
Special indices, tuning;
Schema is “denormalized”
relational
DBMS
CS 245
Notes11
57
MOLAP Server
Multi-Dimensional OLAP Server
Sales
M.D. tools
Product
B
A
milk
soda
eggs
soap
1
utilities
CS 245
multidimensional
server
Notes11
2 3 4
Date
could also
sit on
relational
DBMS
58
Index Structures
Traditional Access Methods
B-trees,
hash tables, R-trees, grids, …
Popular in Warehouses
inverted
lists
bit map indexes
join indexes
text indexes
CS 245
Notes11
59
Inverted Lists
18
19
20
21
22
23
25
26
age
index
CS 245
r5
r19
r37
r40
name age
joe
20
fred
20
sally
21
nancy 20
tom
20
pat
25
dave
21
jeff
26
...
20
23
rId
r4
r18
r19
r34
r35
r36
r5
r41
r4
r18
r34
r35
inverted
lists
Notes11
data
records
60
Using Inverted Lists
Query:
Get
people with age = 20 and name = “fred”
List for age = 20: r4, r18, r34, r35
List for name = “fred”: r18, r52
Answer is intersection: r18
CS 245
Notes11
61
Bit Maps
20
23
20
21
22
1
1
0
1
1
0
0
0
0
0
0
1
0
0
0
1
0
1
1
23
25
26
age
index
CS 245
bit
maps
Notes11
id
1
2
3
4
5
6
7
8
name age
joe
20
fred
20
sally
21
nancy 20
tom
20
pat
25
dave
21
jeff
26
...
18
19
data
records
62
Using Bit Maps
Query:
Get
people with age = 20 and name = “fred”
List for age = 20: 1101100000
List for name = “fred”: 0100000001
Answer is intersection: 010000000000
Good if domain cardinality small
Bit vectors can be compressed
CS 245
Notes11
63
Join
• “Combine” SALE, PRODUCT relations
• In SQL: SELECT * FROM SALE, PRODUCT
sale
prodId storeId
p1
c1
p2
c1
p1
c3
p2
c2
p1
c1
p1
c2
joinTb
CS 245
date
1
1
1
1
2
2
prodId
p1
p2
p1
p2
p1
p1
amt
12
11
50
8
44
4
name
bolt
nut
bolt
nut
bolt
bolt
product
price
10
5
10
5
10
10
Notes11
storeId
c1
c1
c3
c2
c1
c2
date
1
1
1
1
2
2
id
p1
p2
name price
bolt
10
nut
5
amt
12
11
50
8
44
4
64
Join Indexes
join index
product
sale
CS 245
id
p1
p2
rId
r1
r2
r3
r4
r5
r6
name price
bolt
10
nut
5
jIndex
r1,r3,r5,r6
r2,r4
prodId storeId
p1
c1
p2
c1
p1
c3
p2
c2
p1
c1
p1
c2
Notes11
date
1
1
1
1
2
2
amt
12
11
50
8
44
4
65
What to Materialize?
Store in warehouse results useful for
common queries
Example:
total sales
day 2
day 1
c1
c2
c3
p1
44
4
p2 c1
c2
c3
p1
12
50
p2
11
8
p1
p2
c1
56
11
c2
4
8
c3
50
materialize
CS 245
...
p1
c2
12
c3
50
129
p1
p2
Notes11
c1
67
c1
110
19
66
Materialization Factors
Type/frequency of queries
Query response time
Storage cost
Update cost
CS 245
Notes11
67
Cube Aggregates Lattice
129
all
c1
67
p1
c2
12
c3
50
city
city, product
p1
p2
c1
56
11
c2
4
8
product
city, date
date
product, date
c3
50
day 2
day 1
CS 245
c1
c2
c3
p1
44
4
p2 c1
c2
c3
p1
12
50
p2
11
8
city, product, date
Notes11
use greedy
algorithm to
decide what
to materialize
68
Dimension Hierarchies
all
cities
state
city
c1
c2
state
CA
NY
city
CS 245
Notes11
69
Dimension Hierarchies
all
city
city, product
product
city, date
date
product, date
state
city, product, date
state, date
state, product
state, product, date
not all arcs shown...
CS 245
Notes11
70
Interesting Hierarchy
time
all
years
weeks
quarters
day
1
2
3
4
5
6
7
8
week
1
1
1
1
1
1
1
2
month
1
1
1
1
1
1
1
1
quarter
1
1
1
1
1
1
1
1
year
2000
2000
2000
2000
2000
2000
2000
2000
conceptual
dimension table
months
days
CS 245
Notes11
71
Algorithms
Query Optimization
Parallel Processing
Data Mining
CS 245
Notes11
72
Example: Association Rules
How do we perform rule mining efficiently?
Observation: If set X has support t, then
each X subset must have at least support t
For 2-sets:
if
we need support s for {i, j}
then each i, j must appear in at least s baskets
CS 245
Notes11
73
Algorithm for 2-Sets
(1) Find OK products
those
appearing in s or more baskets
(2) Find high-support pairs
using only OK products
CS 245
Notes11
74
Algorithm for 2-Sets
INSERT INTO okBaskets(basket, item)
SELECT basket, item
FROM Baskets
GROUP BY item
HAVING COUNT(basket) >= s;
Perform mining on okBaskets
SELECT I.item, J.item, COUNT(I.basket)
FROM okBaskets I, okBaskets J
WHERE I.basket = J.basket AND
I.item < J.item
GROUP BY I.item, J.item
HAVING COUNT(I.basket) >= s;
CS 245
Notes11
75
Counting Efficiently
One way:
basket I.item J.item
t1
p5
p8
t2
p5
p8
t2
p8
p11
t3
p2
p3
t3
p5
p8
t3
p2
p8
...
...
...
CS 245
sort
threshold = 3
basket I.item J.item
t3
p2
p3
t3
p2
p8
t1
p5
p8
t2
p5
p8
t3
p5
p8
t2
p8
p11
...
...
...
Notes11
count &
remove
count I.item J.item
3
p5
p8
5
p12 p18
...
...
...
76
Counting Efficiently
Another way:
basket I.item J.item
t1
p5
p8
t2
p5
p8
t2
p8
p11
t3
p2
p3
t3
p5
p8
t3
p2
p8
...
...
...
scan &
count
threshold = 3
count I.item J.item
1
p2
p3
2
p2
p8
3
p5
p8
5
p12
p18
1
p21
p22
2
p21
p23
...
...
...
remove
count I.item J.item
3
p5
p8
5
p12 p18
...
...
...
keep counter
array in memory
CS 245
Notes11
77
Yet Another Way
basket I.item J.item
t1
p5
p8
t2
p5
p8
t2
p8
p11
t3
p2
p3
t3
p5
p8
t3
p2
p8
...
...
...
(1)
scan &
hash &
count
(2) scan &
remove
false positive
CS 245
count
1
5
2
1
8
1
...
bucket
A
B
C
D
E
F
...
in-memory
hash table
in-memory
counters
basket I.item J.item
t1
p5
p8
t2
p5
p8
t2
p8
p11
t3
p5
p8
t5
p12 p18
t8
p12 p18
...
...
...
Notes11
threshold = 3
count I.item J.item
3
p5
p8
5
p12 p18
...
...
...
(4) remove
count I.item J.item
3
p5
p8
1
p8
p11
5
p12
p18
...
...
...
(3) scan& count
78
Discussion
frequency
Hashing scheme: 2 (or 3) scans of data
Sorting scheme: requires a sort!
Hashing works well if few high-support pairs
and many low-support ones
iceberg queries
threshold
item-pairs ranked by frequency
CS 245
Notes11
79
Managing
Metadata
Warehouse Design
Tools
Client
Client
Query & Analysis
Metadata
Warehouse
Integration
Source
CS 245
Notes11
Source
Source
80
Metadata
Administrative
definition
of sources, tools, ...
schemas, dimension hierarchies, …
rules for extraction, cleaning, …
refresh, purging policies
user profiles, access control, ...
CS 245
Notes11
81
Metadata
Business
business
terms & definition
data ownership, charging
Operational
data
lineage
data currency (e.g., active, archived, purged)
use stats, error reports, audit trails
CS 245
Notes11
82
Design
What data is needed?
Where does it come from?
How to clean data?
How to represent in warehouse (schema)?
What to summarize?
What to materialize?
What to index?
CS 245
Notes11
83
Tools
Development
Planning & Analysis
performance monitoring, usage patterns, exception reporting
System & Network Management
what-if scenarios (schema changes, refresh rates), capacity planning
Warehouse Management
design & edit: schemas, views, scripts, rules, queries, reports
measure traffic (sources, warehouse, clients)
Workflow Management
“reliable scripts” for cleaning & analyzing data
CS 245
Notes11
84
Current State of Industry
Extraction and integration done off-line
Usually
in large, time-consuming, batches
Everything copied at warehouse
Not
selective about what is stored
Query benefit vs storage & update cost
Query optimization aimed at OLTP
High
throughput instead of fast response
Process whole query before displaying
anything
CS 245
Notes11
85
Future Directions
Better performance
Larger warehouses
Easier to use
What are companies & research labs
working on?
CS 245
Notes11
86
Research (1)
Incremental Maintenance
Data Consistency
Data Expiration
Recovery
Data Quality
Error Handling (Back Flush)
CS 245
Notes11
87
Research (2)
Rapid Monitor Construction
Temporal Warehouses
Materialization & Index Selection
Data Fusion
Data Mining
Integration of Text & Relational Data
CS 245
Notes11
88
Conclusions
Massive amounts of data and
complexity of queries will push limits
of current warehouses
Need better systems:
easier
to use
provide quality information
CS 245
Notes11
89