From c37bd6b74939808c59b95f999ef67a21a3925897 Mon Sep 17 00:00:00 2001 From: BorisTyshkevich <125603338+BorisTyshkevich@users.noreply.github.com> Date: Wed, 19 Jul 2023 13:46:10 +0200 Subject: [PATCH] Update backfill-populate-mv-in-a-controlled-manner.md finalizeAggregation --- .../backfill-populate-mv-in-a-controlled-manner.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/content/en/altinity-kb-schema-design/materialized-views/backfill-populate-mv-in-a-controlled-manner.md b/content/en/altinity-kb-schema-design/materialized-views/backfill-populate-mv-in-a-controlled-manner.md index 7fa7d48d89..264a0aef2b 100644 --- a/content/en/altinity-kb-schema-design/materialized-views/backfill-populate-mv-in-a-controlled-manner.md +++ b/content/en/altinity-kb-schema-design/materialized-views/backfill-populate-mv-in-a-controlled-manner.md @@ -53,12 +53,22 @@ SELECT id, -- ORDER BY column initializeAggregation(argMax,v3,ts) -- we need to convert from values to States for columns with AggregatingFunction type FROM huge_table WHERE toYYYYMM(ts) = 202105; - -ATTACH ... ``` Actually, the first GROUP BY run will happen just before 1M rows will be stored on disk as a data part. You may disable that behavior by switching off [optimize_on_insert](https://clickhouse.com/docs/en/operations/settings/settings#optimize-on-insert) setting if you have heavy calculations during aggregation. +You may attach such a table (with AggregatingFunction columns) to the main table as in the example above, but if you don't like to have States in the aggregated table, data should be finalized and converted back to normal values. In that case, you have to move data by INSERT ... SELECT again: + +```sql +INSERT INTO MV +SELECT id,ts,v1,v2, -- nothing special for SimpleAggregatingFunction columns + finalizeAggregation(v3) +from mv_import FINAL +``` + +The last run of GROUP BY will happen during FINAL execution and AggregatingFunction types converted back to normal values. + +