Skip to content

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

ClickHouse 8 min read Deep dive mediumAdept

How we made querying Pandas DataFrames with chDB 87x faster

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.

Assumes: Python GILPandas DataFramesCPython C API basicscolumnar query engines

Related posts

  • 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.

  • Querying Pandas DataFrames with ClickHouse

    ClickHouse mediumAdept

    chDB, an embedded Python library built on the ClickHouse engine, can run SQL directly against Pandas DataFrames through the chdb.dataframe module. DataFrames are passed as named parameters and referenced in SQL as __name__. The walkthrough uses Kaggle Canadian house-price data to show aggregation with GROUP BY ALL, joining two DataFrames, re-querying the resulting chDB Table via __table__, and converting results back with to_pandas(). It needs pandas and pyarrow installed, and string columns come back as bytes, so filters must compare against values like b"Ontario".

  • Announcing chDB 4: write Pandas, run ClickHouse, now on Hex

    ClickHouse mediumAdept

    chDB 4 adds DataStore, a Pandas-compatible API that records operations lazily as a chain of LazyOps, then compiles them into ClickHouse SQL with filter pushdown, column pruning and limit propagation, executing in-process on the ClickHouse engine. A query planner splits pipelines into segments when an operation has no ClickHouse equivalent, handing data to Pandas and back via memoryview and the Python() table function with near-zero-copy exchange for fixed-width columns. Pandas segments act as optimization barriers, so Pandas-only operations are best placed late in the pipeline. Row-ID tracking preserves source ordering, with an optional performance mode that skips it. Automatic caching serves notebook workflows, and NaN/NULL, string sort order and integer overflow semantics are documented differences from Pandas. It ships pre-installed in Hex notebooks.

  • 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.

  • Longbridge Technology simplifies their architecture and achieves 10x performance boost with ClickHouse

    ClickHouse mediumAdept

    Longbridge, a Singapore online brokerage, replaced a fragmented market-data stack of PostgreSQL (historical), Redis (real-time) and DynamoDB (high-write) with ClickHouse after evaluating it against TimescaleDB and TDengine for write throughput, Decimal support, time functions and aggregations. Historical data was migrated via ClickHouse external tables over OSS and Alibaba Cloud DTS, which merged 128 PostgreSQL sub-tables into one table and converted varchar fields to Decimal; Redis was kept for real-time data with ticker-level writes moved to ClickHouse. Reported results include about 5x compression (500GB down to 100GB), 10x faster single-table writes than PostgreSQL, and built-in aggregation and window functions replacing scheduled statistics jobs.

The quest for software engineering knowledge.

Look:
Layout: