DB2 Row Compression Strategies

By Tom Nonmacher

Managing the size of your databases is a critical aspect of database management. One of the strategies that you can employ to achieve this is row compression. In today's blog post, we'll look at how you can implement row compression strategies in DB2 11.1, and compare this with the similar features available in SQL Server 2016, SQL Server 2017, MySQL 5.7, and Azure SQL.

Row compression in DB2 11.1 works by reducing the amount of physical storage required to store data. It works by using a technique known as value compression, which minimizes the space required to store NULL and default values. For example, you can use the following command to enable row compression:

ALTER TABLE table_name ROW COMPRESSION COMPRESS YES;

Remember to run the REORG command after altering the table. This command removes fragmented free space in the table, making the data storage more efficient. It is also important to note that the actual space savings from row compression will depend on the nature of your data, and the ratio of NULL and default values present.

SQL Server 2016 and 2017 also provide a similar feature known as data compression that can help reduce the size of your databases. You can use the following command to enable row compression:

ALTER TABLE table_name REBUILD WITH (DATA_COMPRESSION = ROW);

SQL Server's data compression feature also supports page compression, which is a more advanced form of compression that can provide even greater space savings. However, it requires more CPU resources, so you need to balance the need for space savings with the available CPU resources.

MySQL 5.7, on the other hand, does not have a built-in row compression feature. However, you can use third-party storage engines such as InnoDB, which supports a form of row compression known as compact row format. You can enable it using the following command:

ALTER TABLE table_name ROW_FORMAT=COMPACT;

Azure SQL, being a cloud-based database service, provides a feature known as Azure Data Compression. This feature allows you to compress data at the row level, page level, or column level, depending on your needs. You can enable row compression using the following command:

ALTER TABLE table_name REBUILD PARTITION = ALL WITH (DATA_COMPRESSION = ROW);

In conclusion, row compression is a valuable tool for managing the size of your databases. It can not only help save storage space but also improve the performance of your database operations by reducing the amount of I/O required to retrieve data. However, the actual benefits will depend on the nature of your data and the specific database technology you are using.

DB2



A21515
Please enter the code from the image above in the box below.