Skip to content

chore: deprecate withasync helpers - #2096

Merged
kavirajk merged 13 commits into
mainfrom
kavirajk/deprecate-with-async-helper
Nov 13, 2026
Merged

kavirajk merged 13 commits into
mainfrom
kavirajk/deprecate-with-async-helper

Conversation

@kavirajk

@kavirajk kavirajk commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Related: #1848

Async insert is default since CH 26.2 (older than all the versions client now supports). It's often confusing that this helper exists.

Also not clear way to disable async insert if user wants to.

This PR explains the rationale, update the README and docs and mark those apis depreicated.

Checklist

Delete items not relevant to your PR:


Note

Low Risk
Documentation and deprecation-only for runtime behavior; existing helpers remain. New tests validate insert settings without changing production insert logic.

Overview
Deprecates WithAsync, WithStdAsync, and Conn.AsyncInsert and documents WithSettings with async_insert / wait_for_async_insert as the supported path. Godoc and README now call out that ClickHouse 26.2+ enables async insert by default (latency on single-row inserts) and that WithAsync(false) does not turn async off.

Examples, benchmarks, and MDX docs are rewritten to use WithSettings instead of the deprecated helpers, including migration tables and notes that multiple WithSettings calls replace rather than merge.

Adds tests/async_insert_test.go integration coverage (native + database/sql, both protocols) that asserts sync vs async inserts via system.query_log profile events for server default, client settings, and context overrides.

Reviewed by Cursor Bugbot for commit db933f0. Bugbot is set up for automated code reviews on this repo. Configure here.

Signed-off-by: Kaviraj <kavirajkanagaraj@gmail.com>
Signed-off-by: Kaviraj <kavirajkanagaraj@gmail.com>
Signed-off-by: Kaviraj <kavirajkanagaraj@gmail.com>
Signed-off-by: Kaviraj <kavirajkanagaraj@gmail.com>
Signed-off-by: Kaviraj <kavirajkanagaraj@gmail.com>
@kavirajk
kavirajk requested a review from chernser as a code owner November 3, 2026 10:53

@ccoltx ccoltx left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to keep this helper, if the server default is WithAsync(false), this gives the user an easy way to set it too true.

We should also ensure there are integration tests that cover the default (so not passing async_insert=1) and one that sets async_insert=0.


// The batch uses only the context from PrepareBatch, so WithAsync must be on it.
ctx = clickhouse.Context(ctx, clickhouse.WithAsync(true))
// The batch uses only the context from PrepareBatch, so the async insert settings must be on it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't true anymore. Since the server defaults to async, this code isn't needed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless it defaults to WithAsync(false), then it would be required.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is with semantics as well. WithAsync(false) doesn't disable async insert. It sets async_insert=1, wait_for_async_insert=0. The false here is for wait_for_async_insert=0.

More reason not to use it :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know which one the server uses by default?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread docs/clickhouse-api.mdx Resolved
Comment thread docs/database-sql-api.mdx Resolved
@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

🤖 Claude review

Deprecates WithAsync, WithStdAsync and Conn.AsyncInsert, moves the docs, examples and benchmarks to WithSettings, and adds integration tests that read AsyncInsertQuery from system.query_log. The change is correct and I approve it.

What I verified:

  • No behavior change: only doc comments change in clickhouse.go, context.go and lib/driver/driver.go. The deprecated symbols stay available.
  • The replacement is equivalent. asyncInsert (Native and HTTP) only adds async_insert and wait_for_async_insert to the query options and then sends the query as exec does.
  • The docs claim "WithSettings replaces, it does not merge" agrees with WithSettings in context.go (o.settings = settings).
  • The new tests follow the project rules: MergeTree table, clusterAllReplicas and SYSTEM FLUSH LOGS ON CLUSTER on Cloud, t.Cleanup for each connection, version gates that skip, Native and HTTP, native API and database/sql.
  • The open thread about the WithSettings enable case is addressed by the new test case.

Blind spots:

  • I did not run the tests against a live server.
  • I did not verify the server facts in the docs (default since ClickHouse 26.2, the 50 ms and 200 ms adaptive timeouts) against the ClickHouse source.

Verdict: ✅ Approve

Inline comments are attached to the relevant lines. This summary updates in place on re-review.

Signed-off-by: Kaviraj <kavirajkanagaraj@gmail.com>
Comment thread README.md Resolved
Comment thread docs/clickhouse-api.mdx Resolved
Comment thread tests/async_insert_test.go Resolved
Signed-off-by: Kaviraj <kavirajkanagaraj@gmail.com>
Comment thread tests/async_insert_test.go Resolved
Comment thread docs/clickhouse-api.mdx
|---|---|
| `WithAsync(true)` | `WithSettings(clickhouse.Settings{"async_insert": 1, "wait_for_async_insert": 1})`. On ClickHouse 26.2 and later with the default server settings, you can remove it. |
| `WithAsync(false)`, `WithStdAsync(false)` | `WithSettings(clickhouse.Settings{"async_insert": 1, "wait_for_async_insert": 0})` |
| `conn.AsyncInsert(ctx, query, wait)` | `conn.Exec(ctx, query)` with the settings above on `ctx` |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Nit — nit: migration table omits args and WithStdAsync(true)

The table does not show two forms that a caller can have, so the caller must guess the replacement.

  • AsyncInsert also takes args ...any. The replacement is conn.Exec(ctx, query, args...).
  • The first row lists WithAsync(true) only. WithStdAsync(true) has the same replacement.
Suggested change
| `conn.AsyncInsert(ctx, query, wait)` | `conn.Exec(ctx, query)` with the settings above on `ctx` |
| `conn.AsyncInsert(ctx, query, wait, args...)` | `conn.Exec(ctx, query, args...)` with the settings above on `ctx` |

@github-actions

Copy link
Copy Markdown
Contributor

AI review gate — Human approval in place of AI review

Approved on the head commit by slabko (write access, not the author), standing in for the AI review:

  • Cursor Bugbot is still reviewing this commit.

What to do:

  • Nothing to do yet if the review is running. The gate turns green when it finishes clean.
  • No review showing up? Post bugbot run as a new top-level PR comment. If that does nothing, Bugbot is probably not enabled for this repository: ask a repository administrator.

Evaluated at db933f00. This required workflow does not re-run on its own once the AI review later concludes — check the Cursor Bugbot check on this commit directly for its current state.

@security-ai-gate-reviewer security-ai-gate-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated approval by the AI review gate.

The required AI review gate concluded SUCCESS on db933f0, and this change touches no path that requires a human reviewer. This approval is posted by an automated identity (security-ai-gate-reviewer[bot]), not a human, and is bound to the evaluated commit. A new push dismisses it and re-evaluates.

repo=ClickHouse/clickhouse-go pr=#2096 head=db933f007e475a7fd95bff8f237e47fbd8d1adcd

@polyglotAI-bot

Copy link
Copy Markdown
Collaborator

Deprecates the async insert helpers, documents migration to explicit server settings, and adds integration coverage for settings precedence across both APIs and protocols. No actionable defects found in the reviewed snapshot. ✅ Approve. This was a static review: integration tests and the stated server defaults and timing were not verified at runtime.

Final verdict

✅ Approve

Automated review by Polyglot AI (gpt-6-astra) of db933f0. Requested by @kavirajk. Replies on the inline threads are read on the next review. A maintainer can ask for a new review by mentioning @polyglotAI-bot or requesting a review from it.

@polyglotAI-bot polyglotAI-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of db933f0 posted: see the summary comment and the inline threads.

@kavirajk
kavirajk merged commit d124d2b into main Nov 13, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants