@@ -8,7 +8,7 @@ You can use `AggregatingMergeTree` tables for incremental data aggregation, incl
The engine processes all columns with [AggregateFunction](../../data_types/nested_data_structures/aggregatefunction.md#data_type-aggregatefunction) type.
It is appropriate to use `AggregatingMergeTree` if it reduces the number of rows by orders.
It is appropriate to use `AggregatingMergeTree` if it reduces the number of rows by orders.
## Creating a Table
...
...
@@ -29,11 +29,12 @@ For a description of request parameters, see [request description](../../query_l
**Query clauses**
When creating a `ReplacingMergeTree` table the same [clauses](mergetree.md#table_engines-mergetree-configuring) are required, as when creating a `MergeTree` table.
When creating a `ReplacingMergeTree` table the same [clauses](mergetree.md#table_engines-mergetree-configuring)are required, as when creating a `MergeTree` table.
### Deprecated Method for Creating a Table
<detailsmarkdown="1"><summary>Deprecated Method for Creating a Table</summary>
!!! attention Do not use this method in new projects and, if possible, switch the old projects to the method described above.
!!! attention
Do not use this method in new projects and, if possible, switch the old projects to the method described above.
All of the parameters have the same meaning as in `MergeTree`.
</details>
## SELECT and INSERT
To insert data, use `INSERT SELECT` query with aggregate `- State`- functions.
To insert data, use [INSERT SELECT](../../query_language/insert_into.md#queries-insert-select) query with aggregate `-State`- functions.
When selecting data from `AggregatingMergeTree` table, use `GROUP BY` clause and the same aggregate functions as when inserting data, but using `- Merge` suffix.
When selecting data from `AggregatingMergeTree`table, use `GROUP BY` clause and the same aggregate functions as when inserting data, but using `-Merge` suffix.
In the results of `SELECT` query the values of `AggregateFunction` type have implementation-specific binary representation for all of the ClickHouse output formats. If dump data into, for example, `TabSeparated` format with `SELECT` query then this dump can be loaded back using `INSERT` query.
In the results of `SELECT` query the values of `AggregateFunction` type have implementation-specific binary representation for all of the ClickHouse output formats. If dump data into, for example, `TabSeparated` format with `SELECT` query then this dump can be loaded back using `INSERT` query.
The engine inherits from [MergeTree](mergetree.md#table_engines-mergetree) and adds to data parts merge algorithm the logic of rows collapsing.
The engine inherits from [MergeTree](mergetree.md#table_engines-mergetree) and adds the logic of rows collapsing to data parts merge algorithm.
`CollapsingMergeTree` deletes (collapses) pairs of rows by specific rules. The engine may significantly reduce the volume of storage and increase efficiency of `SELECT` query as a consequence.
...
...
@@ -27,7 +27,7 @@ For a description of request parameters, see [request description](../../query_l
**CollapsingMergeTree Parameters**
-`sign` — Name of the column with the type of row: `1`— "state" row, `-1` — "cancel" row.
-`sign` — Name of the column with the type of row: `1`is a "state" row, `-1` is a "cancel" row.
Column data type — `Int8`.
...
...
@@ -35,7 +35,7 @@ For a description of request parameters, see [request description](../../query_l
When creating a `CollapsingMergeTree` table, the same [clauses](mergetree.md#table_engines-mergetree-configuring) are required, as when creating a `MergeTree` table.
### Deprecated Method for Creating a Table
<detailsmarkdown="1"><summary>Deprecated Method for Creating a Table</summary>
!!! attention
Do not use this method in new projects and, if possible, switch the old projects to the method described above.
...
...
@@ -54,6 +54,7 @@ All of the parameters excepting `sign` have the same meaning as in `MergeTree`.
-`sign` — Name of the column with the type of row: `1` — "state" row, `-1` — "cancel" row.
Column Data Type — `Int8`.
</details>
<aname="collapsingmergetree-algorithm"></a>
...
...
@@ -121,7 +122,7 @@ For each resulting data part ClickHouse saves:
Thus, collapsing should not change the results of calculating statistics.
Changes gradually collapsed so that in the end only the last state of almost every object left.
The `Sign` is required because the merging algorithm doesn't guarantee that all of the rows with the same primary key will be in the same resulting data part and even on the same physical server. ClickHouse process `SELECT` queries with multiple threads, and it can not predict the order of rows in the result. The aggregation is required if there is a need to get completely "collapsed" data from `CollapsingMergeTree` table.
The `Sign` is required because the merging algorithm doesn't guarantee that all of the rows with the same primary key will be in the same resulting data part and even on the same physical server. ClickHouse process `SELECT` queries with multiple threads, and it can not predict the order of rows in the result. The aggregation is required if there is a need to get completely "collapsed" data from `CollapsingMergeTree` table.
To finalize collapsing write a query with `GROUP BY` clause and aggregate functions that account for the sign. For example, to calculate quantity, use `sum(Sign)` instead of `count()`. To calculate the sum of something, use `sum(Sign * x)` instead of `sum(x)`, and so on, and also add `HAVING sum(Sign) > 0`.
We use two `INSERT` queries to create two different data parts. If we insert the data with one query ClickHouse creates one data part and will not perform any merge ever.
@@ -46,7 +46,7 @@ The names of these columns should be set in the rollup configuration.
When creating a `GraphiteMergeTree` table, the same [clauses](mergetree.md#table_engines-mergetree-configuring) are required, as when creating a `MergeTree` table.
### Deprecated Method for Creating a Table
<detailsmarkdown="1"><summary>Deprecated Method for Creating a Table</summary>
!!! attention
Do not use this method in new projects and, if possible, switch the old projects to the method described above.
@@ -35,7 +35,7 @@ For a description of request parameters, see [request description](../../query_l
When creating a `ReplacingMergeTree` table the same [clauses](mergetree.md#table_engines-mergetree-configuring) are required, as when creating a `MergeTree` table.
### Deprecated Method for Creating a Table
<detailsmarkdown="1"><summary>Deprecated Method for Creating a Table</summary>
!!! attention
Do not use this method in new projects and, if possible, switch the old projects to the method described above.
...
...
@@ -53,5 +53,6 @@ All of the parameters excepting `ver` have the same meaning as in `MergeTree`.
-`ver` - column with the version. Optional parameter. For a description, see the text above.
@@ -34,9 +34,10 @@ The columns must be of a numeric type and must not be in the primary key.
When creating a `SummingMergeTree` table the same [clauses](mergetree.md#table_engines-mergetree-configuring) are required, as when creating a `MergeTree` table.
### Deprecated Method for Creating a Table
<detailsmarkdown="1"><summary>Deprecated Method for Creating a Table</summary>
!!! attention Do not use this method in new projects and, if possible, switch the old projects to the method described above.
!!! attention
Do not use this method in new projects and, if possible, switch the old projects to the method described above.
```
CREATE TABLE [IF NOT EXISTS] [db.]table_name [ON CLUSTER cluster]
The query can specify a list of columns to insert `[(c1, c2, c3)]`. In this case, the rest of the columns are filled with:
- The values calculated from the `DEFAULT`expressions specified in the table definition.
- The values calculated from the `DEFAULT` expressions specified in the table definition.
- Zeros and empty strings, if `DEFAULT` expressions are not defined.
If [strict_insert_defaults=1](../operations/settings/settings.md#settings-strict_insert_defaults), columns that do not have `DEFAULT` defined must be listed in the query.
...
...
@@ -41,6 +41,8 @@ INSERT INTO t FORMAT TabSeparated
You can insert data separately from the query by using the command-line client or the HTTP interface. For more information, see the section "[Interfaces](../interfaces/index.md#interfaces)".
При создании таблицы `AggregatingMergeTree` используются те же [секции](mergetree.md#table_engines-mergetree-configuring), что и при создании таблицы `MergeTree`.
### Устаревший способ создания таблицы
<detailsmarkdown="1"><summary>Устаревший способ создания таблицы</summary>
!!! attention
Не используйте этот способ в новых проектах и по возможности переведите старые проекты на способ описанный выше.
При создании таблицы `ReplacingMergeTree` используются те же [секции](mergetree.md#table_engines-mergetree-configuring), что и при создании таблицы `MergeTree`.
### Устаревший способ создания таблицы
<detailsmarkdown="1"><summary>Устаревший способ создания таблицы</summary>
!!! attention
Не используйте этот способ в новых проектах и по возможности переведите старые проекты на способ описанный выше.
При создании таблицы `SummingMergeTree` использутся те же [секции](mergetree.md#table_engines-mergetree-configuring) запроса, что и при создании таблицы `MergeTree`.
### Устаревший способ создания таблицы
<detailsmarkdown="1"><summary>Устаревший способ создания таблицы</summary>
!!! attention
Не используйте этот способ в новых проектах и по возможности переведите старые проекты на способ описанный выше.