Fuzzing ClickHouse
ClickHouse's AST-based query fuzzer takes SQL queries from the regression test suite, parses them, and randomly mutates the AST. It swaps in bad numeric values such as NaN and integer limits, perturbs strings and arrays, and splices function arguments, expressions and tables from other test queries. The core is about 700 lines of C++ and has found more than 200 bugs, including segfaults and logic errors. Much of that comes from pairing it with assertions, a distinct LOGICAL_ERROR exception for internal bugs, and clang sanitizers. In CI it weights permutations toward new tests in pull requests and needs settings constraints, since it once disabled its own execution-time limit.
Related posts
- BuzzHouse: Bridging the database fuzzing gap for testing ClickHouse
ClickHouse mediumAdept
BuzzHouse is a new ClickHouse fuzzer that generates complex but mostly semantically valid SQL backed by a tracked catalog of tables, filling a gap left by SQLsmith, SQLancer, the AST fuzzer and WINGFUZZ. It has found about 100 new issues. Correctness is checked by dumping and re-reading tables, comparing equivalent queries via SQLancer-style oracles, re-running queries under different settings, and comparing results against another relational database. The design tradeoffs covered include valid versus random identifiers, why coverage-guided fuzzing was skipped, and how statement probabilities (e.g. DROP frequency) shape what the fuzzer can reach.
- Fuzzing collaboration with WINGFUZZ - Part 1
ClickHouse easyNovice
WINGFUZZ, a DBMS fuzzing engine, found eight new bugs in ClickHouse, some introduced only four months earlier, using two techniques. Grammar-free mutation builds a metadata graph from built-in SQL tests, reshuffles statements, and fixes semantic errors by metadata-guided substitution (Griffin). Type-affinity sequence generation uses coverage feedback to learn which SQL statement-type pairs matter and builds new sequences around them. ClickHouse is now integrating WINGFUZZ into its daily testing.
- Decorating a Christmas Tree With the Help Of Flaky Tests
ClickHouse mediumAdept
ClickHouse treats flaky tests as bugs to investigate rather than noise to mute or retry, and deliberately makes tests flakier to surface hidden issues. Its practices include randomizing the environment on every run, running new tests 100 times before merge, using new tests as a fuzzing corpus, injecting random sleeps and core switches around mutex operations, and running in parallel on slow machines. Results of all test runs, nearly 1.8 billion records and 5–9 million runs per day, are stored in ClickHouse itself. A 561-day by 3772-test pass/fail pixel map of the stateless functional tests, rendered by JavaScript querying ClickHouse directly, forms a 'Christmas tree' where horizontal red lines mark flaky tests and vertical red lines mark days master was broken.
- Testing the Performance of ClickHouse
ClickHouse mediumAdept
ClickHouse catches performance regressions in CI by running the reference and patched servers side by side on the same machine and alternating about 3000 end-to-end test queries between them. This cancels out environmental systematic errors. A non-parametric bootstrap on the difference of median run times yields a noise threshold T, and a change is flagged only when it exceeds both T and 5%. Queries with T of 10% or more are marked unstable. Regressions are investigated with the built-in sampling profiler (system.trace_log), differential flamegraphs, ProfileEvents and hardware counters, while historical results stored in ClickHouse help locate when a change was introduced. Keeping false positives low matters more than producing a green check, and many test queries turned out to measure nothing meaningful.
- Fuzzer Blind Spots (Meet Jepsen!)
TigerBeetle hardMasterJepsen found a missing-results bug in TigerBeetle's query engine despite four fuzzers covering it, because the VOPR and LSM query fuzzer pre-registered disjoint queries whose matching objects were always consecutive in every secondary index, so zig-zag merge join probing was never exercised. The bug was in ScanTreeLevel: after a probe shrank the scan's key range, the key_exclusive_next check could misfire from the wrong end and mark the level finished, returning truncated results. Rewriting the fuzzer to generate random objects and random queries against a full model reproduced the bug trivially, and the fix splits the termination condition. The broader lesson is that biased fuzzer workloads can silently project away reachable states, so targeted fuzzers should be complemented with broader, less-structured sampling and precise output checking.