You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Before attempting other optimizations, you should optimize their ordering key to ensure ClickHouse produces the fastest possible results.
20
-
Choosing the key right largely depends on the queries you're going to run. Suppose most of our queries filter by `project` and `subproject` columns.
21
-
In this case, its a good idea to add them to the ordering key - as well as the time column since we query on time as well:
19
+
Before attempting other optimizations, you should optimize ordering keys to ensure ClickHouse produces the fastest possible results.
20
+
Choosing the right key largely depends on the queries you're going to run. Suppose most of our queries filter by the `project` and `subproject` columns.
21
+
In this case, it's a good idea to add them to the ordering key — as well as the `time` column since we query on time as well.
22
22
23
23
Let's create another version of the table that has the same column types as `wikistat`, but is ordered by `(project, subproject, time)`.
24
24
@@ -171,7 +171,7 @@ GROUP BY path, month;
171
171
172
172
This destination table will only be populated when new records are inserted into the `wikistat` table, so we need to do some [backfilling](/docs/data-modeling/backfilling).
173
173
174
-
The easiest way to do this is using an [`INSERT INTO SELECT`](/docs/sql-reference/statements/insert-into#inserting-the-results-of-select) statement to insert directly into the materialized view's target table [using](https://github.com/ClickHouse/examples/tree/main/ClickHouse_vs_ElasticSearch/DataAnalytics#variant-1---directly-inserting-into-the-target-table-by-using-the-materialized-views-transformation-query) the view's SELECT query (transformation):
174
+
The easiest way to do this is using an [`INSERT INTO SELECT`](/docs/sql-reference/statements/insert-into#inserting-the-results-of-select) statement to insert directly into the materialized view's target table [using](https://github.com/ClickHouse/examples/tree/main/ClickHouse_vs_ElasticSearch/DataAnalytics#variant-1---directly-inserting-into-the-target-table-by-using-the-materialized-views-transformation-query) the view's `SELECT` query (transformation):
175
175
176
176
```sql
177
177
INSERT INTO wikistat_top
@@ -187,10 +187,10 @@ Depending on the cardinality of the raw data set (we have 1 billion rows!), this
187
187
188
188
* Creating a temporary table with a Null table engine
189
189
* Connecting a copy of the normally used materialized view to that temporary table
190
-
* Using an INSERT INTO SELECT query, copying all data from the raw data set into that temporary table
190
+
* Using an `INSERT INTO SELECT` query, copying all data from the raw data set into that temporary table
191
191
* Dropping the temporary table and the temporary materialized view.
192
192
193
-
With that approach, rows from the raw data set are copied block-wise into the temporary table (which doesn't store any of these rows), and for each block of rows, a partial state is calculated and written to the target table, where these states are incrementally merged in the background.
193
+
With this approach, rows from the raw data set are copied block-wise into the temporary table (which doesn't store any of these rows), and for each block of rows, a partial state is calculated and written to the target table, where these states are incrementally merged in the background.
194
194
195
195
```sql
196
196
CREATETABLEwikistat_backfill
@@ -261,5 +261,5 @@ LIMIT 10;
261
261
10 rows in set. Elapsed: 0.004 sec.
262
262
```
263
263
264
-
Our performance improvement here is dramatic.
264
+
Our performance improvement here is dramatic.
265
265
Before it took just over 2 seconds to compute the answer to this query and now it takes only 4 milliseconds.
0 commit comments