Back to Writing Partitioned Tables to Disk

Persisting Tables · Writing Partitioned Tables to Disk · Practice Question

Check Whether a Column Was Persisted with Compression

Sign in to track your progress

Question

After persisting the table to disk, how can you confirm whether or not compression was applied to a specific column?

Solution

-21! `:/hdb/2025.01.15/t/price

For an uncompressed column, the result is empty.

Example output for a compressed column:

compressedLength  | 2082
uncompressedLength| 2728
algorithm         | 2i
logicalBlockSize  | 17i
zipLevel          | 6i

Explanation

-21! is the kdb+ internal function for inspecting the compression metadata of an on-disk column file. It takes a file path symbol and, for a compressed file, returns a dictionary with five keys:

KeyMeaning
compressedLengthSize of the column file on disk in bytes
uncompressedLengthSize of the data when loaded into memory
algorithmCompression algorithm: 1i=q IPC, 2i=gzip, 3i=snappy, 4i=lz4hc, 5i=zstd
logicalBlockSizeThe power-of-2 block size used during compression (17 = 2^17 = 128 KB)
zipLevelCompression effort, 1–9 (for gzip)

If the result is empty, the file was written without compression — the default when no compression settings have been specified.

The function operates on any binary column file path — it does not require the database to be loaded or .Q.par to be used. You can check any column by supplying its full path directly:

-21! `:/hdb/2025.01.15/t/sym
-21! `:/hdb/2025.01.15/t/qty

This is the standard first step when diagnosing storage footprint or verifying that a compression job ran correctly.