DB2 10.5 – How to Compress CLOB Columns

compressiondb2db2-10.5db2-luw

I have a table with a CLOB(1M). If I enable compression (compression yes adaptive) on the the table the CLOB is not compressed. Is there a way to make this work in DB2 10.5?

Best Answer

Historically LOB data are stored in data structures separate from the normal row data, these data structures are not compressed. With Db2 for LUW 9.7 and later you have an option to store part of LOB columns, subject to the row length limitation, inline with data rows. Inline LOB data will be compressed along with the rows they belong to.

CREATE TABLE foo (
  lob_col CLOB (1M) INLINE LENGTH 2000
)

This is only helpful if the majority of your LOB values fall within the inline length limit. Note also that storing LOBs inline can have impact on query performance (fewer rows fit on a page, thus potentially increasing I/O demand) and logging overhead (inlined LOBs are always logged).