Skip to content

Add enable_compression setting for MySQL table function and engine - #103229

Merged
tiandiwonder merged 1 commit into
ClickHouse:masterfrom
bernardlim:MySQL-protocol-compression
Jun 5, 2026
Merged

tiandiwonder merged 1 commit into
ClickHouse:masterfrom
bernardlim:MySQL-protocol-compression

Conversation

@bernardlim

@bernardlim bernardlim commented Apr 21, 2026 •

Copy link
Copy Markdown
Contributor

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Add enable_compression setting for the mysql table function, the MySQL table engine, the MySQL database engine, dictionary SOURCE(MYSQL), and named collections. When enabled, ClickHouse negotiates MySQL protocol-level compression for all data transferred over the connection.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Motivation: MySQL connections will benefit from protocol compression, bandwidth is expensive especially large transfers over public or bandwidth-constrained networks. enable_compression enables MySQL protocol compression for connections created through the mysql table function, MySQL table engine, MySQL database engine, dictionary SOURCE(MYSQL), and named collections.

Parameters:

  • enable_compression enables MySQL protocol compression for connections created through the mysql table function, MySQL table engine, MySQL database engine, dictionary SOURCE(MYSQL), and named collections.

Example use:

SELECT *
FROM mysql(
    'host:3306',
    'database',
    'table',
    'user',
    'password',
    SETTINGS enable_compression = 1
);

Example with named collection:

SELECT *
FROM mysql(my_mysql_conn, table = 'remote_table', enable_compression = 1);

Example with MySQL table engine:

CREATE TABLE mysql_table
ENGINE = MySQL('host:3306', 'database', 'table', 'user', 'password')
SETTINGS enable_compression = 1;

Example with MySQL dictionary source:

CREATE DICTIONARY my_dict (id UInt64, value String)
PRIMARY KEY id
SOURCE(MYSQL(
    host 'host' port 3306
    user 'user' password 'password'
    db 'database' table 'table'
    enable_compression 1
))
LAYOUT(FLAT()) LIFETIME(0);

Version info

  • Merged into: 26.6.1.418

@bernardlim
bernardlim marked this pull request as draft April 21, 2026 06:19
@bernardlim
bernardlim marked this pull request as ready for review April 21, 2026 06:19
@tiandiwonder tiandiwonder self-assigned this Apr 21, 2026

@tiandiwonder tiandiwonder 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.

No functional tests — The PR adds no test that verifies compression is actually negotiated. Given the blocker above, a test would have caught the defect immediately. At minimum, an integration test should confirm that a query succeeds when enable_compression = 1 is set and that the connection is established correctly.

Missing documentation — docs/en/engines/table-engines/integrations/mysql.md has a ## Settings section that documents each setting individually (e.g., connection_auto_close, connection_pool_size). The new enable_compression setting is absent from both that file and docs/en/sql-reference/table-functions/mysql.md.

Comment thread src/Common/mysqlxx/Connection.cpp Resolved
Comment thread src/Common/mysqlxx/Connection.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Apr 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [adff562]

Summary: ❌

job_name test_name status info comment
Stateless tests (arm_asan_ubsan, targeted) FAIL
Server died FAIL cidb IGNORED
Stateless tests (arm_asan_ubsan, azure, sequential) FAIL
03622_distributed_index_analysis_all_replicas ERROR cidb IGNORED
Server died FAIL cidb IGNORED
Segmentation fault (STID: 2520-6b44) FAIL cidb IGNORED
Integration tests (amd_asan_ubsan, db disk, old analyzer, 1/6) FAIL
test_hedged_requests/test.py::test_stuck_replica FAIL cidb IGNORED

AI Review

Summary

The PR adds the enable_compression setting across the mysql table function, MySQL table engine, MySQL database engine, MySQL dictionary sources, and named collections, then forwards it into MYSQL_OPT_COMPRESS. The current diff also adds documentation and focused integration assertions for the separate settings carriers, including shared XML dictionary pools. I did not find unresolved correctness, safety, or coverage issues that require inline comments.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Apr 21, 2026
@bernardlim

bernardlim commented May 18, 2026 •

Copy link
Copy Markdown
Contributor Author

No functional tests — The PR adds no test that verifies compression is actually negotiated. Given the blocker above, a test would have caught the defect immediately. At minimum, an integration test should confirm that a query succeeds when enable_compression = 1 is set and that the connection is established correctly.

