Skip to content

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

ClickHouse 9 min read Article mediumAdept

ClickHouse Newsletter February 2023: A ‘Sample’ of What’s Happening in the Community

ClickHouse's SAMPLE BY clause trades exact answers for speed on very large tables, illustrated with a 425-billion-row Wikistat dataset. A full-table monthly average took about 278 seconds. Taking the first million rows was fast but biased, while a table with a hashed sampling key (cityHash64(path)) placed first in the ORDER BY answered from a 1% sample in about 6 seconds with reasonable accuracy. Sums must be scaled up by the sampling factor. The newsletter also lists upcoming webinars and meetups, recaps 23.1 features (experimental inverted indices, parameterized views, query result cache) and links recent blog posts.

Related posts

  • Native random sampling in ClickHouse

    ClickHouse mediumAdept

    ClickHouse's SAMPLE clause runs aggregations over a deterministic subset of rows selected by a hash-based sample key, which must be part of the primary key so granules above the hash threshold can be skipped. On a 30M-row UK house price dataset, sipHash64(postcode1, postcode2) spreads rows evenly across buckets, while a low-cardinality column like county skews badly because Greater London holds 13% of sales. Sampling works by fraction or by minimum row count, and the _sample_factor virtual column scales sums and counts back to full-dataset estimates; avg needs no adjustment. A 10% sample cut a grouped analytical query from 687 ms to 141 ms by reading 384 of 3,719 granules, with sales estimates about 7–8% off, which is acceptable for exploratory work.

  • ClickHouse and The One Billion Row Challenge

    ClickHouse mediumAdept

    ClickHouse Local solves the One Billion Row Challenge (min/mean/max temperature per station from a 13GB text file) in about 20 seconds on an 8-core Hetzner VM, versus nearly 3 minutes for the Java baseline. Reading lines with LineAsString and splitting on ';' instead of using the CSV parser cut the time from 27.6s to 19.9s. Loading into a Memory table first, or precomputing aggregates with a Materialized View into an AggregatingMergeTree via a Null engine, makes later queries near-instant but costs 21–26s of load time, so neither beats the single-scan query end to end. ClickHouse SQL using randCanonical and a Box-Muller transform also generates the dataset 6.8x faster than the Java generator.

  • ClickHouse Over the Years with Benchmarks

    ClickHouse mediumAdept

    Every ClickHouse release from 1.1.54378 (April 2018) onward was installed on one AWS m5.8xlarge and run through the Star Schema Benchmark, the Brown University benchmark and ClickHouse's own hits benchmark to see how performance changed over time. The setup pulls 328 versions from the old Yandex and new packages.clickhouse.com apt repositories, then exports the hits dataset to CSV with clickhouse-local. Getting the data into old versions meant workarounds for missing features: dropping index_granularity_bytes, replacing LowCardinality with String and IPv4 with String, and splitting DateTime64 into DateTime plus a milliseconds column. Star Schema Benchmark results come with a caveat, since its random value distribution does not resemble real datasets.

  • How to take random samples from big PostgreSQL tables

    Render mediumAdept

    Random sampling from billion-row PostgreSQL tables with ORDER BY random() scans every row and runs a top-N heapsort, taking over a minute. A WHERE random() < p filter (Bernoulli sampling) drops the sort and halves runtime, but it still reads every heap page. TABLESAMPLE SYSTEM picks whole 8kB heap blocks and returns about 10k rows in roughly 50ms, at the cost of a nondeterministic result count and correlated rows within each block. A 10k-trial simulation showed result sizes and runtimes are normally distributed with modest row overlap. For joins, sample one side (the "many" side) before joining, and never sample both tables independently.

  • ClickHouse Release 23.8

    ClickHouse mediumAdept

    ClickHouse 23.8 makes file reads much faster by using Parquet row-group min/max statistics to skip data, answering count() from file metadata, and pruning files via the _file virtual column without reading them. On a 126GiB PyPI Parquet dataset in GCS, a count dropped from 26.5s to 11.4s, a time-range filter from 84s to 35s, and a 10% filename sample from 4.6s to 0.6s. The release also adds the S3Queue table engine for streaming ingestion from S3. It tracks processed files in ClickHouse Keeper using an unordered mode (with TTL and file-count limits) or an ordered mode keyed on filenames. Direct querying of zip, tar and 7z archives via the file function is also new.

The quest for software engineering knowledge.

Look:
Layout: