This document compares and contrasts row-organized tables and column-organized tables in DB2. Row-organized tables are better suited for OLTP workloads as they are efficient for transactional operations but can be I/O intensive. Column-organized tables are better for OLAP workloads as they provide efficient data compression and more rapid columnar operations like aggregation. DB2 introduces column-organized tables to optimize analytic query performance for workloads that access more than 5-10% of data. Both table organizations can co-exist in the same database, tablespace or schema.
3. DB2 uses row-organized tables
Good for OLTP
Storage required for tables and indexes
Fetching Large table is i/o Intensive
What are we doing now
4. Row Organized Table
Employee ID Last Name First Name Salary
1 Manager SuperPay 10000000
2 DBA HighPressure 80000
3 Programmer BlameDBA 100000
4 Tester BlameAllOthers 100000
5 CEO Iam Boss 1000000000000000
1, Manager, SuperPay, 10000000; 2, DBA, Highpressure, 80000; 3, Programmer, BlameDBA, 100000
PAGE 1 PAGE 2
5. Works like this
db2 “select salary from schema.employee where salary < 20000000”;
Employee ID Last Name First Name Salary
1 Manager Super Pay 10000000
2 DBA High Pressure 80000
3 Programmer Blame DBA 100000
4 Tester Blame All Others 100000
5 CEO Iam Boss 1000000000000000
Employee ID Last Name First Name Salary
1 Manager Super Pay 10000000
2 DBA High Pressure 80000
3 Programmer Blame DBA 100000
4 Tester Blame All Others 100000
db2 “select c1, c2, c3 from column100 where <>”;
97%
6. DB2 introduces column-organized tables
Good for OLAP
Efficient Compression
What’s New
7. How do I create…
db2 "CREATE TABLE <emp> (colname datatype)
ORGANIZE BY COLUMN;
OR
Set DB CFG : dft_table_org
OR
Set DB2_WORKLOAD registry variable to ANALYTICS
8. How does it look?
ID
1
2
3
4
5
Last Name
Manager
DBA
Programmer
Tester
CEO
First Name
Superpay
Highpressure
BlameDBA
Blameallothers
IamBoss
Salary
1000000
80000
100000
100000
100000000000
PAGE 1 PAGE 2 PAGE 3
Employee ID Last Name First Name Salary
1 Manager SuperPay 10000000
2 DBA HighPressure 80000
3 Programmer BlameDBA 100000
4 Tester BlameAllOthers 100000
5 CEO IamBoss 1000000000000000
1 2 3 4 5 Manager DBA Programmer
Tester CEO
Superpay Highpressure BlameDBA
Blameallothers IamBoss
Highly Efficient Compression
10. Perform Efficient reads
Store Data in a compressed format
Achieve disk savings
Reduce I/O
Rapid columnar operations- MIN, MAX, SUM, COUNT and
AVG
Goal is to
11. OLAP/DSS systems
Fetch subset of columns
Optimize analytic query performance
Workloads accesses more than 5-10% of data
Ideal to use with…
12. Which one to choose?
Row Organized Table Column Organized Table
Suitable for OLTP Suitable for OLAP
I/O intensive Reduced I/O
Limited compression Efficient compression
Can co-exist in the same DB, TBSP or Schema