Missing documentation — docs/en/engines/table-engines/integrations/mysql.md has a ## Settings section that documents each setting individually (e.g., connection_auto_close, connection_pool_size). The new enable_compression setting is absent from both that file and docs/en/sql-reference/table-functions/mysql.md.

Updated the PR and squashed it back into a single commit for easier review.

The current diff now includes:

  • enable_compression documented in the MySQL table engine syntax and settings section
  • a CREATE TABLE ... SETTINGS enable_compression = 1 example
  • enable_compression documented for the mysql table function
  • a table-function usage example
  • integration coverage in tests/integration/test_storage_mysql/test.py
  • dictionary/named-collection support via the MySQL dictionary allowed-key whitelist
  • connector-side propagation down to MYSQL_OPT_COMPRESS

Example usage for the MySQL table engine:

CREATE TABLE mysql_table
(
    id UInt64,
    name String
)
ENGINE = MySQL('mysql-host:3306', 'database', 'table', 'user', 'password')
SETTINGS enable_compression = 1;

Example usage for the MySQL table function:

SELECT *
FROM mysql(
    'mysql-host:3306',
    'database',
    'table',
    'user',
    'password'
)
SETTINGS enable_compression = 1;

Could you please review them, thank you @tiandiwonder.

@bernardlim
bernardlim force-pushed the MySQL-protocol-compression branch 3 times, most recently from 2c3940d to 019fa42 Compare May 19, 2026 04:06
@bernardlim

Copy link
Copy Markdown
Contributor Author

bump @tiandiwonder, can help trigger gh-bot review ?
thank you.

@bernardlim
bernardlim requested a review from tiandiwonder May 26, 2026 02:19
@tiandiwonder
tiandiwonder requested a review from Copilot May 27, 2026 00:39
@tiandiwonder tiandiwonder added the can be tested Allows running workflows for external contributors label May 27, 2026

Copilot AI 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.

Pull request overview

Adds an enable_compression option for MySQL-backed integrations, plumbing it from ClickHouse MySQL settings through connection pools into the mysqlxx connection setup where MYSQL_OPT_COMPRESS is applied.

Changes:

  • Registers enable_compression as a MySQL setting and forwards it through MySQL pool/failover constructors.
  • Applies MySQL protocol compression during connection initialization when enabled.
  • Adds integration coverage and documentation for table function/table engine usage.

Reviewed changes

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

Show a summary per file
File Description
src/Storages/MySQL/MySQLSettings.cpp Adds the new MySQL setting definition.
src/Storages/MySQL/MySQLHelpers.cpp Passes the setting into MySQL pool creation.
src/Dictionaries/MySQLDictionarySource.cpp Allows the setting in MySQL dictionary named collections.
src/Common/mysqlxx/PoolWithFailover.cpp Forwards compression into replica pools.
src/Common/mysqlxx/mysqlxx/PoolWithFailover.h Extends constructor signature.
src/Common/mysqlxx/Pool.cpp Reads/stores/forwards compression setting.
src/Common/mysqlxx/mysqlxx/Pool.h Adds pool member and constructor parameter.
src/Common/mysqlxx/mysqlxx/Connection.h Extends connection APIs/config loading.
src/Common/mysqlxx/Connection.cpp Applies MYSQL_OPT_COMPRESS before connecting.
tests/integration/test_storage_mysql/test.py Adds integration checks for setting usage paths.
docs/en/sql-reference/table-functions/mysql.md Documents table function usage.
docs/en/engines/table-engines/integrations/mysql.md Documents table engine usage.

Comment thread src/Common/mysqlxx/Connection.cpp Resolved
Comment thread src/Common/mysqlxx/mysqlxx/Pool.h Resolved
Comment thread src/Common/mysqlxx/Pool.cpp Resolved
@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label May 28, 2026
@bernardlim
bernardlim force-pushed the MySQL-protocol-compression branch from 13237e1 to cae90de Compare May 28, 2026 08:44
@CLAassistant

CLAassistant commented May 28, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Comment thread src/Common/mysqlxx/PoolFactory.cpp Resolved
@tiandiwonder

Copy link
Copy Markdown
Contributor

Table-function example in the PR description uses the wrong SETTINGS placement. The first example uses a trailing
query-level SETTINGS:

  SELECT * FROM mysql('host:3306', 'database', 'table', 'user', 'password')
  SETTINGS enable_compression = 1;

