v.21.4New Features

Add _partition_id Virtual Column and partitionID() Function for MergeTree Engines

Add _partition_id virtual column for MergeTree* engines. Allow to prune partitions by _partition_id. Add partitionID() function to calculate partition id string. #21401 (Amos Bird).
Added the _partition_id virtual column to MergeTree* table engines, enabling partition pruning using this column. Introduced the partitionID() function to compute the partition ID string.

Why it matters

This feature allows users to efficiently filter and prune data partitions by using the _partition_id virtual column in queries. It improves query performance when working with partitioned tables by enabling direct access to partition identifiers. The partitionID() function provides a way to programmatically obtain the partition ID string for specific rows or data.

How to use it

Users can use the _partition_id virtual column directly in the WHERE clause to filter partitions in SELECT, ALTER, and other queries on MergeTree* tables. The partitionID() function can be called in queries to get the partition ID string for a row. Example usage:

SELECT * FROM table WHERE _partition_id = '2023-06-01';

SELECT partitionID() FROM table LIMIT 1;