mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-20 08:40:50 +00:00
Support toUInt8/toInt8 for if constant condition optimization.
This commit is contained in:
parent
b68f0df8b4
commit
185c20cf88
@ -49,6 +49,16 @@ static bool tryExtractConstValueFromCondition(const ASTPtr & condition, bool & v
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (function->name == "toUInt8" || function->name == "toInt8")
|
||||
{
|
||||
if (const auto * expr_list = function->arguments->as<ASTExpressionList>())
|
||||
{
|
||||
if (expr_list->children.size() != 1)
|
||||
throw Exception(ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH, "Function {} must have exactly two arguments", function->name);
|
||||
|
||||
return tryExtractConstValueFromCondition(expr_list->children.at(0), value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -0,0 +1,8 @@
|
||||
42
|
||||
42
|
||||
42
|
||||
42
|
||||
42
|
||||
42
|
||||
42
|
||||
42
|
@ -0,0 +1,14 @@
|
||||
drop table if exists test;
|
||||
-- this queries does not have to pass, but they works historically
|
||||
-- let's support this while can, see #31687
|
||||
create table test (x String) Engine=StripeLog;
|
||||
insert into test values (0);
|
||||
select if(0, y, 42) from test;
|
||||
select if(1, 42, y) from test;
|
||||
select if(toUInt8(0), y, 42) from test;
|
||||
select if(toInt8(0), y, 42) from test;
|
||||
select if(toUInt8(1), 42, y) from test;
|
||||
select if(toInt8(1), 42, y) from test;
|
||||
select if(toUInt8(toUInt8(0)), y, 42) from test;
|
||||
select if(cast(cast(0, 'UInt8'), 'UInt8'), y, 42) from test;
|
||||
drop table if exists t;
|
Loading…
Reference in New Issue
Block a user