Skip to content

Commit

Permalink
Backport #57147 to 23.10: Fix segfault after ALTER UPDATE with Nullab…
Browse files Browse the repository at this point in the history
…le MATERIALIZED column
  • Loading branch information
robot-clickhouse committed Nov 28, 2023
1 parent d07ff8a commit 06323c9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Interpreters/MutationsInterpreter.cpp
Expand Up @@ -690,9 +690,15 @@ void MutationsInterpreter::prepare(bool dry_run)
{
if (column.default_desc.kind == ColumnDefaultKind::Materialized)
{
auto type_literal = std::make_shared<ASTLiteral>(column.type->getName());

auto materialized_column = makeASTFunction("_CAST",
column.default_desc.expression->clone(),
type_literal);

stages.back().column_to_updated.emplace(
column.name,
column.default_desc.expression->clone());
materialized_column);
}
}
}
Expand Down
@@ -0,0 +1,3 @@
0 0 false
1 1 true
0 0 false
@@ -0,0 +1,18 @@
DROP TABLE IF EXISTS crash_02919;

CREATE TABLE crash_02919 (
b Int64,
c Nullable(Int64) MATERIALIZED b,
d Nullable(Bool) MATERIALIZED b
)
ENGINE = MergeTree
ORDER BY tuple();

INSERT INTO crash_02919 VALUES (0);
SELECT b, c, d FROM crash_02919;
ALTER TABLE crash_02919 UPDATE b = 1 WHERE 1=1 SETTINGS mutations_sync = 1;
SELECT b, c, d FROM crash_02919;
ALTER TABLE crash_02919 UPDATE b = 0.1 WHERE 1=1 SETTINGS mutations_sync = 1;
SELECT b, c, d FROM crash_02919;

DROP TABLE crash_02919;

0 comments on commit 06323c9

Please sign in to comment.