Repository navigation
Add "Maybe you meant ...?" hint to SHOW CREATE for a missing table - #110633
Conversation
When `SHOW CREATE TABLE` (or `VIEW`/`DICTIONARY`) refers to a table that
does not exist, the error was thrown without the "Maybe you meant ...?"
suggestion that `SELECT` queries already produce for a similarly-named
table, e.g.:
Code: 60. DB::Exception: There is no metadata of table emb_siglip2 in database default. (UNKNOWN_TABLE)
The hint is now added in the common `IDatabase::getCreateTableQuery`
wrapper, so it applies to every database engine (the various
`getCreateTableQueryImpl` overrides report a missing table with
`UNKNOWN_TABLE`, `CANNOT_GET_CREATE_TABLE_QUERY`, or
`CANNOT_GET_CREATE_DICTIONARY_QUERY`). It is computed after
`getCreateTableQueryImpl` returns, i.e. outside any database lock it may
hold, to avoid a deadlock, and only when the table is really absent.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Workflow [PR], commit [0c8e424] Summary: ✅
AI ReviewSummaryThis PR extends Findings
Final VerdictChanges not yet ready: the dictionary-only remask still lies about existing dictionaries when |
|
@groeneai, investigate the failure: AST fuzzer (amd_debug, targeted) — This is unrelated to this PR's diff (only |
…ableQuery, add dictionary-database test coverage `isTableExist` can itself throw for remote engines like `DatabaseMySQL` and `DatabaseMaterializedPostgreSQL` (both re-fetch metadata), which was replacing the original, more informative exception (e.g. a MySQL connection failure) with the new one raised while merely checking whether the table exists for hint purposes. Swallow that secondary failure and preserve the original exception instead. Also add a stateless test case exercising the `CANNOT_GET_CREATE_DICTIONARY_QUERY` branch via a `Dictionary`-engine database, which was previously untested.
|
Investigated. This is a pre-existing engine bug, unrelated to this PR's diff — confirmed via CIDB: STID 2508-3750 appears only on unrelated branches (this PR and #109768's Root cause: the fuzzed query is EXPLAIN AST optimize = 1 SELECT count()
FROM dist_larger AS lt INNER JOIN dist_smaller AS rt ON lt.key = rt.key
SETTINGS distributed_product_mode = 'local', enable_analyzer = 1where both are Fix in a separate PR: #110677. It mirrors the This is distinct from the other |
…ning out of stderr The test creates a database with the deprecated `Ordinary` engine, and the server emits the "Server has databases (for example ...) with Ordinary engine, which was deprecated" warning once per server lifetime, synchronously within the first such `CREATE DATABASE` query. Shell tests run `clickhouse-client` with `--send_logs_level=warning`, so whenever this test happened to be the first one to create an `Ordinary` database (always the case in the flaky check, sometimes in parallel runs), the warning was forwarded to the client and failed the test with "having stderror". Pass `--send_logs_level=fatal` for that single statement, like other tests creating `Ordinary` databases do (e.g. `04340_timeseries_rename_digest_mismatch`). Failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110633&sha=4b1e0730977f25a9a7dab1e9a293fc65f2855c24&name_0=PR&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20flaky%20check%29 PR: #110633 Co-Authored-By: Claude Fable 5 <[email protected]>
`SHOW CREATE DICTIONARY` is authorized with the `SHOW_DICTIONARIES` grant, which does not imply `SHOW_TABLES`, but `TableNameHints` filtered hint candidates with `SHOW_TABLES` only - so a user with dictionary-only visibility still got the bare error without the "Maybe you meant ...?" hint. Keep a candidate name visible when the user has `SHOW_DICTIONARIES` on it and the object really is a dictionary: the grant by itself does not tell tables and dictionaries apart, so the extra check is needed to avoid leaking the names of tables to a user with only a dictionary-level grant. Add an RBAC regression test covering both sides: the dictionary-only user gets the hint for a similarly-named dictionary, and gets no hint (no name leak) for a typo close to a table's name. PR: #110633 Co-Authored-By: Claude Fable 5 <[email protected]>
The previous `SHOW_DICTIONARIES` fix classified every candidate name with `IDatabase::tryGetTable` inside `TableNameHints::getAllRegisteredNames`. For a user with `GRANT SHOW DICTIONARIES ON db.*`, `IAccessRights::isGranted` is true for every name, so a single typo in `SHOW CREATE DICTIONARY` could synchronously foreground-load every table in the database (each `tryGetTable` waits for startup/lazy-load completion and `getAllTableNames` also returns not-yet-loaded names), and could even trip an unrelated load failure while merely formatting an error hint. Keep `getAllRegisteredNames` a cheap, name-only filter: a name visible only through `SHOW_DICTIONARIES` is now kept as a candidate without any load. The dictionary classification moves to a new `TableNameHints::isHintNameVisible`, applied only to the single closest ranked candidate in `getHintForTable` and `getExtendedHintForTable`. That loads at most one table (the matched candidate), and only when it is not already covered by `SHOW_TABLES` - so a dictionary-only grant still cannot leak the names of similarly-named tables. Behavior for `04545_show_create_table_hints` and `04546_show_create_dictionary_hint_rbac` is unchanged.
…t path fail-closed Two follow-ups from the AI review of the SHOW CREATE hint change. Major 1: `TableNameHints::getHintForTable` and `getExtendedHintForTable` filtered visibility only after `IHints<>` had already truncated the candidates to a single raw name. With a `SHOW_DICTIONARIES`-only grant, a closer hidden table could therefore mask a farther but visible dictionary, so `SHOW CREATE DICTIONARY` fell back to the bare error even though an allowed dictionary existed. Both methods now ask `NamePrompter` for several ranked candidates (`max_hint_candidates`) and return the closest one that is actually visible, so the closer hidden table is skipped and the dictionary is suggested. The user-facing message still shows a single hint. Major 2: `isHintNameVisible` loads the matched object via `tryGetTable` to confirm it really is a dictionary, but `TableNameHints` is shared by generic unknown-table paths (`IDatabase::getTable`, `DatabaseCatalog::tryGetTable`, `IdentifierResolver`), not only by the guarded `SHOW CREATE` wrapper. On ordinary/atomic databases `tryGetTable` waits for the matched table to start up and rethrows load errors, so a plain missing-table lookup could surface an unrelated startup/load exception while merely formatting a hint. `isHintNameVisible` now catches any such error and treats it as "not visible", keeping hint computation fail-closed. Extends `04546_show_create_dictionary_hint_rbac` with the masking case: a dictionary-only user is suggested a visible dictionary even when a closer hidden table exists, without leaking the table's name.
The `catch_all` style check flagged the `catch (...)` added in the previous commit (fail-closed handling in `TableNameHints::isHintNameVisible`) as silently swallowing exceptions. The swallow is intentional: it runs only while formatting a hint for a missing table, and a load error there must not replace the original `UNKNOWN_TABLE` error. Add the sanctioned `Ok` comment inside the catch block to document this and satisfy the check.
…DICTIONARY probe `SHOW CREATE DICTIONARY` is authorized with the `SHOW DICTIONARIES` grant, which does not imply `SHOW TABLES` / `SHOW COLUMNS`. Previously, when a user holding only `SHOW DICTIONARIES` named an object that turned out to be a regular table rather than a dictionary, `InterpreterShowCreateQuery` fetched its create query and threw `BAD_ARGUMENTS` `... is not a DICTIONARY` with the table name. That let such a user tell a hidden table apart from a name that does not exist - i.e. use `SHOW CREATE DICTIONARY` as an existence oracle for tables they are not allowed to see. The earlier hint work only closed the typo-based leak; this closes the exact-name probe too. `InterpreterShowCreateQuery` now, before fetching the create query, checks - only for a user who can neither `SHOW TABLES` nor `SHOW COLUMNS` on the object - whether the name really is a dictionary. If it is not (a hidden table or a missing name), both are reported identically as a missing dictionary (`UNKNOWN_TABLE`, `There is no dictionary ...`), carrying the same `Maybe you meant ...?` hint, which only ever suggests dictionaries to such a user. Users who can also observe the object as a table keep the precise `is not a DICTIONARY` diagnostic. This mirrors `InterpreterExistsQuery`, where `EXISTS DICTIONARY` on a regular table reports non-existence for such a user. Extends `04546_show_create_dictionary_hint_rbac` with the exact-name regression: the dictionary-only user's error for a real table is indistinguishable from a missing name and never says `is not a DICTIONARY`, while a full-access user still gets that precise diagnostic. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The exact-name gate in `InterpreterShowCreateQuery` decided whether to synthesize `There is no dictionary ...` via `DatabaseCatalog::isDictionaryExist`, which calls `tryGetTable` - on Ordinary/Atomic databases that waits for the probed table to start up and rethrows load failures. A user with only `SHOW DICTIONARIES` probing a hidden table that is still starting up or fails to load would get the load error instead of the synthetic missing-dictionary error, making the hidden table distinguishable from a missing name again. Probe under a local try/catch and treat any failure as "not a dictionary", same fail-closed treatment as `TableNameHints::isHintNameVisible`.
The previous fix probed `DatabaseCatalog::isDictionaryExist` before fetching the create query, so a dictionary-only user could reach `... is not a DICTIONARY` for a hidden regular table if the object was dropped and recreated as a table between the probe and `getCreateTableQuery` - reopening the existence oracle via TOCTOU. `InterpreterShowCreateQuery` now fetches and validates the *same* create query in a single lookup for a user who can neither `SHOW TABLES` nor `SHOW COLUMNS` the object: there is no separate existence probe and thus no window in which the object could change kind. If the fetched object is not a dictionary - a hidden table, a name that vanished, or one that fails to load - it is reported identically to a missing dictionary, with the same "Maybe you meant ...?" hint. Users who can also observe the object as a table keep the precise `... is not a DICTIONARY` diagnostic, which a dictionary-only user can now never reach. This mirrors `InterpreterExistsQuery`, which likewise answers a dictionary-only user from a single observation instead of a second visibility-changing lookup. The `04546_show_create_dictionary_hint_rbac` test gains the TOCTOU settled end-state: a dictionary replaced by a regular table under the same name is still reported to a dictionary-only user as a missing dictionary, never as `... is not a DICTIONARY`. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
… hidden-table match The AI review flagged that `TableNameHints::getHintForTable` jumped straight to `getExtendedHintForTable` (cross-database search) as soon as the closest raw candidate was an exact match for the probed name. On the remasked `SHOW CREATE DICTIONARY` path a `SHOW DICTIONARIES`-only user probing a hidden regular table `db.foo` exactly, while the same database also holds a visible dictionary `db.foos` (one edit away), then got the bare `There is no dictionary db.foo` error instead of the available same-database `Maybe you meant db.foos?` hint - so the exact-name path did not preserve the same hint behavior as an ordinary missing dictionary. Skip only the exact candidate itself and keep scanning the remaining local candidates for the closest *visible* one before falling back to cross-database search. The empty-results case still falls through to the extended search. The exact-match skip previously also covered a transiently unretrievable name (a table not yet loaded at startup, or a stale-UUID lookup); that behavior is kept, it just no longer abandons the rest of the local candidates. Extends `04546_show_create_dictionary_hint_rbac` with a regression for an exact hidden-table probe (`mask_target`) against a similarly named visible dictionary (`mask_targets`) in the same database: the dictionary-only user is now pointed at `mask_targets`, the hidden table's own name never leaks, and the probe stays reported as a missing dictionary rather than `... is not a DICTIONARY`. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ntract The AI review noted that the new "Maybe you meant ...?" hint is unreachable under object-level `SHOW` grants: `InterpreterShowCreateQuery` checks access on the requested identifier before any lookup, so `GRANT SHOW DICTIONARIES ON db.dict_target` + `SHOW CREATE DICTIONARY db.dict_targe` (and the analogous `SHOW COLUMNS` case for `SHOW CREATE TABLE`/`VIEW`) is denied with `ACCESS_DENIED` and never reaches the hint path. This is deliberate rather than a defect. Unlike `SELECT`, whose analyzer resolves the name before its access check - and so surfaces a hint and, for an existing but hidden object, tells it apart from a missing name even under an object-level grant - `SHOW CREATE` must not become an existence oracle. Checking access on the requested name first means an existing but hidden object and a missing name are both reported as `ACCESS_DENIED`, indistinguishable to a user not granted on that name. Verified locally: `SHOW CREATE TABLE db.secret` (hidden, exists) and `SHOW CREATE TABLE db.secre` (missing) both return `ACCESS_DENIED`, whereas `SELECT` returns `ACCESS_DENIED` vs `UNKNOWN_TABLE`. Per the review's "narrow the contract explicitly and cover that restriction in tests" option, this documents the contract at the access check in `InterpreterShowCreateQuery.cpp` and adds `04611_show_create_hint_object_level_grant`, covering the DICTIONARY (`SHOW DICTIONARIES`) and TABLE/VIEW (`SHOW COLUMNS`) surfaces, the oracle-safety property, and a broad-grant contrast that keeps the hint. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…RY instead of masking them For a user authorized with only `SHOW DICTIONARIES`, the exact-name path in `InterpreterShowCreateQuery` fetched the create query under a `catch (...)` that treated *every* failure as "not a dictionary" and remasked it to `There is no dictionary ...`. That was too broad: `DatabaseOnDisk::getCreateTableQueryImpl` calls `tryGetTable` first, and `DatabaseWithOwnTablesBase::tryGetTable` waits on the startup task and rethrows load failures. So an exact `SHOW CREATE DICTIONARY db.dict` against a real dictionary that fails to load or start up would falsely report that the dictionary does not exist - regressing diagnostics for an authorized user and diverging from `EXISTS DICTIONARY`, which surfaces the load failure. Narrow the remask to *missing* names only: keep reporting a missing dictionary (with the "Maybe you meant ...?" hint) when the fetch fails with `UNKNOWN_TABLE`, `CANNOT_GET_CREATE_TABLE_QUERY`, or `CANNOT_GET_CREATE_DICTIONARY_QUERY` - the same set the `IDatabase::getCreateTableQuery` wrapper uses to detect an absent object - so a hidden regular table and a name that does not exist stay indistinguishable to this user (the existence-oracle protection is preserved). Any other failure - most notably a genuine load/startup failure of an object that really exists - is preserved and surfaced, matching `EXISTS DICTIONARY`. This also replaces the broad `catch (...)` with a typed `catch (const Exception &)` that rethrows the non-missing case. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…lure The exact-name protection for `SHOW CREATE DICTIONARY` keyed the remask on `getCreateTableQuery`'s error code, remasking only the three "missing name" codes and re-throwing anything else. But `getCreateTableQuery` calls `tryGetTable` first, which rethrows a hidden regular table's own load/startup failure (or a parse failure on corrupted metadata). So a user holding only `SHOW DICTIONARIES`, probing a hidden regular table that was still starting up, had corrupted metadata, or otherwise threw a non-"missing" error, got that distinguishing exception instead of the synthetic `There is no dictionary ...` - reopening the existence oracle this path is meant to close. Make the dictionary-only path fully fail-closed: the object is shown only when the single `getCreateTableQuery` fetch positively proves it to be a dictionary. Any other outcome - a hidden regular table, a name that does not exist, or *any* failure of the fetch - is reported identically as a missing dictionary with the same "Maybe you meant ...?" hint. The decision no longer depends on the error code, so a hidden table's load/startup/metadata failure can no longer leak its existence. The swallowed error is not lost: it resurfaces when a user who is allowed to see the object really accesses it. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 89/95 (93.68%) · Uncovered code |
alexey-milovidov
left a comment
There was a problem hiding this comment.
It was funny to read, but okay.
…ning out of stderr The test creates a database with the deprecated `Ordinary` engine, and the server emits the "Server has databases (for example ...) with Ordinary engine, which was deprecated" warning once per server lifetime, synchronously within the first such `CREATE DATABASE` query. Shell tests run `clickhouse-client` with `--send_logs_level=warning`, so whenever this test happened to be the first one to create an `Ordinary` database (always the case in the flaky check, sometimes in parallel runs), the warning was forwarded to the client and failed the test with "having stderror". Pass `--send_logs_level=fatal` for that single statement, like other tests creating `Ordinary` databases do (e.g. `04340_timeseries_rename_digest_mismatch`). Failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110633&sha=4b1e0730977f25a9a7dab1e9a293fc65f2855c24&name_0=PR&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20flaky%20check%29 PR: ClickHouse#110633 Co-Authored-By: Claude Fable 5 <[email protected]>
`SHOW CREATE DICTIONARY` is authorized with the `SHOW_DICTIONARIES` grant, which does not imply `SHOW_TABLES`, but `TableNameHints` filtered hint candidates with `SHOW_TABLES` only - so a user with dictionary-only visibility still got the bare error without the "Maybe you meant ...?" hint. Keep a candidate name visible when the user has `SHOW_DICTIONARIES` on it and the object really is a dictionary: the grant by itself does not tell tables and dictionaries apart, so the extra check is needed to avoid leaking the names of tables to a user with only a dictionary-level grant. Add an RBAC regression test covering both sides: the dictionary-only user gets the hint for a similarly-named dictionary, and gets no hint (no name leak) for a typo close to a table's name. PR: ClickHouse#110633 Co-Authored-By: Claude Fable 5 <[email protected]>
…e-hints Add "Maybe you meant ...?" hint to SHOW CREATE for a missing table
When
SHOW CREATE TABLE(alsoSHOW CREATE VIEW/SHOW CREATE DICTIONARY) refers to a table that does not exist, the error was thrown without the "Maybe you meant ...?" suggestion thatSELECTqueries already produce for a similarly-named table. For example, a typo or a wrong/omitted database produced:with no hint, even when a table with a close name exists in this or another database.
The hint is now added in the common
IDatabase::getCreateTableQuerywrapper, so it applies to every database engine (the variousgetCreateTableQueryImploverrides report a missing table withUNKNOWN_TABLE,CANNOT_GET_CREATE_TABLE_QUERY, orCANNOT_GET_CREATE_DICTIONARY_QUERY). The suggestion is computed aftergetCreateTableQueryImplreturns — i.e. outside any database lock it may hold, to avoid a deadlock — and only when the table is really absent, reusing the sameTableNameHintsmachinery asSELECT:The hint also respects the access model of
SHOW CREATE DICTIONARY, which is authorized with theSHOW DICTIONARIESgrant (it does not implySHOW TABLES):TableNameHintsnow keeps a candidate name visible to a user holding onlySHOW DICTIONARIESwhen the object really is a dictionary, so such a user gets the hint for a similarly-named dictionary while the names of tables remain invisible to them.The same access model is enforced for an exact name too, not just for typo hints. Previously a user holding only
SHOW DICTIONARIEScould runSHOW CREATE DICTIONARY db.some_tableon a hidden regular table and get... is not a DICTIONARY, which confirmed that a table with that name exists — turningSHOW CREATE DICTIONARYinto an existence oracle for tables the user is not allowed to see. For a user who can neitherSHOW TABLESnorSHOW COLUMNSon the object,InterpreterShowCreateQuerynow fetches and validates the same create query in a single lookup — there is no separate existence probe and hence no window in which the object could be dropped and recreated as a different kind — and reports a hidden regular table or a name that does not exist identically as a missing name (There is no dictionary ...), so these are indistinguishable to such a user and... is not a DICTIONARYis unreachable for them. For such a user this path is fully fail-closed: the object is shown only when that single fetch positively proves it to be a dictionary; any other outcome — a hidden regular table, a name that does not exist, or any failure of the fetch itself (for example a hidden table that is still starting up, has corrupted metadata, or otherwise throws) — is reported identically as a missing dictionary. The decision does not depend on the error code, becausegetCreateTableQuerycallstryGetTablefirst and a hidden table's own load or startup failure would otherwise escape and distinguish it from a missing name. The swallowed error is not lost: it resurfaces when a user who is allowed to see the object really accesses it. Users who can also observe the object as a table keep the preciseis not a DICTIONARYdiagnostic. This mirrorsInterpreterExistsQuery, which likewise answers a dictionary-only user from a single observation instead of a second visibility-changing lookup.The suggestion follows this same access model. Access is checked on the requested identifier before any lookup, so the hint appears when the user's grant covers the requested name — a broad
db.*/*.*grant, or the exact name itself. With an object-levelSHOWgrant scoped to a single name — e.g.GRANT SHOW DICTIONARIES ON db.dict_targetorGRANT SHOW COLUMNS ON db.tbl_target— a misspelled name is not covered, so it is denied withACCESS_DENIEDand no hint is produced. This is deliberate and narrower thanSELECT:SELECTresolves the name during analysis, before its access check, so it surfaces a hint and, for an existing but hidden object, distinguishes it from a missing name even under object-level grants.SHOW CREATEintentionally does not — checking access on the requested name first keeps it from becoming an existence oracle, so an existing but hidden object and a missing name are both reported asACCESS_DENIEDand stay indistinguishable to a user who is not granted on that name.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
SHOW CREATE TABLE(andSHOW CREATE VIEW/SHOW CREATE DICTIONARY) now suggests a similarly-named table in the error message when the requested table does not exist, the same waySELECTqueries do.Documentation entry for user-facing changes