Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

ClickHouse 7 min read How-to mediumAdept

Pipelined SQL in ClickHouse 26.8

ClickHouse 26.8 adds pipelined SQL via a `|>` operator that lets queries be written as a sequence of transformations (FROM, WHERE, AGGREGATE, EXTEND, ORDER BY, LIMIT), building on the FROM-first syntax available since 22.12. Pipelines are rewritten into nested conventional SQL, visible via EXPLAIN SYNTAX, but the whole query is optimized before execution rather than materializing each stage. Worked examples on the UK property prices dataset show re-aggregating aggregation results without CTEs, how stage order changes results (e.g. LIMIT before AGGREGATE), and using pipelines in views and INSERT ... SELECT.

Assumes: SQL aggregation and GROUP BYsubqueries and CTEs

Related posts

  • ClickHouse Newsletter May 2022: Explain Statement – Query Optimization

    ClickHouse mediumAdept

    ClickHouse's May 2022 newsletter centers on using EXPLAIN for query optimization. EXPLAIN SYNTAX reveals rewrites such as wildcard expansion and predicate pushdown into subqueries. EXPLAIN PLAN with indexes=1 shows granules read: on a 1-billion-row MergeTree table, sorting by the filtered column lets the primary key prune reads to 1 of 122,071 granules, cutting query time from 0.688s to 0.007s. The newsletter also covers the 22.4 release, which adds experimental transactions, Keeper load balancing, a RocksDB metadata cache that cut startup from 75 minutes to 20 seconds at 700k parts, and WITH FILL INTERPOLATE gap filling, plus upcoming events and revamped docs.

  • ClickHouse Release 23.2

    ClickHouse mediumAdept

    ClickHouse 23.2 ships 18 features, 30 performance optimisations and 43 bug fixes. Its headline change is multi-stage PREWHERE, which filters columns from smallest to largest uncompressed size so that each step narrows the granules scanned by the next. It is enabled with enable_multiple_prewhere_read_steps=1, ideally alongside move_all_conditions_to_prewhere. The release also adds read support for Apache Iceberg v1 via the iceberg table function and engine (latest snapshot only for now), a corrMatrix aggregate for Pearson correlation matrices, Kafka Connect Sink compatibility with Amazon MSK, and a GA Metabase plugin.

  • ClickHouse Release 26.7

    ClickHouse mediumAdept

    ClickHouse 26.7 ships 61 features, 112 performance optimizations and 329 bug fixes, led by a fused ordered-aggregation pipeline that pushes LIMIT into in-order GROUP BY. On TPC-H SF100 it made a Top-N order-summary query 313× faster with 592× less memory by stopping reads once N groups complete. JOIN gains include runtime filters from the build side that skip probe-side granules via primary-key and skip-index analysis (6.2× faster on a selective TPC-H join), compact 8-byte row references in hash tables (median 12% faster, 15% less memory), and a new dpsub join-ordering algorithm that can chain with greedy as a fallback. Vector search also improves through QBit additions such as Int8 support, strided storage, randomized Hadamard rotations and quantization codecs, alongside phrase search, EXPLAIN ANALYZE and unified URL access.

  • ClickHouse Release 26.3

    ClickHouse mediumAdept

    ClickHouse 26.3 ships 27 features, 40 performance optimizations and 202 bug fixes. Headline changes are asynchronous inserts enabled by default, JOIN reordering for ANTI/SEMI/FULL joins, and MATERIALIZED CTEs, which evaluate a WITH subquery once into a temporary table. In a UK property-prices example, materializing the CTE roughly halved query time and cut peak memory from 1.5 GiB to about 88 MiB. The release also adds pretty/compact EXPLAIN output, naturalSortKey, JSONExtract support for the JSON type, and experimental WebAssembly UDFs sandboxed with Wasmtime. TTL DELETE can now use vertical merges, and the post explains how horizontal and vertical merges work and when each is chosen.

  • ClickHouse Release 25.7

    ClickHouse mediumAdept

    ClickHouse 25.7 adds standard SQL UPDATE and DELETE built on lightweight "patch parts". Instead of rewriting columns, small immutable parts are applied during background merges and matched at query time, making declarative updates up to 1,000× faster in ClickHouse's benchmarks. count() GROUP BY aggregations now store the 64-bit count directly in the hash table cell, skipping the memory arena and pointer indirection, which cut query time ~34% and memory ~21% on a 100M-row benchmark. The release also brings four hash-join optimizations: tighter single-key loops, faster OR-condition joins, no repeated hashing, and precisely sized result buffers, worth roughly 1.4–1.8× speedups, plus AI-powered SQL generation in clickhouse-client via a `??` prefix.

The quest for software engineering knowledge.

Look:
Layout: