Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

DB2 10.1 DBA for Linux, UNIX, and Windows certification exam 611 prep, Part 2: Physical design

Mohamed Obide (mobide@eg.ibm.com), Consulting IT Specialist, IBM
Mohamed Obide
Mohamed Obide is an IBM certified Level 2 IT specialist with IBM Egypt's Technology Development Center for 10 years and an overall IT experience of 18 years. He is currently leading IBM's Information Management Technology Ecosystem (IMTE) in Cairo and acting as IM practice leader in the Middle East and Africa. He provides support on database migration projects and DB2 and services on all IM products in the region. His areas of expertise include product development, database architecture, data integration, and performance tuning.
Anas Mosaad (amosaad@eg.ibm.com), IT Specialist, IBM
Anas Mosaad
Anas Mosaad is a DB2 solutions migration consultant with IBM Egypt. Anas has more than six years of experience in the software development industry. He is a member of the IBM's Information Management Technology Ecosystem Team focusing on enabling and porting customer, business partner, and independent software vendor (ISV) solutions to IBM DB2. His expertise includes portal and J2EE development, database design, and database application development.
Adel El-Metwally (adel@eg.ibm.com), IT Specialist, IBM
Adel El-Metwally
Adel El-Metwally is an IT specialist with IBM Egypt's Technology Development Center and is a certified DB2 advanced database administrator. He is currently a member of IBM's Information Management Technology Ecosystem (IMTE), working on database migration projects and DB2 administration consulting. His areas of expertise include application development and database administration.
Mohamed El-Bishbeashy
Mohamed El-Bishbeashy works as an IT specialist for IBM Cairo Technology Development Center (C-TDC), Software Group. He has 10 years of experience in the software development industry, five of which are within IBM. His technical experience includes application and product development, DB2 administration, and persistence layer design and development. He is an IBM Certified Advanced DBA and IBM Certified Application Developer. Currently, he is a member of the Information Management Technology Ecosystem (IMTE) team as a DB2 database migration specialist.

Summary:  This tutorial discusses the creation of IBM DB2® databases, as well as various methods used for placing and storing objects within a database. The focus is on partitioning, compression, and XML, which are all important performance and application development concepts you need to store and access data quickly and efficiently. This is second in a series of eight tutorials you can use to help you prepare for the DB2 10.1 DBA for Linux®, UNIX®, and Windows® certification exam 611. The material here primarily covers the objectives in Section 2 of the exam.

View more content in this series

Date:  31 Jan 2013
Level:  Intermediate PDF:  A4 and Letter (1094 KB | 56 pages)Get Adobe® Reader®

Activity:  5114 views
Comments:  

Table compression

You can use less disk space for your tables by taking advantage of the DB2 table compression capabilities. Compression saves disk storage space by using fewer database pages to store data. You can use compression with new and existing tables. Temporary tables are also compressed automatically, if the database manager deems it to be advantageous to do so. Row compression uses a dictionary-based compression algorithm to replace recurring strings with shorter symbols within data rows.

Table row compression types

There are two types of row compression you can choose from:

  • Classic row compression
  • Adaptive compression

Data stored within data rows, including inlined LOB or XML values, can be compressed with adaptive and classic row compression. XML storage objects can be compressed using static compression. However, storage objects for long data objects stored outside table rows is not compressed.


Classic row compression

Classic row compression, sometimes referred to as static compression, uses a table-level compression dictionary to compress data by row. The dictionary is used to map repeated byte patterns from table rows to much smaller symbols; these symbols then replace the longer byte patterns in the table rows. The compression dictionary is stored with the table data rows in the data object portions of the table.

Using row compression

To use row compression, you must first set the table to be compression eligible, then you must generate the dictionary that contains the common strings from within the table. To set the table to be eligible for compression, use either of the following commands: create table table_name ... compress yes static or alter table table name compress yes static.

Creating the row compression dictionary

Creating the compression dictionary allows the table to be compressed. DB2 then needs to scan the data in the table to find the common strings it can compress out of the table and put in the dictionary. To do this, you use the reorg command. The first time you compress a table (or to rebuild the compression dictionary) you must run the command reorg table table_name resetdictionary.

This will scan the table, create the dictionary, and perform the actual table reorganization, compressing the data as it goes. From this point onward, any insert into this table or subsequent load of data will honor the compression dictionary and compress all new data. If in the future you want to run a normal table reorg and not rebuild the dictionary, you can run reorg table table_name keepdictionary.

Each table has its own dictionary, meaning that a partitioned table will have a separate dictionary for each partition. This is good because it allows DB2 to adapt to changes in the data as you roll in a new partition.

To disable compression for a table, use the ALTER TABLE statement with the COMPRESS NO option; rows you later add are not compressed. Existing rows remain compressed. To extract the entire table after you turn off compression, you must perform table reorganization with the REORG TABLE command:

alter table tablename compress no
reorg table table_name
                


Adaptive compression

Adaptive compression actually uses two compression approaches. The first employs the same table-level compression dictionary used in classic row compression to compress data based on repetition within a sampling of data from the table as a whole. The second approach uses a page-level dictionary-based compression algorithm to compress data based on data repetition within each page of data. The dictionaries map repeated byte patterns to much smaller symbols; these symbols then replace the longer byte patterns in the table. The table-level compression dictionary is stored within the table object for which it is created and is used to compress data throughout the table. The page-level compression dictionary is stored with the data in the data page and is used to compression only the data within that page.

Using adaptive compression

You compress table data using adaptive compression by setting the COMPRESS attribute of the table to YES ADAPTIVE or to YES, which by default enables adaptive compression. You can set this attribute when you create the table by running the command create table tablename .. compress yes adaptive or create table tablename .. compress yes.

You can also alter an existing table to use compression by using the same options for the ALTER TABLE statement alter table tablename compress yes adaptive or alter table tablename compress yes.

HINT: If you have scripts or applications that issue the ALTER TABLE or CREATE TABLE statements with the COMPRESS YES clause, make sure you add the STATIC or ADAPTIVE keyword to explicitly indicate the table compression method you want.

After you enable compression, operations that add data to the table, such as an INSERT, LOAD INSERT, or IMPORT INSERT command operation, can use adaptive compression. In addition, index compression is enabled for the table. Indices are created as compressed indices unless you specify otherwise and if they are the types that can be compressed.

To disable compression for a table, use the ALTER TABLE statement with the COMPRESS NO option; rows that you later add are not compressed. Existing rows remain compressed. To extract the entire table after you turn off compression, you must perform a table reorganization with the REORG TABLE command.


Compress temp tables

Compression for temporary tables is enabled automatically with the DB2 Storage Optimization Feature. Only classic row compression is used for temporary tables. When executing queries, the DB2 optimizer considers the storage savings and the impact on query performance that compression of temporary tables offers to determine whether it is worthwhile to use compression. If it is worthwhile, compression is used automatically.


Estimating space savings

The ADMIN_GET_TAB_COMPRESS_INFO table function estimates the compression savings that can be gained for the table, assuming a REORG with RESETDICTIONARY option will be performed. The following example uses the ADMIN_GET_TAB_COMPRESS_INFO table function to estimate percentage saved for classic and adaptive compression if enabled on the DB2INST1.CUSTOMERS table:

 
SELECT TABNAME, OBJECT_TYPE, ROWCOMPMODE, PCTPAGESSAVED_CURRENT current, 
   PCTPAGESSAVED_STATIC with_static, PCTPAGESSAVED_ADAPTIVE with_adaptive 
   FROM TABLE(SYSPROC.ADMIN_GET_TAB_COMPRESS_INFO('DB2INST1','CUSTOMERS')) AS T
                


Figure 8. Result for the example using ADMIN_GET_TAB_COMPRESS_INFO table function
Image                         shows result for the example using ADMIN_GET_TAB_COMPRESS_INFO table function

7 of 12 | Previous | Next

Comments



static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Information Management
ArticleID=856797
TutorialTitle=DB2 10.1 DBA for Linux, UNIX, and Windows certification exam 611 prep, Part 2: Physical design
publish-date=01312013
author1-email=mobide@eg.ibm.com
author1-email-cc=
author2-email=amosaad@eg.ibm.com
author2-email-cc=
author3-email=adel@eg.ibm.com
author3-email-cc=
author4-email=mohamedb@eg.ibm.com
author4-email-cc=