From 86e3c5a2bc9bc99b76fef7ac3bee03a0a2e0b2d7 Mon Sep 17 00:00:00 2001 From: Vlad Ilyushchenko Date: Thu, 2 Oct 2025 13:41:22 +0100 Subject: [PATCH] fix clickhouse create table to use current syntax of the merge tree --- pkg/targets/clickhouse/creator.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/pkg/targets/clickhouse/creator.go b/pkg/targets/clickhouse/creator.go index 9e991d36b..6ccfaa5bb 100644 --- a/pkg/targets/clickhouse/creator.go +++ b/pkg/targets/clickhouse/creator.go @@ -137,13 +137,16 @@ func createMetricsTable(conf *ClickhouseConfig, db *sqlx.DB, tableName string, f sql := fmt.Sprintf(` CREATE TABLE %s ( - created_date Date DEFAULT today(), - created_at DateTime DEFAULT now(), - time String, - tags_id UInt32, - %s, - additional_tags String DEFAULT '' - ) ENGINE = MergeTree(created_date, (tags_id, created_at), 8192) + created_date Date DEFAULT today(), + created_at DateTime DEFAULT now(), + time String, + tags_id UInt32, + %s, + additional_tags String DEFAULT '' + ) ENGINE = MergeTree() + ORDER BY (tags_id, created_at) + PARTITION BY created_date + SETTINGS index_granularity = 8192 `, tableName, strings.Join(columnsWithType, ",")) @@ -180,7 +183,10 @@ func generateTagsTableQuery(tagNames, tagTypes []string) string { "created_at DateTime DEFAULT now(),\n"+ "id UInt32,\n"+ "%s"+ - ") ENGINE = MergeTree(created_date, (%s), 8192)", + ") ENGINE = MergeTree()\n"+ + "PARTITION BY created_date\n"+ + "ORDER BY (%s)\n"+ + "SETTINGS index_granularity = 8192", cols, index) }