Skip to content

Commit

Permalink
Backport #57147 to 23.8: Fix segfault after ALTER UPDATE with Nullabl…
Browse files Browse the repository at this point in the history
…e MATERIALIZED column
  • Loading branch information
robot-clickhouse committed Nov 28, 2023
1 parent f4fd9d5 commit 6ff082f
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
Original file line number Diff line number Diff line change
Expand Up @@ -671,9 +671,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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
0 0 false
1 1 true
0 0 false
Original file line number Diff line number Diff line change
@@ -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 6ff082f

Please sign in to comment.