Repository navigation
Add enable_compression setting for MySQL table function and engine - #103229
Conversation
tiandiwonder
left a comment
There was a problem hiding this comment.
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.
|
Workflow [PR], commit [adff562] Summary: ❌
AI ReviewSummaryThe PR adds the Final VerdictStatus: ✅ Approve |
Updated the PR and squashed it back into a single commit for easier review. The current diff now includes:
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. |
2c3940d to
019fa42
Compare
|
bump @tiandiwonder, can help trigger gh-bot review ? |
There was a problem hiding this comment.
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_compressionas 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. |
13237e1 to
cae90de
Compare
0561c54 to
5026536
Compare
|
Table-function example in the PR description uses the wrong SETTINGS placement. The first example uses a trailing enable_compression is a MySQLSettings entry, not a query-level Setting, and TableFunctionMySQL::parseArguments only reads an |
tiandiwonder
left a comment
There was a problem hiding this comment.
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).
ab89b0e to
030eea6
Compare
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
108402f to
6e98629
Compare
…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
d23344e to
4e8154d
Compare
4e8154d to
adff562
Compare
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 74/105 (70.48%) | Lost baseline coverage: none · Uncovered code |
|
I reckon all CI failures are pre-existing unrelated to this PR, none touch MySQL connection pooling. thanks for the feedbacks. |
ef937ef
`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
…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]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Add
enable_compressionsetting for themysqltable function, theMySQLtable engine, theMySQLdatabase engine, dictionarySOURCE(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
Motivation: MySQL connections will benefit from protocol compression, bandwidth is expensive especially large transfers over public or bandwidth-constrained networks.
enable_compressionenables MySQL protocol compression for connections created through themysqltable function,MySQLtable engine,MySQLdatabase engine, dictionarySOURCE(MYSQL), and named collections.Parameters:
enable_compressionenables MySQL protocol compression for connections created through themysqltable function,MySQLtable engine,MySQLdatabase engine, dictionarySOURCE(MYSQL), and named collections.Example use:
Example with named collection:
Example with MySQL table engine:
Example with MySQL dictionary source:
Version info
26.6.1.418