v.24.7Experimental Feature

Change Binary Serialization of Variant Data Type to Include Compact Mode

Change binary serialization of the Variant data type: add compact mode to avoid writing the same discriminator multiple times for granules with single variant or with only NULL values. Add MergeTree setting use_compact_variant_discriminators_serialization that is enabled by default. Note that Variant type is still experimental and backward-incompatible change in serialization is ok. #62774 (Kruglov Pavel).
Change the binary serialization of the Variant data type by introducing a compact mode that reduces redundant writing of the discriminator for granules containing a single variant or only NULL values.

Why it matters

The feature aims to optimize storage efficiency and improve serialization performance for the Variant data type by avoiding repeated writing of the same discriminator value when it is unnecessary. This reduces data size and overhead when working with granules that have uniform variant types or only NULLs.

How to use it

Enable the new serialization mode by setting the MergeTree setting use_compact_variant_discriminators_serialization to true. This setting is enabled by default in the new version. No additional changes to queries or table definitions are required.