1
2010 Calpont Corporation
The Thinking Person’s Guide to Data Warehouse Design
Robin SchumacherVP Products
Calpont
2
2010 Calpont Corporation
Agenda
Building a logical design
Transitioning to a physical design
Monitoring and tuning the design
3
2010 Calpont Corporation
Building a logical design
4
2010 Calpont Corporation
Why care about design…?
5
2010 Calpont Corporation
What is the key component for success?
In other words, what you do with your MySQL Server – in terms of physical design, schema design, and
performance design – will be the biggest factor on whether a BI system hits the mark…
* Philip Russom, “Next Generation Data Warehouse Platforms”, TDWI, 2009.
*
6
2010 Calpont Corporation
First – get/use a modeling tool
7
2010 Calpont Corporation
The logical design for OLTP
8
2010 Calpont Corporation
Simple reporting databases
OLTP Database Read Shard OneReporting Database
Application Servers
End Users
ETL
Just use the same design on a different box…
Replication
9
2010 Calpont Corporation
Horror story number one…
10
2010 Calpont Corporation
The logical design for analytics/data warehousing
11
2010 Calpont Corporation
Logical Design Considerations
• Datatypes are more generally defined, not directed toward a database engine
• Entities aren’t designed for performance necessarily• Redundancy is avoided, but simplicity is still a goal• Bottom line: you want to make sure your data is correctly
represented and is easily understood (new class of user today)
12
2010 Calpont Corporation
Manual horizontal partitioningModeling technique to overcome large data volumes
13
2010 Calpont Corporation
Manual Vertical PartitioningModeling technique to overcome wide tables/rows
14
2010 Calpont Corporation
Pro’s/con’s to manual partitioning
• More tables to manage• More referential integrity to
manage• More indexes to manage• Joins oftentimes needed to
accomplish query requests• Oftentimes, a redesign is
needed because the rows / columns you thought you’d be accessing together change; it’s hard to predict ad-hoc query traffic
• Less I/O if design holds up• Easy to prune obsolete data• Possibly less object contention
Pro’s
Con’s
15
2010 Calpont Corporation
The bottom line on logical modeling
• Use a modeling tool to capture your designs• Do not utilize a third-normal form design for analytics; keep it
simple and understandable• Manual partitioning is OK in some cases, but,..• Let the database engine do the work for you
16
2010 Calpont Corporation
Transitioning to a physical design
17
2010 Calpont Corporation
SQL or NoSQL…?
Row or Column database…?
How to scale…?
Should I worry about High availability…?
Index or no…?
How should I partition my data…?
Is sharding a good idea…?
18
2010 Calpont Corporation
General list of top BI database design decisions
• General architecture / data orientation
• Storage engine selection• Physical table/Index
partitioning• Indexing creation and
placement• Optimizing data loads
19
2010 Calpont Corporation
Divide & conquer is the best approach
• Whether you choose to go NoSQL, Shard with normal or special MySQL engines, use MPP storage engines, or something similar, divide & conquer is your best friend
• You can scale-up and divide & conquer to a point, but you will hit disk, memory, or other limitations
• Scaling up and out is the best future proof methodology
20
2010 Calpont Corporation
Divide & conquer via sharding
21
2010 Calpont Corporation
What technologies you should be looking at
* Philip Russom, “Next Generation Data Warehouse Platforms”, TDWI, 2009.
*
22
2010 Calpont Corporation
Row or column-based engine?
Yes, Row-based tables! Yes, Column-based tables!
Will need most columns in a table for query
Only need subset of columns for query
Will be doing lots of single inserts/deletes
Need very fast loads; little DML
Small-medium data Medium-very large data
Know exactly what to index; won’t change
Very dynamic; query patterns change
23
2010 Calpont Corporation
Column vs. row orientation
A column-oriented architecture looks the same on the surface, but stores data differently than legacy/row-based databases…
24
2010 Calpont Corporation
Example: InfiniDB vs. “Leading” row DB
InfiniDB takes up 22% less space InfiniDB loaded data 22% faster
InfiniDB total query times were 65% less InfiniDB average query times were 59% less
Notice not only are
the queries faster, but also more
predictable
* Tests run on standalone machine: 16 CPU, 16GB RAM, CentOS 5.4 with 2TB of raw data
25
2010 Calpont Corporation
Why not use both…?
• You can create a hybrid system where you use row-based tables and column-based tables in the same instance and same database
• Use InnoDB for OLTP or MyISAM for certain read operations
• Use column-based tables for analytics, data marts, or warehouses
• You can scale out with column tables and use row-based tables locally
26
2010 Calpont Corporation
Why not use both…?
27
2010 Calpont Corporation
MyISAM
Archive
Memory
CSV
• High-speed query/insert engine• Non-transactional, table locking• Good for data marts, small
warehouses
• Compresses data by up to 80%• Fastest for data loads• Only allows inserts/selects• Good for seldom accessed data
• Main memory tables• Good for small dimension tables• B-tree and hash indexes
• Comma separated values• Allows both flat file access and
editing as well as SQL query/DML• Allows instantaneous data loads
Also:Merge for pre-5.1 partitioning
Most used DW Storage engines internal to MySQL
28
2010 Calpont Corporation
What about NoSQL options?
• Standard model is not relational• Typically don’t use SQL to
access the data• Take up more space than
column databases• Lack special optimizers /
features to reduce I/O• Really are row-oriented architectures that store data in
‘column families, which are expected to be accessed together (remember logical vertical partitioning?) Individual columns cannot be accessed independently
• Will be faster with individual insert and delete operations• Will normally be faster with single row requests• Will lag in typical analytic / data warehouse use cases
2010 Calpont Corporation
Partitioning – not ‘if’ but ‘how’mysql> CREATE TABLE part_tab
-> ( c1 int ,c2 varchar(30) ,c3 date )
-> PARTITION BY RANGE (year(c3)) (PARTITION p0 VALUES LESS THAN (1995),
-> PARTITION p1 VALUES LESS THAN (1996) , PARTITION p2 VALUES LESS THAN (1997) ,
-> PARTITION p3 VALUES LESS THAN (1998) , PARTITION p4 VALUES LESS THAN (1999) ,
-> PARTITION p5 VALUES LESS THAN (2000) , PARTITION p6 VALUES LESS THAN (2001) ,
-> PARTITION p7 VALUES LESS THAN (2002) , PARTITION p8 VALUES LESS THAN (2003) ,
-> PARTITION p9 VALUES LESS THAN (2004) , PARTITION p10 VALUES LESS THAN (2010),
-> PARTITION p11 VALUES LESS THAN MAXVALUE );
mysql> create table no_part_tab (c1 int,c2 varchar(30),c3 date);
*** Load 8 million rows of data into each table ***
mysql> select count(*) from no_part_tab where c3 > date '1995-01-01' and c3 < date '1995-12-31';
+----------+
| count(*) |
+----------+
| 795181 |
+----------+
1 row in set (38.30 sec)
mysql> select count(*) from part_tab where c3 > date '1995-01-01' and c3 < date '1995-12-31';
+----------+
| count(*) |
+----------+
| 795181 |
+----------+
1 row in set (3.88 sec)
90% Response Time Reduction
2010 Calpont Corporation
Partitioning – Stripe your Partitions
CREATE TABLE T1 (col1 INT, col2 CHAR(5), col3 DATE) ENGINE=MYISAM
PARTITION BY HASH(col1)
(
PARTITION P1
DATA DIRECTORY = '/appdata1/data',
PARTITION P2
DATA DIRECTORY = '/appdata2/data',
PARTITION P3
DATA DIRECTORY = '/appdata3/data’,
PARTITION P4
DATA DIRECTORY = '/appdata4/data’
);
Note that striping only works for some engines (e.g. MyISAM, Archive) and for only certain operating systems (e.g. the option is ignored on Windows). You can use the REORGANIZE PARTITION command to move current partitions to new devices.
2010 Calpont Corporation
Partitioning – Smart Data Pruning
mysql> delete from t2 where
-> c3 > date '1995-01-01' and c3 < date '1995-12-31';
Query OK, 805114 rows affected (47.41 sec)
Most data warehouses have pruning or obsolete data operations that remove unwanted data. Using partitioning allows you to much more quickly and efficiently remove obsolete data:
mysql> alter table t1 drop partition p1;
Query OK, 0 rows affected (0.03 sec)
Records: 0 Duplicates: 0 Warnings: 0
VS.
The DROP PARTITION is A DDL operation, which runs much faster than a DML DELETE.
32
2010 Calpont Corporation
Index Creation and Placement
• If query patterns are known and predictable, and data is relatively static, then indexing isn’t that difficult
• If the situation is a very ad-hoc environment, indexing becomes more difficult. Must analyze SQL traffic and index the best you can
• Over-indexing a table that is frequently loaded / refreshed / updated can severely impact load and DML performance. Test dropping and re-creating indexes vs. doing in-place loads and DML. Realize, though, any queries will be impacted from dropped indexes
• Index maintenance (rebuilds, etc.) can cause issues in MySQL (locking, etc.)
• Remember some storage engines don’t support normal indexes (Archive, CSV)
• Remember that a benefit of (most) column databases is that they do not need or use indexes
33
2010 Calpont Corporation
Optimizing for data loads
• The two biggest killers of load performance are (1) very wide tables for row-based tables; (2) many indexes on a table;
• Stating the obvious, LOAD DATA INFILE and the high-speed loaders of column-based engines are the fastest way to load data vs. singleton or array insert statements
• Column-based tables typically load faster than row-based tables with load utilities, however they will experience slower insert/delete rates than row-based tables
• Loading data in primary key format helps some engines (e.g. InnoDB).
34
2010 Calpont Corporation
Optimizing for data loads
• Move the data as close to the database as possible; avoid having applications on remote machines do data manipulations and send data across the wire a row at a time – perhaps the worst way to load data
• Oftentimes good to create staging tables then use procedural language to do data modifications and/or create flat files for high speed loaders
• Loading data via time-based order helps some column databases like InfiniDB; logical range partitioning is then possible
35
2010 Calpont Corporation
Monitoring and tuning the design
36
2010 Calpont Corporation
Three performance analysis methods
Bottleneck analysis
Workload analysis
Ratio analysis
37
2010 Calpont Corporation
Bottleneck analysis
• The focus of this methodology is the answer to the question “what am I waiting on?”
• With MySQL, unfortunately, it can be difficult to determine latency in the database server
• Lock contention rarely an issue in data warehouses• New MySQL performance schema has a ways to go in my
opinion to be truly useful for bottleneck analysis• Problems found in bottleneck analysis translate into better
lock handling in the app, partitioning improvements, better indexing, or storage engine replacement
38
2010 Calpont Corporation
Workload analysis
• The focus of this methodology is the answer to three questions: (1) Who’s logged on?; (2) What are they doing?; (3) How is my machine handing it?
• Monitor active and inactive sessions. Keep in mind idle connections do take up resources
• I/O and ‘hot objects’ a key area of analysis• Key focus should be on SQL statement monitoring and
collection; something that goes beyond standard pre-production EXPLAIN analysis
39
2010 Calpont Corporation
Horror story number two…
40
2010 Calpont Corporation
The pain of slow SQL
* Philip Russom, “Next Generation Data Warehouse Platforms”, TDWI, 2009.
41
2010 Calpont Corporation
Workload analysis
• SQL analysis basically becomes bottleneck analysis, because you’re asking where your SQL statement is spending its time
• Once you have collected and identified your ‘top SQL’, the next step is to do tracing and interrogation into each SQL statement to understand its execution
• Historical analysis is important too; a query that ran fine with 5 million rows may tank with 50 million or with more concurrent users
• Design changes usually involve data file striping, indexing, partitioning, or parallel processing additions
42
2010 Calpont Corporation
Ratio analysis
• Least useful of all the performance analysis methods
• May be OK to get a general rule of thumb as to how various resources are being used
• Do not be misled by ratios; for example, a high cache hit ratio is sometimes meaningless. Databases can be brought to their knees by excessive logical I/O
• Design changes from ratios typically include the altering of configuration parameters and sometimes indexing
43
2010 Calpont Corporation
Conclusions
• Design is the #1 contributor to the overall performance and availability of a system
• With MySQL, you have greater flexibility and opportunity than ever before to build well-designed data warehouses
• With MySQL, you now have more options and features available than ever before
• The above translates into you being able to design data warehouses that can be future proofed: they can run as fast as you’d like (hopefully) and store as much data as you need (ditto)
44
2010 Calpont Corporation
For More Information
• Download InfiniDB Community Edition• Download InfiniDB documentation• Read InfiniDB technical white papers• Read InfiniDB intro articles on MySQL dev zone• Visit InfiniDB online forums• Trial the InfiniDB Enterprise Edition: http://www.calpont.com
www.infinidb.orgwww.calpont.com
45
2010 Calpont Corporation
The Thinking Person’s Guide to Data Warehouse Design
Robin [email protected]