mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-25 17:12:03 +00:00
Merge pull request #18446 from azat/constant-folding
Fix constant folding when the result is unknown
This commit is contained in:
commit
8b9105bf39
@ -1468,7 +1468,7 @@ Code: 395. DB::Exception: Received from localhost:9000. DB::Exception: Too many.
|
|||||||
|
|
||||||
## identity {#identity}
|
## identity {#identity}
|
||||||
|
|
||||||
Returns the same value that was used as its argument. Used for debugging and testing, allows to cancel using index, and get the query performance of a full scan. When query is analyzed for possible use of index, the analyzer doesn’t look inside `identity` functions.
|
Returns the same value that was used as its argument. Used for debugging and testing, allows to cancel using index, and get the query performance of a full scan. When query is analyzed for possible use of index, the analyzer doesn’t look inside `identity` functions. Also constant folding is not applied too.
|
||||||
|
|
||||||
**Syntax**
|
**Syntax**
|
||||||
|
|
||||||
|
@ -16,15 +16,9 @@ public:
|
|||||||
return std::make_shared<FunctionIdentity>();
|
return std::make_shared<FunctionIdentity>();
|
||||||
}
|
}
|
||||||
|
|
||||||
String getName() const override
|
String getName() const override { return name; }
|
||||||
{
|
size_t getNumberOfArguments() const override { return 1; }
|
||||||
return name;
|
bool isSuitableForConstantFolding() const override { return false; }
|
||||||
}
|
|
||||||
|
|
||||||
size_t getNumberOfArguments() const override
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override
|
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override
|
||||||
{
|
{
|
||||||
|
@ -168,6 +168,16 @@ void ExecuteScalarSubqueriesMatcher::visit(const ASTSubquery & subquery, ASTPtr
|
|||||||
lit->alias = subquery.alias;
|
lit->alias = subquery.alias;
|
||||||
lit->prefer_alias_to_column_name = subquery.prefer_alias_to_column_name;
|
lit->prefer_alias_to_column_name = subquery.prefer_alias_to_column_name;
|
||||||
ast = addTypeConversionToAST(std::move(lit), scalar.safeGetByPosition(0).type->getName());
|
ast = addTypeConversionToAST(std::move(lit), scalar.safeGetByPosition(0).type->getName());
|
||||||
|
|
||||||
|
/// If only analyze was requested the expression is not suitable for constant folding, disable it.
|
||||||
|
if (data.only_analyze)
|
||||||
|
{
|
||||||
|
ast->as<ASTFunction>()->alias.clear();
|
||||||
|
auto func = makeASTFunction("identity", std::move(ast));
|
||||||
|
func->alias = subquery.alias;
|
||||||
|
func->prefer_alias_to_column_name = subquery.prefer_alias_to_column_name;
|
||||||
|
ast = std::move(func);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -114,8 +114,9 @@ FROM
|
|||||||
(
|
(
|
||||||
SELECT
|
SELECT
|
||||||
1 AS id,
|
1 AS id,
|
||||||
cast(1, \'UInt8\') AS subquery
|
identity(cast(1, \'UInt8\')) AS subquery
|
||||||
)
|
)
|
||||||
|
WHERE subquery = 1
|
||||||
1 1
|
1 1
|
||||||
SELECT
|
SELECT
|
||||||
a,
|
a,
|
||||||
|
@ -1,4 +1,9 @@
|
|||||||
|
DROP TABLE IF EXISTS dest_table_mv;
|
||||||
|
DROP TABLE IF EXISTS left_table;
|
||||||
|
DROP TABLE IF EXISTS right_table;
|
||||||
|
DROP TABLE IF EXISTS dest_table;
|
||||||
DROP TABLE IF EXISTS src_table;
|
DROP TABLE IF EXISTS src_table;
|
||||||
|
DROP VIEW IF EXISTS dst_mv;
|
||||||
|
|
||||||
create table src_table Engine=Memory as system.numbers;
|
create table src_table Engine=Memory as system.numbers;
|
||||||
CREATE MATERIALIZED VIEW dst_mv Engine=Memory as select *, (SELECT count() FROM src_table) AS cnt FROM src_table;
|
CREATE MATERIALIZED VIEW dst_mv Engine=Memory as select *, (SELECT count() FROM src_table) AS cnt FROM src_table;
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
-- { echo }
|
||||||
|
SELECT * FROM (SELECT (SELECT * FROM system.numbers LIMIT 1 OFFSET 1) AS n, toUInt64(10 / n)) FORMAT CSV;
|
||||||
|
1,10
|
||||||
|
SELECT (SELECT * FROM system.numbers LIMIT 1 OFFSET 1) AS n, toUInt64(10 / n) FORMAT CSV;
|
||||||
|
1,10
|
||||||
|
EXPLAIN SYNTAX SELECT (SELECT * FROM system.numbers LIMIT 1 OFFSET 1) AS n, toUInt64(10 / n);
|
||||||
|
SELECT
|
||||||
|
identity(cast(0, \'UInt64\')) AS n,
|
||||||
|
toUInt64(10 / n)
|
@ -0,0 +1,4 @@
|
|||||||
|
-- { echo }
|
||||||
|
SELECT * FROM (SELECT (SELECT * FROM system.numbers LIMIT 1 OFFSET 1) AS n, toUInt64(10 / n)) FORMAT CSV;
|
||||||
|
SELECT (SELECT * FROM system.numbers LIMIT 1 OFFSET 1) AS n, toUInt64(10 / n) FORMAT CSV;
|
||||||
|
EXPLAIN SYNTAX SELECT (SELECT * FROM system.numbers LIMIT 1 OFFSET 1) AS n, toUInt64(10 / n);
|
Loading…
Reference in New Issue
Block a user