v.20.11Improvement

Primary Key Specification Enhanced for MergeTree Table Engines

Now it's possible to specify PRIMARY KEY without ORDER BY for MergeTree table engines family. Closes #15591. #16284 (alesapin).
Allows specifying PRIMARY KEY without requiring ORDER BY in MergeTree family table engines.

Why it matters

This feature addresses the limitation where users had to define an ORDER BY clause whenever a PRIMARY KEY was specified in MergeTree tables. By decoupling PRIMARY KEY from ORDER BY, it provides more flexibility in table schema design and improves usability, especially for scenarios where sorting is not needed but a primary key is still desired for data organization or uniqueness.

How to use it

When creating a MergeTree family table, you can now specify PRIMARY KEY independently of ORDER BY. For example:

CREATE TABLE example (
id UInt32,
value String
) ENGINE = MergeTree()
PRIMARY KEY id


Here, no ORDER BY clause is required, simplifying table definition.