Change a sorting key
Set a table sorting key with ALTER TABLE MODIFY ORDER BY.
Change a sorting key
Use a table sorting key when you know which paths your queries filter or sort.
Before you begin
- Use the
analyticsdatabase. Create it with the database API if it does not exist. - Use an
eventstable withtenantandevent_timepaths.
1. Set the sorting key
Choose paths that match the table's query patterns.
ALTER TABLE events MODIFY ORDER BY (tenant, event_time)2. Inspect the table
Read the sorting-key expression from system.tables.
SELECT sorting_key FROM system.tables WHERE database = currentDatabase() AND name = 'events'Check the result
The sorting_key value contains tenant and event_time.