Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

[r2dbc] getRowsUpdated() returns 0 for successful INSERT…SELECT — needs reliable written_rows

オープン
#2,860 コメント 6 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
52/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
静か
技術スタック
java
領域
databases

調査の方向性

ClickHouseResult から始め、ClickHouseResponseSummary.getProgress()、getStatistics()、およびトップレベルの getWrittenRows() がどのように UpdateCount を提供しているかを追跡します。HTTP トランスポートを使用して INSERT INTO … SELECT クエリを再現し、getRowsUpdated() と最終的な written_rows の値を比較します。選択した完了後の権威ある値が確実に公開され、成功する INSERT…SELECT に対するリグレッションカバレッジがあることをもって完了とします。

索引モデルが issue の本文から書いたものです。

説明

Summary

ClickHouseResult.getRowsUpdated() in clickhouse-r2dbc returns 0 for
successful INSERT INTO … SELECT FROM … queries that did write rows. This
makes it impossible to reliably distinguish "INSERT…SELECT wrote 0 rows
because the SELECT produced none" from "INSERT…SELECT wrote N rows but the
driver reported 0" at the application layer.

The same row count appears correctly in system.query_log.written_rows
server-side, and the HTTP X-ClickHouse-Summary header also carries an
accurate written_rows once the query finishes. The information exists; the
driver just doesn't expose it via the standard R2DBC Result.getRowsUpdated()
contract for this query shape.

Reproduction

  • Driver: com.clickhouse:clickhouse-r2dbc:0.9.0 (also reproduces on 0.8.x)
  • Server: ClickHouse 25.3
  • Query shape: INSERT INTO target_table (...) SELECT ... FROM source_table WHERE ...
  • Connection settings: async_insert=1, wait_for_async_insert=1
    (per docs, async_insert is a no-op for INSERT…SELECT, but we set it
    globally for the INSERT VALUES path on the same connection)
Flux.from(statement.execute())
    .flatMap(Result::getRowsUpdated)   // emits 0 even when N rows were inserted
    .reduce(0L, Long::sum)
    // observed: returns 0

Verifying server-side after the query finishes:

SELECT written_rows
FROM system.query_log
WHERE query_id = '...' AND type = 'QueryFinish';
-- returns N (the correct count)

Root cause

Looking at ClickHouseResult constructor (current main):

Mono<? extends UpdateCount> updatedCount = Mono.just(response)
    .map(ClickHouseResponse::getSummary)
    .map(ClickHouseResponseSummary::getProgress)
    .map(ClickHouseResponseSummary.Progress::getWrittenRows)
    .map(UpdateCount::new);

The driver reads written_rows from Summary.getProgress(), which is the
interim progress event snapshot — not the final summary. For
INSERT…SELECT queries, a definitive post-completion written_rows is
typically reflected in Summary.getStatistics() (or in a final progress
event that doesn't always land before the subscriber observes completion).

ClickHouseResponseSummary exposes both getProgress() and getStatistics(),
and the top-level getWrittenRows() delegates to progress.

Use case

Detecting at the application layer when an INSERT…SELECT wrote zero rows
(to surface inconsistency conditions before committing dependent state).
Since getRowsUpdated() can return 0 even on success, the check fires
false positives.

Asks

Any one of the following would unblock us:

  1. Source getRowsUpdated() from Summary.getStatistics() (or whichever
    field is authoritative post-completion) instead of from Summary.getProgress().
  2. Expose the raw ClickHouseResponseSummary from ClickHouseResult (or a
    similar handle), so callers can read the final fields themselves.
  3. Document the current semantics so applications know not to rely on
    getRowsUpdated() for INSERT…SELECT.

Happy to send a PR for (1) or (2) — please confirm which direction you'd
prefer.

Environment

  • clickhouse-r2dbc: 0.9.0
  • clickhouse-client / clickhouse-http-client: 0.9.0
  • ClickHouse server: 25.3.x
  • Connection: HTTP transport
主要言語
Java
スター
1.6k
フォーク
637
平均マージ
2日 17時間
マージ済み PR(30日)
29

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

ClickHouse/clickhouse-java のほかの issue

ClickHouse/clickhouse-java の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。