chDB - A Rocket Engine on a Bicycle
chDB embeds the ClickHouse engine as an in-process Python module instead of shelling out to the 500MB clickhouse-local binary, using WriteBufferFromVector, Python memoryview and Pybind11 for zero-copy result retrieval. Getting jemalloc to work inside the shared library meant redirecting malloc with the linker flag -Wl,-wrap,malloc. That exposed crashes when glibc functions like getcwd returned glibc-malloc'd memory that was then freed by je_free, so the author patched jemalloc (PR #2424) to make arenas.lookup safe for checking ownership. The result cut memory usage by 50%, and chDB ranks as the fastest stateless/serverless engine on ClickBench. Later releases added SQL over Pandas DataFrames, query stats and Python UDFs.
Related posts
- chDB Kernel Upgrade Journey: Upgrading ClickHouse to v25.8.2.29
ClickHouse hardMaster
Upgrading chDB's embedded ClickHouse kernel from v25.5 to v25.8.2.29 surfaced allocator conflicts rooted in chDB's dual-library design: a stable-ABI `_chdb.abi3.so` holding the ~120MB engine plus small per-Python-version pybind11 binding libraries. Mixing jemalloc with glibc-allocated memory from Python and third-party libraries causes crashes, so chDB wraps `free` and `operator delete` with the linker's `--wrap` mechanism and uses jemalloc's `arenas.lookup` to send each pointer to `je_free` or glibc's `__real_free`. The new ClickHouse version added its own `__wrap_free` for MemoryTracker accounting, so the two were merged into one implementation. The upgrade also exposed a ClickBench Q29 regression in a regex- and string-heavy query that stresses allocation and deallocation.
- The Journey to Zero-Copy: How chDB Became the Fastest SQL Engine on Pandas DataFrame
ClickHouse mediumAdept
chDB, ClickHouse embedded as a Python library, removed the four serialization steps that made every v1 query take over 100ms by reading Pandas DataFrames in place. That change alone made v2 87x faster than v1. The engineering work included automatic variable discovery via Python(df), batching CPython calls before parallel execution to avoid GIL contention, and reimplementing Python string-to-UTF-8 encoding in C++, which cut one ClickBench query from 8.6s to 0.56s. v4.0 adds zero-copy output by mapping ClickHouse columns directly to NumPy dtypes. In the post's own benchmarks, exporting 1M rows to a DataFrame took about 24% less time than DuckDB, and chDB beat Pandas at most operations on 1M and 10M rows.
- Welcome, chDB
ClickHouse mediumAdept
chDB is a community-built embedded SQL OLAP engine that packages ClickHouse as an in-process Python module, similar in spirit to DuckDB, for local analytics, ETL and exploration without running a server. Instead of shelling out to clickhouse-local via pipes, which adds 10–50 ms of process startup per query and copies results, chDB hooks into ClickHouse's read/write buffers and exchanges data through MemoryView. Examples show querying Parquet and gzipped CSV on S3 with schema inference, returning results as CSV, Pandas DataFrames or Arrow tables, and running SQL directly over DataFrames. Bindings for Rust, Node.js and Go, persistent sessions backed by MergeTree, UDFs and ARM64 support are in progress or recently added.
- How we made querying Pandas DataFrames with chDB 87x faster
ClickHouse mediumAdept
chDB, the in-process embedded ClickHouse, sped up SQL queries over Pandas DataFrames 87x by replacing its original Parquet serialize/deserialize round-trip through file descriptors with a native Python table engine that reads Python objects directly. The new engine is built from a TableFunctionPython, StoragePython and PythonSource that feed ClickHouse's concurrent pipeline. To keep multi-threaded execution from serializing on the GIL and to avoid reference-counting pitfalls, the team concentrated CPython API calls before the pipeline runs, batched copies with SIMD memcpy, and reimplemented Python str encoding conversion in C++. Together these changes cut ClickBench Q23 from over 30s to 0.56s and put chDB ahead of DuckDB in the SQL-on-DataFrame benchmark. chDB v2.0.2 also adds chdb.PyReader for user-defined Python table functions, demonstrated by querying the Google Calendar API with SQL.
- How to use Rust in ClickHouse: avoiding a full rewrite
ClickHouse mediumAdept
ClickHouse, a 1.5M-line C++ analytic database, is adopting Rust incrementally rather than rewriting. It started with Corrosion to wire Rust into CMake and a BLAKE3 hash function, then took on a client history-navigation feature, the PRQL query language, and Databricks' delta-kernel-rs for Delta Lake support. The integration problems were mostly practical: hermetic reproducible builds with vendored crates, buggy FFI wrappers caught quickly by existing CI and fuzzing, library panics that crash the server, compiling Rust with sanitizers (now easier with an MSan toolchain), duplicated cross-compilation setup, and transitive dependencies linking system OpenSSL.