enable_compression is a MySQLSettings entry, not a query-level Setting, and TableFunctionMySQL::parseArguments only reads an
ASTSetQuery from inside the function arguments — so this form would raise UNKNOWN_SETTING. It should be inline:

  SELECT * FROM mysql('host:3306', 'database', 'table', 'user', 'password',
      SETTINGS enable_compression = 1);

@tiandiwonder tiandiwonder 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.

optional: No regression coverage for the cache-key change. Appending ?compression= in getPoolEntryName only takes effect when share_connection=true, but neither new XML dict sets it, so the discriminator is never exercised. Consider a share_connection=true pair differing only in enable_compression, asserting they don't share a pool (one Compression=ON, the other OFF).

@bernardlim
bernardlim force-pushed the MySQL-protocol-compression branch from ab89b0e to 030eea6 Compare June 1, 2026 16:26
bernardlim pushed a commit to bernardlim/ClickHouse that referenced this pull request Jun 1, 2026
Replace two sequential `SYSTEM RELOAD DICTIONARY` calls with a single
`SYSTEM RELOAD DICTIONARIES` so that `dict_compression_wire`
(enable_compression=1, share_connection=1) and `dict_no_compression_wire`
(enable_compression=0, share_connection=1) are both initialized in the same
`PoolFactory` cache lifetime. This directly exercises the cache-key
discriminator: if `?compression=` were removed from `getPoolEntryName`, both
dicts would share a pool and one of the two Compression=ON/OFF assertions
would fail.

ClickHouse#103229
@bernardlim
bernardlim force-pushed the MySQL-protocol-compression branch from 108402f to 6e98629 Compare June 1, 2026 16:40
bernardlim pushed a commit to bernardlim/ClickHouse that referenced this pull request Jun 2, 2026
…ame config path

Previously, PoolFactory::get() keyed shared pools by config_name (the Poco
config path, e.g. "dictionary.source.mysql"). Since ClickHouse loads each XML
dictionary from a separate config file, all dicts share this same path prefix,
so the first lookup (pools.find(config_name)) returned the first dict's pool
for every subsequent dict, bypassing getPoolEntryName entirely.

This meant two dicts with share_connection=1 and different enable_compression
values always shared one pool, causing the dict with enable_compression=0 to
use a compressed connection (Compression=ON) when it should be OFF.

Fix: for shared pools (share_connection=true), use entry_name — which encodes
host, port, user, db and compression — as the cache key instead of config_name.
Non-shared pools (share_connection=false, entry_name="") continue to use
config_name as before.

ClickHouse#103229
@bernardlim
bernardlim force-pushed the MySQL-protocol-compression branch 4 times, most recently from d23344e to 4e8154d Compare June 2, 2026 05:00
@bernardlim
bernardlim force-pushed the MySQL-protocol-compression branch from 4e8154d to adff562 Compare June 2, 2026 05:02
@clickhouse-gh

clickhouse-gh Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.40% 84.40% +0.00%
Functions 92.40% 92.40% +0.00%
Branches 77.00% 77.00% +0.00%

Changed lines: Changed C/C++ lines covered by tests: 74/105 (70.48%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

@bernardlim
bernardlim requested a review from tiandiwonder June 2, 2026 13:58
@bernardlim

Copy link
Copy Markdown
Contributor Author

I reckon all CI failures are pre-existing unrelated to this PR, none touch MySQL connection pooling.

@tiandiwonder

thanks for the feedbacks.

@tiandiwonder
tiandiwonder added this pull request to the merge queue Jun 5, 2026
Merged via the queue into ClickHouse:master with commit ef937ef Jun 5, 2026
162 of 167 checks passed
@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 5, 2026
@bernardlim
bernardlim deleted the MySQL-protocol-compression branch June 7, 2026 14:56
Maoyao233 pushed a commit to Maoyao233/ClickHouse that referenced this pull request Jun 8, 2026
`test_hedged_requests/test.py::test_stuck_replica` is chronically flaky
on heavily overcommitted ASan/UBSan integration shards. The failure shape
in CIDB is identical across 9 unrelated PRs in the past 30 days:

    pause_container('node_1') did not become observably effective within
    90.0s ... still succeed after ~890 probe iterations; last outcome:
    server replied (4 bytes)

The probe in `_wait_for_pause_effective` keeps receiving live ClickHouse
exception packets from `node_1` for the entire 90s budget, which proves
that `docker compose pause` returned success while the cgroup freezer
never actually froze the user-space tasks. The existing SIGSTOP fallback
in `ClickHouseCluster.pause_container` only fires when `docker compose
pause` raises an exception, not when it lies about success, so the
escalation path was never taken.

Switch this test to `cluster.pause_container_using_signal`, which uses
`SIGSTOP`/`SIGCONT` from the start. A signal cannot be silently lost the
way the cgroup freezer can, so the pause becomes observable on the very
first probe iteration. Same helper is already used by
`test_postgresql_replica_database_engine` for the same reason.

The change is local to one call site. The chronic flake hit
`Integration tests (amd_asan_ubsan, db disk, old analyzer, 1/6)` in the
following PRs (CIDB, last 30 days): ClickHouse#103404, ClickHouse#106311, ClickHouse#105010, ClickHouse#105056,
ClickHouse#104830, ClickHouse#106025, ClickHouse#100391, ClickHouse#106571, ClickHouse#103229. All show the same
`server replied (4 bytes)` outcome, distinguishing this from generic
flakiness.

Related: ClickHouse#106571
pull Bot pushed a commit to erickirt/ClickHouse that referenced this pull request Sep 22, 2026
…guration file

ClickHouse#112070 established that the source configuration of a dictionary created with a
DDL query comes from the query itself, so it may not name files for the server to
open: the server reads them with its own privileges. It implemented that as
checkNoSSLPaths, keyed on the three ssl_ca / ssl_cert / ssl_key key names rather
than on the invariant itself.

enable_local_infile is in the same dictionary_allowed_keys and satisfies the same
premise by a second, indirect route: it sets MYSQL_OPT_LOCAL_INFILE on the
outgoing connection, which lets the MySQL endpoint the dictionary points at ask
the client for the contents of a file of its choosing. The option is off by
default for exactly this reason, and has been since 33205bb ("Disable LOAD
DATA LOCAL INFILE because it is insecure", still visible at
mysqlxx/Connection.h:16); 26a951e re-exposed it as an argument and
bfc705c put it in the dictionary source's allowed keys, which is how a DDL
query reaches it. It was never considered in ClickHouse#112070, so this completes that
guard for the sibling key rather than duplicating it.

The guard is applied at the two configuration prefixes the connection pool
actually reads for a DDL-created dictionary: each <replica> prefix and the
single-endpoint prefix, both inside the existing created_from_ddl block of the
non-named-collection branch.

It resolves the value in Pool::Pool's own lookup order, a replica value winning
over the parent as its fallback (Pool.cpp:94-95), so what is rejected is the
value the connection would really use. That matters in both directions: a
<replica> inheriting a truthy parent is rejected, while a truthy parent whose
every replica sets 0 is not, because PoolWithFailover builds only per-replica
pools when replicas exist and so the parent alone decides nothing. An
independent parent check would reject that safe configuration; open ClickHouse#109736 is a
bug fix for the same class of mistake two lines away.

The guard is deliberately not placed beside checkNoSSLPaths, which sits before
the branch because for the SSL keys that breadth is necessary. It is not needed
there for this key: the named-collection route reaches
createMySQLPoolWithFailover, which passes the literal
MYSQLXX_DEFAULT_ENABLE_LOCAL_INFILE (PoolWithFailover.cpp:164), and MySQLSettings
carries no local_infile, so a collection-defined or NAME-overriding key is
accepted and then never read. Guarding it there would break a configuration that
cannot enable the option. That inertness is a precondition rather than a
property, so it is stated in the PR body: adding such a setting, as ClickHouse#103229 did
for enable_compression, would make that branch a live carrier.

Resolution is by value rather than by presence, unlike checkNoSSLPaths: for a
path key any value is dangerous, but enable_local_infile 0 is bit-for-bit the
default and harmless, and this change is already backward incompatible without
breaking configurations that never reach MYSQL_OPT_LOCAL_INFILE = 1.

socket is the one other key in that list naming a path a DDL query can choose. It
is deliberately not mirrored: it is a connect(2) to a path rather than a read of
a file's contents, and pointing a dictionary at a local mysqld.sock is a
legitimate, widely used configuration.

Tests: a stateless test covering the four shapes that enable the option (source,
an explicit <replica>, a <replica> that inherits it, a later <replica> when the
first disables it) and the two that do not (0 at the source, 0 at every <replica>
of a truthy source), which needs no MySQL server
because the rejection precedes any connection, and an integration arm in
test_dictionaries_mysql proving a configuration-file dictionary still loads and
serves data with the option on while the same option from a DDL query against
that endpoint is rejected.

Co-Authored-By: Claude Opus 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors manual approve Manual approve required to run CI pr-improvement Pull request with some product improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants