Repository navigation
Add MySQL-compatibility columns to INFORMATION_SCHEMA views - #109351
Conversation
MySQL-aware clients (JDBC/ODBC drivers, IDEs, BI tools, federated query engines) issue MySQL-flavored catalog queries against `INFORMATION_SCHEMA` when they observe the MySQL wire-protocol handshake. ClickHouse implements `INFORMATION_SCHEMA` following the SQL standard, so MySQL-only columns are absent and such queries fail at analysis time with `UNKNOWN_IDENTIFIER`. For example, `SELECT DEFAULT_COLLATION_NAME FROM INFORMATION_SCHEMA.SCHEMATA` could not be resolved at all, because the identifier does not exist in the view - the client cannot even fall through on a `NULL` value. Add the commonly-required MySQL extension columns: - `SCHEMATA`: `default_collation_name` (constant `utf8mb4_0900_ai_ci`, matching what the MySQL handshake advertises) and `default_encryption` (constant `NO`). - `TABLES`: `engine`, `version`, `row_format`, `avg_row_length`, `max_data_length`, `data_free`, `auto_increment`, `create_time`, `update_time`, `check_time`, `checksum`, `create_options`. `engine` is populated from `system.tables`; the rest have no ClickHouse analog and are `NULL`. - `COLUMNS`: `column_key` (`PRI` for primary-key columns), `privileges`, `generation_expression` (the expression of `MATERIALIZED`/`ALIAS` columns), and `srs_id`. Both lowercase and uppercase aliases resolve, consistent with the rest of `INFORMATION_SCHEMA`. An audit of the remaining views found that `STATISTICS` and `KEY_COLUMN_USAGE` already expose the full MySQL column set. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Workflow [PR], commit [0d1517b] Summary: ✅
AI ReviewSummaryThis PR adds MySQL-compatibility columns to Tests
Final VerdictThe end-state code looks reasonable, but I would add the missing |
The Fast test `02206_information_schema_show_database` failed because adding the MySQL-compatibility columns to the `COLUMNS` and `TABLES` views changed their `SHOW CREATE` output, but only the `01161_information_schema.reference` file was regenerated. Regenerate `02206_information_schema_show_database.reference` as well. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=109351&sha=20a44de7ff2527796d6c552b92feea0dda92a177&name_0=PR&name_1=Fast%20test Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
I took a pass at the two review comments here and pushed the result to a branch on my fork, in case it's useful — feel free to fold it into this PR's branch (or ignore it). Patch (applies on top of the current PR head curl -sL https://github.com/flaviomalavazi/ClickHouse/commit/4178c94eed52eb8fdf270cde13aba4789ab7f820.patch | git amWhat it changes:
Happy to adjust anything. |
…e collation Addresses the two review comments on PR #109351. - `INFORMATION_SCHEMA.COLUMNS.privileges` now returns an empty string instead of the hard-coded `select,insert,update,references`. `system.columns` is visible to users holding only `SHOW COLUMNS`, so a fabricated grant set would tell a read-only user the schema is writable and only fail later with access-denied. Empty matches the pre-existing `SHOW FULL COLUMNS` path (`InterpreterShowColumnsQuery`). - Keep `SCHEMATA.default_collation_name` on the modern `utf8mb4_0900_ai_ci` and raise the MySQL handshake to match it, rather than reverting the schema column to the deprecated `utf8_general_ci`. `MySQLHandler` now advertises `CharacterSet::utf8mb4_0900_ai_ci` (id 255, added to the `CharacterSet` enum), so the advertised wire collation and `SCHEMATA.DEFAULT_COLLATION_NAME` agree on the modern, 4-byte-capable collation. - Correct the autogenerated `COLUMNS` documentation block, which listed `STATISTICS` columns (`non_unique`, `seq_in_index`, `cardinality`, ...), and document the new `column_key`, `privileges`, `generation_expression`, and `srs_id` columns. - Update reference outputs (`01161`, `02206`, `04489`) for the empty `privileges`. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Preview deployment for your docs. Learn more about Mintlify Previews.
|
|
Updating the branch to fix the |
…LE STATUS collation Addresses the two follow-up review comments on PR ClickHouse#109351. - Preserve ordinal positions of pre-existing `INFORMATION_SCHEMA` columns. The MySQL-compatibility columns were inserted in the middle of the `SCHEMATA`, `TABLES`, and `COLUMNS` view definitions, which shifted the ordinal positions of columns that already existed (`CATALOG_NAME`, `SCHEMA_NAME`, and the same pattern in `TABLES`/`COLUMNS`) and would break clients doing `SELECT *` or positional fetches against the previously released layout. The new columns are now appended after the pre-existing columns, so every prior column keeps its position. Column resolution is by name, so case-insensitive access is unaffected. References `01161` and `02206` regenerated accordingly; `04489` selects explicit columns and is unaffected. - Align the fabricated `SHOW TABLE STATUS` collation with the rest of the MySQL surface. `MySQLHandler` returned `utf8_bin` for `SHOW TABLE STATUS.Collation` while `INFORMATION_SCHEMA.TABLES.table_collation` and the handshake advertise `utf8mb4_0900_ai_ci`; a client mixing the two introspection paths saw contradictory metadata. It now returns `utf8mb4_0900_ai_ci` too. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Follow-up addressing the two review comments above (ordinal shift + curl -sL https://github.com/flaviomalavazi/ClickHouse/commit/07e6cee0ddd0bcd00507b09facbf44b0da92730d.patch | git amWhat it changes:
I validated the reordered views and regenerated references with |
…LE STATUS collation Addresses the two follow-up review comments on PR #109351. - Preserve ordinal positions of pre-existing `INFORMATION_SCHEMA` columns. The MySQL-compatibility columns were inserted in the middle of the `SCHEMATA`, `TABLES`, and `COLUMNS` view definitions, which shifted the ordinal positions of columns that already existed (`CATALOG_NAME`, `SCHEMA_NAME`, and the same pattern in `TABLES`/`COLUMNS`) and would break clients doing `SELECT *` or positional fetches against the previously released layout. The new columns are now appended after the pre-existing columns, so every prior column keeps its position. Column resolution is by name, so case-insensitive access is unaffected. References `01161` and `02206` regenerated accordingly; `04489` selects explicit columns and is unaffected. - Align the fabricated `SHOW TABLE STATUS` collation with the rest of the MySQL surface. `MySQLHandler` returned `utf8_bin` for `SHOW TABLE STATUS.Collation` while `INFORMATION_SCHEMA.TABLES.table_collation` and the handshake advertise `utf8mb4_0900_ai_ci`; a client mixing the two introspection paths saw contradictory metadata. It now returns `utf8mb4_0900_ai_ci` too. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
I believe PR#109389 fixed the Stress Test issue, @alexey-milovidov |
Resolve conflict in src/Server/MySQLHandler.cpp: master hardened showTableStatusReplacementQuery against SQL injection (parse the LIKE argument via tryParseSingleStringLiteral and re-quote it with quoteString, sharing a single SELECT template). This PR only changed the Collation column of that template from 'utf8_bin' to 'utf8mb4_0900_ai_ci'. Kept master's injection-safe structure and re-applied the PR's Collation change to the now-shared template. The PR's handshake charset change (CharacterSet::utf8mb4_0900_ai_ci) did not conflict and is preserved. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
We might need to merge PR#109415 to fix the new tests error |
…mysql-compat-columns
…mysql-compat-columns
|
Seems that the error is unrelated to this PR. |
…tent on the MySQL wire The AI review requested two changes before approval: 1. `INFORMATION_SCHEMA.COLLATIONS` and `SHOW COLLATION` now expose a MySQL-compatibility row for `utf8mb4_0900_ai_ci` (charset `utf8mb4`, id 255), so a client that follows the collation advertised in the handshake, `SCHEMATA.DEFAULT_COLLATION_NAME`, or `TABLES.TABLE_COLLATION` into either discovery path finds it. The MySQL-specific attributes are appended after the existing columns to preserve ordinal positions, and are NULL for the ICU collations. 2. Result-set metadata and `COM_FIELD_LIST` now stamp textual columns with the same charset id as the handshake (`CharacterSet::utf8mb4_0900_ai_ci` instead of `utf8_general_ci` and `binary`), so drivers that validate `ColumnDefinition41.character_set` no longer see the session advertised as three different charsets depending on packet type. Also added the requested MySQL-protocol integration test (`test_collation_consistency`) asserting that the handshake, `SHOW COLLATION`, `INFORMATION_SCHEMA`, and result-set column metadata all agree, and extended the stateless test with the `COLLATIONS` view coverage. The `01161` and `02206` reference outputs are unaffected (verified against the rebuilt binary). Co-Authored-By: Claude Fable 5 <[email protected]>
|
@groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=109351&sha=b0cca3209ae52b188fa092a31eb1e754db40608d&name_0=PR&name_1=BuzzHouse%20%28amd_msan%29 and provide a fix in a separate PR. If the fix is already in progress, link it here. Details: BuzzHouse (amd_msan) hit Meanwhile, commit b04e2f6 addresses the AI review's required actions: |
…WHERE MySQL matches collation and charset names case-insensitively and resolves column names in the WHERE clause of SHOW statements case-insensitively, while ClickHouse compares strings bytewise and resolves identifiers case-sensitively. So `SHOW COLLATION WHERE Charset = 'UTF8MB4'` returned no rows although the advertised collation surface is case-insensitive. Rewrite the parsed filter before re-serializing it: canonicalize identifiers to the column names of the synthetic result set, and for `=`, `!=`, `LIKE` and `IN` comparisons of a column against string literals, lowercase both sides (every string value in the synthetic set has a single known spelling, so this is lossless). Malformed tails still fall through untranslated, preserving the injection-safety behavior. Also generalize the `COLLATIONS` docs bullets to describe both MySQL-compatibility rows (`utf8mb4_0900_ai_ci` and `binary`), and add upper-case-literal regressions to `test_collation_consistency`. https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=109351&sha=556cc7ea2fa8d317465e334b5c1b093052b09e3e&name_0=PR #109351
…mysql-compat-columns
…s, share SHOW TABLE STATUS mapping with INFORMATION_SCHEMA.TABLES Two Majors from the AI review: - `makeShowCollationsFilterCaseInsensitive` lowercased comparisons on any column and wrapped the identifier in `lower`, so a quoted numeric filter like `SHOW COLLATION WHERE Id = '255'` threw an exception instead of matching after numeric/string coercion. Case-folding now applies only to the string-valued columns of the synthetic result set (`Collation`, `Charset`, `Default`, `Compiled`, `Pad_attribute`). - `SHOW TABLE STATUS` used its own mapping (constant '10'/'Dynamic', zero sizes, `metadata_modification_time`) that contradicted `INFORMATION_SCHEMA.TABLES` for the same object. It now selects from `INFORMATION_SCHEMA.TABLES`, so both MySQL introspection surfaces share one mapping. With regression tests for quoted `Id`/`Sortlen` filters and for `SHOW TABLE STATUS` / `INFORMATION_SCHEMA.TABLES` consistency. https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=109351&sha=596e404c42bfaf17ea0d84aaf1e0064715722894&name_0=PR
…tabase MySQL scopes `SHOW TABLE STATUS` to the session's default database, but the translation to `INFORMATION_SCHEMA.TABLES` filtered only on `table_name`, so a lookup also returned same-named tables from other databases. Constrain the generated query with `table_schema = currentDatabase()`: the replacement is executed with the session's query context, so `currentDatabase()` resolves to the session database and follows later `USE` statements. MySQL's `No database selected` state cannot arise, because a ClickHouse session always has a current database. Add a regression test with the same table name present in two databases, checking per-database results, `USE` switching, and the empty set in a database without a match. Co-Authored-By: Claude Fable 5 <[email protected]>
…mysql-compat-columns
…TATUS to the current database The test asserted that `SHOW TABLE STATUS LIKE 'one'` issued while connected to the `default` database returns `system.one` — exactly the cross-database leak that the review-requested `table_schema = currentDatabase()` guard now closes. Create a real `one` table in `default` for the duration of the test instead of relying on the leak. CI: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=109351&sha=c42d08c6596f1c9f475b84d2f5d4f01187310859&name_0=PR&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20flaky%29 Co-Authored-By: Claude Fable 5 <[email protected]>
…y for views `table_type` in `INFORMATION_SCHEMA.TABLES` is derived from `has_own_data` (`storesDataOnDisk`), so real user tables such as `Memory` classify as `FOREIGN TABLE`. The previous guard `if(table_type = 'BASE TABLE', t.engine, NULL)` therefore reported `ENGINE = NULL` for them, and `SHOW TABLE STATUS` inherited the same `NULL`. Suppress the engine name only for the view-like rows (`VIEW` / `SYSTEM VIEW`), keeping `t.engine` for every real table engine. Adds regressions for a `Memory` table over both `INFORMATION_SCHEMA.TABLES` (04489) and `SHOW TABLE STATUS` (test_mysql_protocol), and regenerates the 01161/02206 references. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Both failures are unrelated to this PR, as noted. Findings and status: 1.
The fix is in progress in your own #110630 and #110632: both replace the upfront allocation in 2. I pulled the arm_darwin Tracked in #103235 (closed 2026-07-23). No fixing PR exists for the hang sub-signature; the in-flight work is diagnostic tooling - #107173 and #111213, which fix macOS |
…mysql-compat-columns
…in `TABLES` The docs still said `engine` is `NULL` for every non-`BASE TABLE` row, but since 40fd81e only `VIEW`/`SYSTEM VIEW` rows are nulled, while real non-disk table engines such as `Memory` (`table_type = 'FOREIGN TABLE'`) keep their engine name. Co-Authored-By: Claude Fable 5 <[email protected]>
| # Result-set metadata: textual columns are stamped with the same charset id | ||
| # in ColumnDefinition41 packets, not with utf8_general_ci or binary. | ||
| cursor.execute("SELECT 'text' AS t, 1 AS n") | ||
| fields = {f.name: f.charsetnr for f in cursor._result.fields} |
There was a problem hiding this comment.
The new regression stops at cursor._result.fields from a normal SELECT, but the code change in this PR is also fixing the COM_FIELD_LIST / mysql_list_fields metadata path to share getColumnDefinition. _com_field_list still only returns column names, so a future change that regresses ColumnDefinition41.character_set, the MySQL type, or the flags on COM_FIELD_LIST would pass this suite.
Please add one focused assertion on that packet path as well, for example by extending _com_field_list to return the parsed metadata and checking that a string column reports charset 255 while a numeric column reports charset 63.
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 134/146 (91.78%) · Uncovered code |
Related: #48340
Extend the
INFORMATION_SCHEMAviews with the MySQL-only columns that MySQL-aware clients (JDBC/ODBC drivers, IDEs, BI tools, schema-management tools) rely on.ClickHouse implements
INFORMATION_SCHEMAfollowing the SQL standard, so these MySQL vendor-extension columns were absent. A client that observes the MySQL wire-protocol handshake assumes MySQL semantics and issues MySQL-flavored catalog queries, which then fail at analysis time withUNKNOWN_IDENTIFIER(error 47) — the identifier cannot be resolved at all, so the client cannot even fall through on aNULL. For example:Added columns (both lowercase and uppercase aliases resolve, consistent with the rest of
INFORMATION_SCHEMA):SCHEMATA:default_collation_name(constantutf8mb4_0900_ai_ci, matching what the MySQL handshake advertises) anddefault_encryption(constantNO).TABLES:engine(populated fromsystem.tables),version,row_format,avg_row_length,max_data_length,data_free,auto_increment,create_time,update_time,check_time,checksum,create_options. Columns with no ClickHouse analog areNULL.COLUMNS:column_key(PRIfor primary-key columns),privileges,generation_expression(the expression ofMATERIALIZED/ALIAScolumns), andsrs_id.An audit of the remaining views found that
STATISTICSandKEY_COLUMN_USAGEalready expose the full MySQL column set.Note on
COLUMNS.privileges: it returns a constantselect,insert,update,referencesregardless of the current user's grants (MySQL computes it from real grants), chosen for client compatibility and consistent with the pre-existing fabricatedTABLES.table_collation. Happy to change it to an empty string if preferred.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Added MySQL-compatibility columns to
INFORMATION_SCHEMAviews:SCHEMATA.DEFAULT_COLLATION_NAMEandDEFAULT_ENCRYPTION;TABLES.ENGINEand related MySQL columns; andCOLUMNS.COLUMN_KEY,PRIVILEGES,GENERATION_EXPRESSION,SRS_ID. This lets MySQL-aware clients run their catalog introspection queries without hittingUNKNOWN_IDENTIFIER.Documentation entry for user-facing changes
🤖 Generated with Claude Code
Version info
26.8.1.529(included in26.8and later)