ClickHouseのpg_clickhouse v0.10がTPC-H Q17の実行時間を884倍短縮

この拡張機能は、SQLインターフェースとしてPostgreSQLを維持しつつ、実行対象となる分析サブクエリをClickHouseに移して実行します。

By · Published

Primary source: ClickHouse

Why it matters

ClickHouse is using pg_clickhouse to make its analytical engine adoptable without a wholesale PostgreSQL migration. The 884x Q17 result shows the payoff when pushdown works, while the remaining query gaps define the engineering risk.

Optimized analytical query execution via database extension (Flat modernist vector illustration in the spirit of mid-century corporate annual reports, with bold simple shapes and textured overprint)

ClickHouse engineer Josh Ventura released pg_clickhouse v0.10.0 on August 11, pushing more PostgreSQL subqueries into ClickHouse and cutting one vendor-tested TPC-H query from 32.7 seconds to 37 milliseconds.

このリリースは、ClickHouseの共同創業者でCTOの Alexey Milovidov が2009年に構築し始めたアーキテクチャを前進させるものだ:基盤となるデータが増加しても分析クエリを対話的に保つ。基盤となる ClickHouse システムは2012年に Yandex.Metrica で本番導入され、2016年にオープンソースプロジェクトとなった。共同創業者の Aaron Katz と Yury Izrailevsky はその後、データベースを独立した事業に成長させる手助けをし、pg_clickhouse は開発者に既存のインターフェイスを放棄させるのではなく、同じ性能上の賭けを PostgreSQL に広げるものだ。

In an engineering post announcing v0.10.0, Ventura described the release's immediate target as complete query pushdown across the 22-query TPC-H benchmark. The project moved from 12 fully pushed-down queries to 16, leaving six unresolved.

Ventura は v0.10.0 を発表するエンジニアリング投稿の中で、このリリースの直接的な目標を 22 クエリからなる TPC-H ベンチマーク全体でのクエリ・プッシュダウンの完遂と説明した。プロジェクトは完全にプッシュダウンされるクエリを12件から16件に増やし、6件が未解決のままだ。

The result is narrower than the "1000x faster" shorthand suggests. ClickHouse measured an approximately 884x improvement for TPC-H Q17, a specific correlated-subquery workload at scale factor 1. The figures are vendor benchmarks, and they do not establish that PostgreSQL workloads generally become hundreds of times faster after installing the extension.

この結果は「1000倍速くなる」という簡略表現が示すほど一律ではない。ClickHouse は、スケールファクター1 の特定の相関サブクエリワークロードである TPC-H Q17 に対して約884倍の改善を計測した。これらの数値はベンダーによるベンチマークであり、拡張機能をインストールした後に PostgreSQL のワークロードが一般に数百倍速くなることを証明するものではない。

They do show why execution placement matters.

それらは、実行場所(どこで処理を行うか)が重要である理由を示している。

Moving the work instead of the rows

行を移動するのではなく、処理を移動する

pg_clickhouse is an open-source PostgreSQL extension and foreign-data wrapper. It lets a PostgreSQL session query tables held in ClickHouse while attempting to send filters, joins, aggregates and other supported operations to ClickHouse for remote execution.

pg_clickhouse はオープンソースの PostgreSQL 拡張および foreign-data wrapper だ。PostgreSQL セッションが ClickHouse に格納されたテーブルをクエリできるようにし、フィルタ、結合、集計やその他サポートされる操作をリモート実行のために ClickHouse に送ろうとする。

Before v0.10.0, certain correlated subqueries remained as local PostgreSQL plans. pg_clickhouse could end up retrieving rows from ClickHouse and evaluating the subquery against each outer row. That design erased the advantage of putting the analytical data in a column-oriented database because the extension moved large result sets across the database boundary and repeated work inside PostgreSQL.

v0.10.0 以前は、いくつかの相関サブクエリがローカルの PostgreSQL プランのままだった。pg_clickhouse は ClickHouse から行を取得し、外側の各行に対してサブクエリを評価することになり得た。その設計は、分析データを列指向データベースに置く利点を失わせた。というのも、拡張が大きな結果セットをデータベースの境界を越えて移動させ、PostgreSQL 内で処理を繰り返したからだ。

Ventura's team changed the planner and deparser so supported PostgreSQL subqueries become ClickHouse subqueries inside the remote SQL statement. Ventura summarized the change plainly: "Now, subqueries in Postgres become subqueries in ClickHouse."

Ventura のチームはプランナとデパーサを変更し、サポートされる PostgreSQL のサブクエリがリモート SQL 文の内部で ClickHouse のサブクエリになるようにした。Ventura はその変更を率直にまとめている:「今では、Postgres のサブクエリは ClickHouse のサブクエリになります。」

