v.24.12Experimental Feature
New MergeTree Setting for Descending Sort Order Support in ClickHouse
A new MergeTree settingallow_experimental_reverse_keythat enables support for descending sort order in MergeTree sorting keys. This is useful for time series analysis, especially TopN queries. Example usage:ENGINE = MergeTree ORDER BY (time DESC, key)- descending order for thetimefield. #71095 (Amos Bird).
Why it matters
This feature addresses the need to efficiently support descending order in sorting keys, which is particularly valuable for time series analysis and improving the performance of TopN queries by allowing columns like timestamps to be sorted in descending order.How to use it
To use this feature, enable the settingallow_experimental_reverse_key in your MergeTree table configuration and define the sorting key with descending order as part of the ORDER BY clause. For example:ENGINE = MergeTree
ORDER BY (time DESC, key)This will sort the
time field in descending order.