Repository navigation
Forbid to create not insertable tables - #81835
Conversation
| } | ||
|
|
||
| if (res.getAllPhysical().empty()) | ||
| if (!hasPhysicalColumns) |
There was a problem hiding this comment.
We should be able to attach them or execute secondary create.
There was a problem hiding this comment.
Added check and test
| if (!hasPhysicalColumns) | ||
| throw Exception(ErrorCodes::EMPTY_LIST_OF_COLUMNS_PASSED, "Cannot CREATE table without physical columns"); | ||
|
|
||
| if (mode <= LoadingStrictnessLevel::SECONDARY_CREATE && !is_restore_from_backup && !hasInsertableColumns) |
There was a problem hiding this comment.
| if (mode <= LoadingStrictnessLevel::SECONDARY_CREATE && !is_restore_from_backup && !hasInsertableColumns) | |
| if (mode <= LoadingStrictnessLevel::CREATE && !is_restore_from_backup && !hasInsertableColumns) |
I assume we still want to be able to execute a secondary create?
There was a problem hiding this comment.
Now that we allow secondary create of such tables, the change should not be backwards incompatible, correct? If so, I suggest we remove the pr-backwards-incompatible tag.
There was a problem hiding this comment.
@mstetsyuk
I have forgotten why I chose SECONDARY_CREATE here. It applied during alter table calls, so in such a case it is still possible to create table by deleting all insertable columns.
So I think it's better to revert this to CREATE, restores are handled, a replicated database would check it with CREATE, so all SECONDARY_CREATE on replicas should satisfy the condition.
9b5a1cd to
134650a
Compare
| if (res.getAllPhysical().empty()) | ||
| throw Exception(ErrorCodes::EMPTY_LIST_OF_COLUMNS_PASSED, "Cannot CREATE table without physical columns"); | ||
|
|
||
| if (mode <= LoadingStrictnessLevel::SECONDARY_CREATE && !is_restore_from_backup && res.getInsertable().empty()) |
There was a problem hiding this comment.
This would still break adding new replicas to the cluster (which would break releases and horizontal scaling), right?
There was a problem hiding this comment.
Yes, I forgot to change it back, fixed
| @@ -0,0 +1,12 @@ | |||
| -- Tags: no-parallel, no-ordinary-database | |||
| -- Tag no-parallel: static UUID | |||
There was a problem hiding this comment.
You can use no-flaky-check instead. The test itself is parallel with any other test, just not with itself.
|
This was a feature, not a bug. Although it may look like “having a non-insertable table,” that’s not actually the case. You could create a table, insert some data, and then make it non-insertable—which has its own use cases and valid reasons, the first being freedom to use features as needed. This change feels unnecessary from a technical perspective, unintuitive for users, and reduces the overall completeness of the system. Who would expect to create a table with only materialized columns and then be able to insert data into it? It made sense to allow creating the table—why not let people use it the way they want? Practical use cases:
Technical arguments:
Previously, it was possible to create a table, insert some data, and then modify a column to be materialized in order to lock down any further write operations until explicitly altering the columns again: CREATE TABLE t0 ENGINE = Memory() AS SELECT materialize(123)::int AS x;
ALTER TABLE t0 MODIFY COLUMN x MATERIALIZED 0;
SELECT x FROM t0;Now, this is no longer possible. Also, the error message is somewhat misleading: |
ClickHouse PR ClickHouse/ClickHouse#81835 added a check that forbids creating tables without insertable columns (e.g., tables with only MATERIALIZED or ALIAS columns). Since SQLancer's random table generator can produce such definitions, ClickHouse now returns EMPTY_LIST_OF_COLUMNS_PASSED, which should be treated as an expected error rather than causing an AssertionError. The table creation retry loop in ClickHouseProvider.generateDatabase already handles expected errors by regenerating the table definition.
SQLancer was disabled after #81835 which forbids creating tables without insertable columns (e.g., with only `MATERIALIZED` or `ALIAS` columns). SQLancer's random table generator could produce such definitions, causing an `AssertionError`. The fix adds `EMPTY_LIST_OF_COLUMNS_PASSED` to SQLancer's expected errors. The table creation retry loop in `ClickHouseProvider.generateDatabase` already handles expected errors by regenerating the table definition. The fix was submitted upstream: sqlancer/sqlancer#1296 and applied to the ClickHouse fork: https://github.com/ClickHouse/sqlancer This PR switches CI to use the ClickHouse fork (pinned to a specific commit) and re-enables the SQLancer job in the master workflow. Co-Authored-By: Claude Opus 4.6 <[email protected]>
ClickHouse PR ClickHouse/ClickHouse#81835 added a check that forbids creating tables without insertable columns (e.g., tables with only MATERIALIZED or ALIAS columns). Since SQLancer's random table generator can produce such definitions, ClickHouse now returns EMPTY_LIST_OF_COLUMNS_PASSED, which should be treated as an expected error rather than causing an AssertionError. The table creation retry loop in ClickHouseProvider.generateDatabase already handles expected errors by regenerating the table definition.

Materialized columns are physical, but data can't be inserted into such tables without a Default or Ephemeral column.
It can break clickhouse-client in cases like the linked issue.
Closes #72139
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Forbid the creation of a table without insertable columns.