Q17 provides the clearest example. The query calculates an average quantity for each part through a correlated subquery over 6 million line items. ClickHouse reported that pg_clickhouse v0.3 took 32,709 milliseconds because the operation was evaluated locally. Version 0.10 completed it in 37 milliseconds after sending the full query to ClickHouse. Native PostgreSQL took 2,107 milliseconds in the same published test.

Q17 が最もわかりやすい例を示す。このクエリは、600万の line item を横断する相関サブクエリを通じて各部品の平均数量を計算する。ClickHouse は、pg_clickhouse v0.3 がその操作をローカルで評価していたため 32,709 ミリ秒かかったと報告した。完全なクエリを ClickHouse に送信した後、バージョン 0.10 は 37 ミリ秒で完了した。同じ公表テストでネイティブの PostgreSQL は 2,107 ミリ秒だった。

The project's current benchmark table says the tests used TPC-H scale factor 1 on a MacBook Pro with an M4 Max processor and 36 GB of memory. Q2 fell from 3,446 milliseconds in pg_clickhouse v0.3 to 24 milliseconds in v0.10. Q22 dropped from 1,415 milliseconds to 45 milliseconds, although Q22 still uses multiple remote scans rather than one foreign scan.

プロジェクトの現在のベンチマーク表によると、テストは M4 Max プロセッサと36 GBのメモリを搭載した MacBook Pro 上で、TPC-H スケールファクター1 を使用して行われた。Q2 は pg_clickhouse v0.3 の 3,446 ミリ秒から v0.10 の 24 ミリ秒に低下した。Q22 は 1,415 ミリ秒から 45 ミリ秒に落ちたが、Q22 は依然として単一の foreign scan ではなく複数のリモートスキャンを使用している。

Those qualifications matter. TPC-H is a controlled decision-support benchmark, and the published numbers cover one machine, one data scale and selected query plans. ClickHouse has not published pg_clickhouse deployment counts, production customer results or revenue attributable to the extension.

これらの但し書きは重要だ。TPC-H は制御された意思決定支援のベンチマークであり、公表された数値は1台のマシン、1つのデータ規模、および選択されたクエリプランを対象としている。ClickHouse は pg_clickhouse の展開数、本番顧客での結果、または拡張に起因する収益を公表していない。

Query correctness became the harder problem

クエリの正確性がより困難な問題になった

Sending SQL to another database engine creates a second obligation: the remote query must return the result PostgreSQL would have produced.

別のデータベースエンジンに SQL を送ることは第二の義務を生む:リモートクエリは PostgreSQL が生成したであろう結果を返さなければならない。

Ventura focused part of the release on IN, NOT IN, ANY and ALL expressions involving null values. PostgreSQL uses three-valued logic, where an expression can evaluate to true, false or null. ClickHouse's default behavior for these operations uses two-valued logic. A naive translation can therefore return rows PostgreSQL would have filtered out.

Ventura はリリースの一部で、null 値を含む INNOT INANYALL 式に注力した。PostgreSQL は三値論理を使用しており、式は true、false、または null に評価され得る。ClickHouse のこれらの操作に対するデフォルトの振る舞いは二値論理である。そのため単純な翻訳は、PostgreSQL がフィルタアウトしたはずの行を返してしまう可能性がある。

Version 0.10 adds guards based on how an expression is consumed and whether pg_clickhouse can prove its operands cannot be null. That approach reduces the risk of an apparently successful query producing a subtly different answer.

バージョン 0.10 では、式がどのように消費されるか、そして pg_clickhouse がそのオペランドが null であり得ないことを証明できるかどうかに基づいたガードを追加した。そのアプローチは、一見成功したクエリが微妙に異なる答えを出すリスクを低減する。

The new correlated-subquery path requires ClickHouse 25.8 or later. pg_clickhouse checks the server version during planning and falls back to local evaluation when the connected ClickHouse server cannot handle the translated query.

新しい相関サブクエリ経路は ClickHouse 25.8 以降を必要とする。pg_clickhouse はプランニング中にサーバーバージョンをチェックし、接続先の ClickHouse サーバーが変換されたクエリを扱えない場合はローカル評価にフォールバックする。

Six TPC-H queries remain outside full pushdown: Q13, Q15, Q16, Q18, Q20 and Q21. Several are blocked because PostgreSQL converts their subqueries into anti- or semi-joins whose inputs contain additional joins. The pg_clickhouse deparser cannot yet traverse join trees on both sides of that operation. ClickHouse identifies that planner work as the next major step.

完全なプッシュダウンの対象外となっている TPC-H クエリは6件残っている:Q13、Q15、Q16、Q18、Q20、Q21。いくつかは、PostgreSQL がそれらのサブクエリを追加の結合を含む入力を持つ anti- または semi-join に変換するためにブロックされている。pg_clickhouse のデパーサはまだその操作の両側にある結合ツリーを横断できない。ClickHouse はそのプランナ側の作業を次の大きなステップと位置づけている。

The extension is becoming part of ClickHouse's Postgres strategy

この拡張は ClickHouse の Postgres 戦略の一部になりつつある

ClickHouse introduced pg_clickhouse in December 2025 to reduce the application work required when analytical data moves out of PostgreSQL. The premise was that moving data through replication had become easier, while rewriting years of SQL embedded in dashboards, object-relational mappers and scheduled jobs remained expensive.

ClickHouse は、分析データが PostgreSQL から移動する際に必要となるアプリケーション側の作業を減らすために、2025年12月に pg_clickhouse を導入した。前提は、レプリケーションでデータを移動することは容易になっている一方で、ダッシュボード、オブジェクトリレーショナルマッパー、定期ジョブに組み込まれた何年分もの SQL を書き直すのは依然として高コストだということだった。

The extension has since become a component of Postgres managed by ClickHouse, which entered public beta in May 2026. That service combines PostgreSQL for transactions, change-data capture into ClickHouse and pg_clickhouse as a query layer spanning both systems. The strategic value lies in preserving PostgreSQL as the application-facing interface while ClickHouse captures the heavier analytical execution.

その後、この拡張は Postgres managed by ClickHouse のコンポーネントとなり、同サービスは2026年5月にパブリックベータに入った。そのサービスはトランザクション用の PostgreSQL、ClickHouse への change-data capture、そして両システムをまたぐクエリ層としての pg_clickhouse を組み合わせる。戦略的価値は、アプリケーション側のインターフェイスとして PostgreSQL を維持しつつ、より重い分析実行を ClickHouse が受け持つ点にある。

The strategy targets accounts that already depend on PostgreSQL and would resist a full database migration. It also puts pressure on the engineering team to support the long tail of PostgreSQL query behavior, where compatibility failures can be harder to detect than outright errors.

この戦略は、既に PostgreSQL に依存しており完全なデータベース移行に抵抗する顧客をターゲットにしている。また、互換性の失敗は明白なエラーより検出が難しいことが多いため、PostgreSQL のクエリ挙動の長い裾野をサポートするようエンジニアリングチームにプレッシャーをかける。

ClickHouse has the capital to keep working through that list. In January, ClickHouse raised a $400 million Series D led by Dragoneer Investment Group, with participation from Bessemer Venture Partners, GIC, Index Ventures, Khosla Ventures, Lightspeed Venture Partners, T. Rowe Price-advised accounts and WCM Investment Management. ClickHouse said in May that it had passed 4,000 customers and $250 million in annual run-rate revenue.

ClickHouse にはそのリストの作業を継続するための資本がある。今年1月、ClickHouse は Dragoneer Investment Group が主導し、Bessemer Venture Partners、GIC、Index Ventures、Khosla Ventures、Lightspeed Venture Partners、T. Rowe Price に助言されたアカウント、WCM Investment Management らが参加して 4億ドルの Series D を調達した。ClickHouse は5月に 顧客数4,000を超え、年率換算収益が2億5,000万ドルを突破した と述べた。

Version 0.10 also rebuilds the binary driver around ClickHouse's plain-C client library, streams large results in blocks, adds compression and TLS controls, and gives concurrent foreign scans separate connections. The latter change addresses concurrency bugs in the driver. ClickHouse also expanded pushdown support for statistical aggregates, ordered-set aggregates, partitionwise aggregation, date operations and string functions.

バージョン 0.10 はまた、バイナリドライバを ClickHouse の plain-C クライアントライブラリを中心に再構築し、大きな結果をブロック単位でストリーミングし、圧縮および TLS 制御を追加し、同時実行される foreign scan に対して別々の接続を与える。後者の変更はドライバの並行性バグに対処するものだ。ClickHouse は統計集計、ordered-set 集計、partitionwise aggregation、日付操作および文字列関数に対するプッシュダウンサポートも拡張した。

The benchmark improvement will attract attention, but pg_clickhouse's larger test is compatibility. Milovidov built ClickHouse around fast analytical execution. The company is now betting that ClickHouse can sell that engine behind the PostgreSQL interface developers already trust. Ventura's subquery work closes several of the most expensive gaps, with six benchmark queries and a much larger universe of production SQL still ahead.

ベンチマークの改善は注目を集めるだろうが、pg_clickhouse にとってより大きな試練は互換性だ。Milovidov は高速な分析実行を中心に ClickHouse を構築した。同社は現在、ClickHouse が既に開発者が信頼する PostgreSQL インターフェイスの裏でそのエンジンを提供できると賭けている。Ventura のサブクエリに関する作業は最もコストの高いギャップのいくつかを埋めたが、ベンチマーク上で残る6つのクエリと、はるかに大きな本番環境の SQL の世界がまだ残されている。

Reader comments

Conversation for this story loads after sign-in.