Menu

1 / 2

FINAL in ClickHouse Isn’t as Expensive as It Used to Be

DEV Community·Mohamed Hussain S·6 months ago
#TV4hN8eQ
#final#clickhouse#where#query#article
Reading 0:00
15s threshold

For a long time, the advice around FINAL in ClickHouse was pretty straightforward:

Avoid it whenever possible.

And honestly, that advice existed for good reasons.

Older versions of ClickHouse could make FINAL extremely expensive depending on:

table size

partitioning

number of parts

merge state

query patterns

So people started treating FINAL almost like a red flag.

But modern ClickHouse has changed a lot.

And I think the conversation around FINAL deserves a bit more nuance now.

Why FINAL Existed in the First Place

To understand why FINAL was historically considered expensive, you first need to understand what it actually does.

In engines like:

ReplacingMergeTree

CollapsingMergeTree

VersionedCollapsingMergeTree

ClickHouse does not immediately rewrite rows in place.

Instead:

inserts create new parts

background merges reconcile rows later

deduplication happens asynchronously

That means queries can temporarily see:

duplicate versions

old versions

intermediate states

Example:

SELECT *…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.