Skip to content

Commit

Permalink
Update backfill-populate-mv-in-a-controlled-manner.md
Browse files Browse the repository at this point in the history
finalizeAggregation
  • Loading branch information
BorisTyshkevich authored Jul 19, 2023
1 parent 1066ac4 commit c37bd6b
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.





Expand Down

0 comments on commit c37bd6b

Please sign in to comment.