In this blog, we will learn about how to reduce I/O and improve query performance using PREWHERE in queries with FINAL keyword on ReplacingMergeTree table in Clickhouse. Prerequisite Clickhouse ReplacingMergeTree FINAL prewhere Above is the best place to understand prewhere optimiation and how it can improve the query performance. It is recommended to go through it before proceeding. PREWHERE with FINAL in ReplacingMergeTree ReplacingMergeTree table engine is widely used to design the update/delete use case in Clickhouse. And it is very common to use FINAL keyword to deduplicate and query the latest copy of data. PREWHERE is one of the powerful technique to reduces I/O and improve query performance by avoiding unnecessary data reads, and filtering out irrelevant data before reading non-filter columns from disk. By default PREWHERE optimization is enabled on all query except the one with FINAL keyword. Why prewhere is disabled on query with FINAL ?…