## TL;DR
Projections are extra sort orders stored with the table itself: transparent to queries and cheap to maintain. Materialized views are separate tables filled by insert triggers: more flexible (they can aggregate, filter, or join) but they cost insert throughput and storage. Use projections when the same table just needs another ORDER BY pattern; use materialized views when you need a different grain, an aggregation, or data from another table.

## The query
```text
clickhouse projection vs materialized view
```

## Use this when
- you are choosing between a projection and a materialized view in ClickHouse
- a materialized view is slowing down inserts and you want a cheaper option
- queries need a different sort order than the table's primary key

## Not for
- plain MergeTree tuning, which is a separate topic
- precomputation in other databases or warehouses

## Steps
1. List what the query needs: same rows in a new order means projection; fewer rows, aggregates, or joins mean materialized view.
   Expected output: You have a clear answer for which feature matches the requirement.

2. For projections, define the projection with the ORDER BY your slow queries use, then let the optimizer pick it up automatically.
   Expected output: EXPLAIN shows the query using the projection without any query rewrite.

3. For materialized views, decide between a TO-table (explicit target, flexible) and the implicit inner table, and keep the MV query simple.
   Expected output: The MV populates on insert and queries against it return fresh results.

4. Measure insert impact before and after adding either. MVs can noticeably slow high-rate ingestion.
   Expected output: You have insert throughput numbers with and without the MV.

5. Avoid stacking both on the same access pattern. One precomputation layer is enough; two is maintenance debt.
   Expected output: Each slow query pattern has exactly one precompute strategy.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_rWBvs_uOXIQv2-_9VZRC-A
