Row-level compression compresses individual rows in a table.
Row-level compression is intended for fixed-length, regular data. For most fixed-length columns, data does not completely occupy the space reserved for the row. For example, a 32-bit integer with a value of 2 is represented by 0x10 in hexadecimal. SAP ASE requires 1 byte to represent this value, but fills the other 3 bits of the row with zeros. Similarly, if a 50-byte fixed-length character column includes the character data “a”, SAP ASE requires 1 byte for the character data, but completes the column with zeros.
Some fixed-length datatypes are not compressed because there is no benefit in doing so. For example, SAP ASE uses only 1 byte to store a tinyint, so compressing a row using this datatype is not beneficial.
create table t1 (col1 char(1) not null, col2 char(50) not null, col3 tinyint not null, col4 int not null, col5 varchar(20)) lock datapages
alter table t1 set compression = row
SAP ASE does not compress col1 and col3 because their length is 1 byte. SAP ASE compresses col2 and col4 and stores required information about decompression for each column using the minimum space, if required.
insert t1 values ( "a", "aaaaa", 1, 100, "NineBytes")
When uncompressed, the value of col2, char(50) is “aaaaa” with 45 blanks to fill out the rest of the column. After compression, the value of col2 is “aaaaa”, using one byte for each “a”.
The value of col4 is 100, and is represented with a single byte.
Trailing blanks are truncated from the value of col5; 9 bytes to store the value.