Skip to content

Add schema caching and manual config for inserts#256

Merged
alex-clickhouse merged 6 commits intomainfrom
insert-skip-schema-query
Mar 24, 2026
Merged

Add schema caching and manual config for inserts#256
alex-clickhouse merged 6 commits intomainfrom
insert-skip-schema-query

Conversation

@alex-clickhouse
Copy link
Copy Markdown
Collaborator

@alex-clickhouse alex-clickhouse commented Mar 17, 2026

Adds two options for avoiding the schema query for inserts:

  • Schema cache (so it's done once)
  • Provide schema manually (so it's done never)

Manual schema takes priority over auto-discovered, if it's provided.

The latter option also requires the column list to be provided, because we don't know the ordering otherwise. But I don't think anyone relies on the db ordering of columns anyway (and they shouldn't), so I don't think it matters that much.

All this schema stuff is moved to its own class.

Also adds a new example showing how to use this functionality.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 17, 2026

Codecov Report

❌ Patch coverage is 89.47368% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
ClickHouse.Driver/Utility/SchemaResolver.cs 88.88% 5 Missing and 3 partials ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds schema-resolution optimizations for ClickHouseClient.InsertBinaryAsync by introducing a reusable SchemaResolver with two new InsertOptions knobs: supplying column types explicitly (skips schema probing entirely) and caching a table schema per client instance (avoids repeated probe round-trips). It also updates docs and examples, and adds tests to validate the new behavior.

Changes:

  • Add InsertOptions.ColumnTypes (manual schema) and InsertOptions.UseSchemaCache (per-client schema caching) for InsertBinaryAsync.
  • Refactor schema discovery/probing logic into a new internal SchemaResolver.
  • Add an example + NUnit tests, and document the feature in release notes/changelog.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
examples/README.md Adds a link to the new schema optimization insert example.
examples/Program.cs Runs the new SchemaOptimization example in the example runner.
examples/Insert/Insert_008_SchemaOptimization.cs Demonstrates ColumnTypes and UseSchemaCache usage for InsertBinaryAsync.
ClickHouse.Driver/Utility/SchemaResolver.cs New schema resolution component with manual schema + cache strategies.
ClickHouse.Driver/InsertOptions.cs Adds ColumnTypes and UseSchemaCache options and propagates them through WithQueryId.
ClickHouse.Driver/ClickHouseClient.cs Replaces inline schema probing with SchemaResolver.ResolveAsync.
ClickHouse.Driver.Tests/InsertBinarySchemaTests.cs Adds tests for manual schema and schema cache behavior.
RELEASENOTES.md Documents the new insert schema options for v1.1.0.
CHANGELOG.md Mirrors release note entries for the new insert schema options for v1.1.0.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread ClickHouse.Driver/Utility/SchemaResolver.cs Outdated
Comment thread ClickHouse.Driver/Utility/SchemaResolver.cs Outdated
Comment thread ClickHouse.Driver/Utility/SchemaResolver.cs Outdated
Comment thread ClickHouse.Driver.Tests/InsertBinarySchemaTests.cs
Comment thread examples/Insert/Insert_008_SchemaOptimization.cs Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds insert-schema optimization capabilities to ClickHouseClient.InsertBinaryAsync by introducing a dedicated schema resolution component, plus new InsertOptions knobs to either provide schema manually or cache resolved schema across inserts. Includes new example usage and automated tests to validate query-count behavior and correctness.

Changes:

  • Introduce SchemaResolver to centralize insert schema discovery, manual schema usage, and optional per-client schema caching.
  • Add InsertOptions.ColumnTypes (manual schema) and InsertOptions.UseSchemaCache (cached schema) and wire them into InsertBinaryAsync.
  • Add an examples entry + new insert example, and add a comprehensive NUnit test suite covering the new behavior.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
examples/README.md Adds the new schema optimization insert example to the examples index.
examples/Program.cs Runs the new schema optimization example as part of the insert examples sequence.
examples/Insert/Insert_008_SchemaOptimization.cs Demonstrates using ColumnTypes and UseSchemaCache with InsertBinaryAsync.
RELEASENOTES.md Documents the new insert schema optimization options for the upcoming release.
CHANGELOG.md Mirrors release notes for the new schema optimization options.
ClickHouse.Driver/Utility/SchemaResolver.cs New internal component implementing schema resolution + caching strategy.
ClickHouse.Driver/InsertOptions.cs Adds new public insert options (ColumnTypes, UseSchemaCache) and clones them in WithQueryId.
ClickHouse.Driver/ClickHouseClient.cs Integrates SchemaResolver into InsertBinaryAsync and removes inline schema probing helper.
ClickHouse.Driver.Tests/InsertBinarySchemaTests.cs Adds tests ensuring schema probing is skipped/cached as expected and data round-trips correctly.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread ClickHouse.Driver/InsertOptions.cs
Comment thread ClickHouse.Driver/Utility/SchemaResolver.cs Outdated
Comment thread ClickHouse.Driver/Utility/SchemaResolver.cs Outdated
@alex-clickhouse alex-clickhouse requested a review from mzitnik March 17, 2026 15:36
@alex-clickhouse alex-clickhouse merged commit 05ae940 into main Mar 24, 2026
17 checks passed
@alex-clickhouse alex-clickhouse deleted the insert-skip-schema-query branch March 24, 2026 09:29
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.

3 participants