Repository navigation
Name the real cause in CREATE TABLE validation errors - #116871
Conversation
Two findings from applying the error-message survey to DDL: the `CREATE
TABLE` statements of ClickBench, TPC-H, TPC-DS and the Join Order
Benchmark, damaged the same way as the queries were, 2280 statements.
A `DEFAULT` expression that does not resolve reported a name that appears
nowhere in the query:
CREATE TABLE t (a UInt32, b UInt32 DEFAULT nosuch) ENGINE = MergeTree ORDER BY a
Unknown expression or function identifier `b_tmp_alter15627740530694008313`
in scope SELECT _CAST(b_tmp_alter15627740530694008313, 'UInt32') AS b,
nosuch AS b_tmp_alter15627740530694008313 FROM dummy.dummy.
Maybe you meant: ['b_tmp_alter15627740530694008313']
Validation builds two expressions for a column that has both a type and a
default: the default expression under a synthetic alias, and a conversion
of that alias to the declared type. The conversion refers to the alias, so
any failure inside the default expression surfaces as a failure to resolve
the alias - and the typo hint then suggests the very name it has just
called unknown. Give the conversion its own copy of the default
expression instead. The two expressions are only analysed, never executed,
so the copy costs nothing, and the error now names what the user wrote:
Unknown expression or function identifier `nosuch` ...
A typo of a real column also gets a usable hint now (`DEFAULT aaab` with a
column `aaaa` suggests `aaaa` instead of the synthetic name).
A key that cannot be used did not say which part of it was the problem:
Sorting key contains nullable columns, but merge tree setting
`allow_nullable_key` is disabled
Sorting key cannot contain constants
The check walks the key expression's sample block, so the element is right
there:
Sorting key contains nullable column `b` of type Nullable(String), but
merge tree setting `allow_nullable_key` is disabled
Sorting key cannot contain constants, but `1` is one
This matters for a long key or an expression key, where the message is the
only thing the user has to go on. The deterministic-expression check next
to it already names the offending part (`non-deterministic part `rand()``),
so this follows it.
|
Workflow [PR], commit [7c17215] Summary: ✅
AI ReviewSummaryThis PR fixes the synthetic Tests
Final Verdict
LLVM Coverage ReportMeasured on commit 7c17215.
Changed lines: Changed C/C++ lines covered: 28/28 (100.00%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units9 translation units recompiled, 57 s compile time in total, 9 of them have a recent master baseline. |
`AlterCommands::validate` builds the same pair of expressions as
`getDefaultExpressionInfoInto` does for `CREATE`, at two more places, and
had the same problem: the type conversion referred to the synthetic alias,
so
ALTER TABLE t ADD COLUMN z UInt32 DEFAULT nosuch
ALTER TABLE t MODIFY COLUMN s DEFAULT nosuch
reported `Unknown expression or function identifier
'z_tmp_alter9544450424068748861'` and offered that name as the hint for
itself. Give the conversion its own copy of the expression here too. The
second place re-checks the existing default of a column whose type is
being changed, and needs the same treatment.
Found by damaging the `ALTER` statements of the same corpus after the
`CREATE` path was fixed.
`_cleanup_database` in `clickhouse-test` asks tests numbered from 02800 on to leave no tables behind.
…e-validation-messages
The merge of master pulled in `05050_totime_legacy_update_on_cluster`, so the test moves to the next free number.
…e-validation-messages
|
🕵 Both reds on 7feb37e are unrelated to this PR (it only changes DDL validation messages), and neither has a fix on
@groeneai, investigate the second failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=116871&sha=7feb37e6bc2b10bf725385c2f042fcb67b34c3e2&name_0=PR&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20db%20disk%2C%20old%20analyzer%2C%206%2F6%29 and provide a fix in a separate PR. If the fix is already in progress, link it here. |
|
A fix is in progress in two parts, and one part is already on master, so for the second red the base merge you just pushed should clear it. #117412 (yours, merged 2026-09-01T11:31:33Z). The What killed #117564 (mine, open) covers the residual, which this job shows. #117412 did not remove all of the pressure: the job level |
…e-validation-messages
|
🕵 Thanks for the analysis, @groeneai. Merged The four reds on 73b5d89 were all outside this PR's scope (it only changes the text of
Re-verified |
|
🕵 It is the test that has to move, not the code. Case 10 of it pinned the alias collision this PR removes: ALTER TABLE t_mod_def MODIFY COLUMN c UInt64 CODEC(T64, LZ4),
MODIFY COLUMN c UInt64 COMMENT 'z'; -- { serverError MULTIPLE_EXPRESSIONS_FOR_ALIAS }Each type-carrying subcommand appends one I built
So the collision now fires only where the subcommands actually conflict, and case 10 should assert the outcome instead. This is the diff I verified, and it belongs in this PR, since on 61124de it fails (the ALTER is still rejected there): --- a/tests/queries/0_stateless/04904_alter_two_modify_column_same_column_default.sql
+++ b/tests/queries/0_stateless/04904_alter_two_modify_column_same_column_default.sql
@@ -153,11 +153,16 @@ ALTER TABLE t_mod_def MODIFY COLUMN c REMOVE MATERIALIZED;
ALTER TABLE t_mod_def MODIFY COLUMN c UInt32; -- { serverError BAD_ARGUMENTS }
DROP TABLE t_mod_def;
--- 10. Two type-carrying subcommands over a pre-existing default keep colliding as before.
+-- 10. Two type-carrying subcommands over a pre-existing default compose, and reach the same
+-- outcome as the two statements written separately.
CREATE TABLE t_mod_def (event String, c UInt32 MATERIALIZED JSONExtractUInt(event, 'x'))
ENGINE = MergeTree() ORDER BY tuple();
ALTER TABLE t_mod_def MODIFY COLUMN c UInt64 CODEC(T64, LZ4),
- MODIFY COLUMN c UInt64 COMMENT 'z'; -- { serverError MULTIPLE_EXPRESSIONS_FOR_ALIAS }
+ MODIFY COLUMN c UInt64 COMMENT 'z';
+SELECT '10', type, default_kind, default_expression, comment, compression_codec FROM system.columns
+ WHERE database = currentDatabase() AND table = 't_mod_def' AND name = 'c';
+INSERT INTO t_mod_def (event) VALUES ('{"x":42}');
+SELECT '10', c FROM t_mod_def;
DROP TABLE t_mod_def;
-- 11. An existing default that cannot be read as the new type is still rejected, with or without a
--- a/tests/queries/0_stateless/04904_alter_two_modify_column_same_column_default.reference
+++ b/tests/queries/0_stateless/04904_alter_two_modify_column_same_column_default.reference
@@ -21,5 +21,7 @@
8set UInt64 MATERIALIZED JSONExtractUInt(event, \'x\')
8remove UInt64
8remove 7
+10 UInt64 MATERIALIZED JSONExtractUInt(event, \'x\') z CODEC(T64, LZ4)
+10 42
11 Int8
12 MATERIALIZED k + 1Against |
…e-validation-messages
…cal `_CAST` expressions Case 10 pinned `MULTIPLE_EXPRESSIONS_FOR_ALIAS` for `MODIFY COLUMN c UInt64 CODEC(...), MODIFY COLUMN c UInt64 COMMENT 'z'` over a pre-existing `MATERIALIZED` default. That error came from the two subcommands producing `_CAST(c_tmp_alter<A>, 'UInt64') AS c` and `_CAST(c_tmp_alter<B>, 'UInt64') AS c`. With this PR the default expression is cloned into the `_CAST`, so both expressions are identical and may share the alias; the ALTER now composes like the two statements written separately. Genuinely conflicting defaults (`DEFAULT 1` vs `DEFAULT 2`) are still rejected. Assert the outcome instead. Analysis and diff by @groeneai: #116871 (comment) CI: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=116871&sha=face0f565163ce1f2ba1e002b62f5e73e1df6f0f&name_0=PR&name_1=Fast%20test PR: #116871 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
🕵 Thanks, @groeneai — adopted your case-10 change to |
`ALTER TABLE at2 MODIFY COLUMN b Date` succeeds, so it did not cover the
second branch in `AlterCommands::validate` that re-checks an existing default
against a new type. Add a case whose stored default cannot be converted to the
new type: the error scope now shows `_CAST('abc', 'UInt32')`, and would show
the synthetic `b_tmp_alter<random>` alias if that branch regressed.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 The only red on c88e306 is Merged @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=116871&sha=c88e306f7a1822717476cccc8dd22e728ebe1361&name_0=PR&name_1=Performance%20Comparison%20%28arm_release%2C%20master_head%2C%206%2F6%29 (unstable |
| run "CREATE TABLE t (a UInt32, b Nullable(String), c UInt32) ENGINE = MergeTree ORDER BY (a, b, c)" | ||
| run "CREATE TABLE t (a UInt32, b Nullable(UInt32)) ENGINE = MergeTree PARTITION BY b ORDER BY a" | ||
| run "CREATE TABLE t (a UInt32, b UInt32) ENGINE = MergeTree ORDER BY (a, 1, b)" |
There was a problem hiding this comment.
The new key-diagnostic coverage only exercises ORDER BY and PARTITION BY, but the PR description/changelog also claim the explicit PRIMARY KEY case. MergeTreeData::checkProperties still only calls checkKeyExpression for new_sorting_key and new_partition_key, never new_primary_key, so ENGINE = MergeTree PRIMARY KEY b ORDER BY (b, a) is still unproven here and will route through the Sorting key ... wording. Please add a focused explicit-PRIMARY KEY regression (or narrow the claim if that wording is intentional).
|
Investigated: same cause as In this run the PR server was slower on all 8 queries (+13-17%, 7 of 7 samples each) and stayed slow through both confirmation restarts. The reference server was slow only after the first restart, so No fixing PR exists yet: it waits on the choice asked there, dropping PIE for |
…olumn-matcher Conflict in `04904_alter_two_modify_column_same_column_default`: master (ClickHouse#116871) made case 10 compose and extended it with an `INSERT`; this PR also makes it compose and additionally lets the combined form of case 11 succeed. Kept the PR's version of the test and adopted master's extended case 10. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #116806
Related: #116809
Related: #116812
Related: #116815
Related: #116817
The survey of error messages for mistakes in SQL queries so far only damaged queries. This applies the same method to DDL — the
CREATE TABLEstatements of ClickBench, TPC-H, TPC-DS and the Join Order Benchmark plus a set of MergeTree features the benchmark schemas do not use (codecs, TTL, projections, skip indices, materialized and aliased columns, dictionaries,ALTER), damaged the same way: 2280 statements, 2013 errors.DDL messages hold up well — type, engine, codec and index-type typos all get a hint, the primary-key prefix check names the position, precision bounds name the value. Two things did not.
A
DEFAULTexpression that does not resolve reported a name that appears nowhere in the query.Validation builds two expressions for a column that has both a declared type and a default: the default expression under a synthetic alias, and a conversion of that alias to the declared type. Because the conversion refers to the alias, any failure inside the default expression surfaces as a failure to resolve that alias — and the typo hint then helpfully suggests the very name it has just called unknown. Giving the conversion its own copy of the default expression fixes it; the two expressions are only analysed, never executed, so the copy costs nothing:
A typo of a real column now gets a usable hint too —
DEFAULT aaabin a table with a columnaaaasuggestsaaaainstead of the synthetic name. A column declared without a type took a different path and was already reported correctly, which is why this went unnoticed.A key that cannot be used did not say which part of it was the problem.
The check walks the key expression's sample block, so the offending element is right there:
Partition keyandPrimary keyget the same treatment, since they share the check. This matters for a long key or an expression key, where the message is all the user has to go on. The deterministic-expression check right next to it already names the offending part (non-deterministic partrand()``), so this just follows it.The 118 stateless tests that mention
allow_nullable_key,THERE_IS_NO_DEFAULT_VALUEordefault expression and column typewere run; the 5 failures are unrelated environment ones (nosystem.query_log, notest_shard_localhostcluster, no ZooKeeper in the local setup). The new test is taggedno-old-analyzerbecause withenable_analyzer = 0theDEFAULTfailure is worded differently (Missing columns: 'nosuch'— which the change fixes there too, just with different text).Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
An unresolved name in a column
DEFAULT,MATERIALIZEDorALIASexpression is now reported by the name the user wrote, instead of an internal<column>_tmp_alter<random>alias that appears nowhere in the query (which also broke the "Maybe you meant" hint). A sorting, primary or partition key that contains a nullable column or a constant now names that column or constant.Workflow [PR]
Sync PR [sync-upstream/pr/116871]
Version info
26.10.1.1516-master(included in26.10and later)