From 72197fec3a9f05c93011ea47abb2bab5f77687a5 Mon Sep 17 00:00:00 2001 From: BorisTyshkevich <125603338+BorisTyshkevich@users.noreply.github.com> Date: Fri, 1 Nov 2024 11:16:47 +0100 Subject: [PATCH] Update projections-examples.md FINAL queries --- .../projections-examples.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/content/en/altinity-kb-queries-and-syntax/projections-examples.md b/content/en/altinity-kb-queries-and-syntax/projections-examples.md index 93deb236cd..e8d6d3024a 100644 --- a/content/en/altinity-kb-queries-and-syntax/projections-examples.md +++ b/content/en/altinity-kb-queries-and-syntax/projections-examples.md @@ -4,6 +4,13 @@ linkTitle: "Projections" description: > Projections --- + +Projections in ClickHouse act as inner tables within a main table, functioning as a mechanism to optimize queries by using these inner tables when only specific columns are needed. Essentially, a projection is similar to a Materialized View with an AggregatingMergeTree engine, designed to be automatically populated with relevant data. + +However, too many projections can lead to excess storage, much like overusing Materialized Views. Projections share the same lifecycle as the main table, meaning they are automatically backfilled and don’t require query rewrites, which is particularly advantageous when integrating with BI tools. + +Projection parts are stored within the main table parts, and their merges occur simultaneously as the main table merges, ensuring data consistency without additional maintenance. + ## Links * Amos Bird - kuaishou.com - Projections in ClickHouse. [slides](https://github.com/ClickHouse/clickhouse-presentations/blob/master/percona2021/projections.pdf). [video](https://youtu.be/jJ5VuLr2k5k?list=PLWhC0zeznqkkNYzcvHEfZ8hly3Cu9ojKk) @@ -12,6 +19,7 @@ description: > * ClickHouse presentation on Projections https://www.youtube.com/watch?v=QDAJTKZT8y4 * Blog video https://clickhouse.com/videos/how-to-a-clickhouse-query-using-projections + ## Why is a projection not used? - FINAL queries do not work with projections. @@ -68,8 +76,11 @@ Since version 24.8, it is controlled by a new table-level setting: [deduplicate_merge_projection_mode](https://clickhouse.com/docs/en/operations/settings/merge-tree-settings#deduplicate_merge_projection_mode) = 'throw'/'drop'/'rebuild' +However, projection usage is still disabled for FINAL queries. + +## Lightweight DELETEs with projections -Since 24.7, we also have a setting to control the behavior w.r.t. lightweight deletes: lightweight_mutation_projection_mode. +By default, DELETE does not work for tables with projections. This is because rows in a projection may be affected by a DELETE operation. But there is a MergeTree setting lightweight_mutation_projection_mode to change the behavior (Since 24.7) ## System tables