Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
420f2958
C
ClickHouse
项目概览
2dot5
/
ClickHouse
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
ClickHouse
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
420f2958
编写于
2月 10, 2021
作者:
A
alesapin
提交者:
GitHub
2月 10, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #19991 from ClickHouse/constant-propagation-fix
Do not use inputs which values are known constants in ActionsDAG.
上级
85396fc8
aead46c1
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
21 addition
and
6 deletion
+21
-6
src/Interpreters/ActionsDAG.cpp
src/Interpreters/ActionsDAG.cpp
+17
-5
src/Storages/MergeTree/MergeTreeRangeReader.cpp
src/Storages/MergeTree/MergeTreeRangeReader.cpp
+1
-1
tests/queries/0_stateless/01671_merge_join_and_constants.reference
...ries/0_stateless/01671_merge_join_and_constants.reference
+1
-0
tests/queries/0_stateless/01671_merge_join_and_constants.sql
tests/queries/0_stateless/01671_merge_join_and_constants.sql
+2
-0
未找到文件。
src/Interpreters/ActionsDAG.cpp
浏览文件 @
420f2958
...
...
@@ -39,7 +39,17 @@ ActionsDAG::ActionsDAG(const ColumnsWithTypeAndName & inputs_)
for
(
const
auto
&
input
:
inputs_
)
{
if
(
input
.
column
&&
isColumnConst
(
*
input
.
column
))
{
addInput
(
input
,
true
);
/// Here we also add column.
/// It will allow to remove input which is actually constant (after projection).
/// Also, some transforms from query pipeline may randomly materialize constants,
/// without any respect to header structure. So, it is a way to drop materialized column and use
/// constant value from header.
/// We cannot remove such input right now cause inputs positions are important in some cases.
addColumn
(
input
,
true
);
}
else
addInput
(
input
.
name
,
input
.
type
,
true
);
}
...
...
@@ -116,7 +126,6 @@ ActionsDAG::Node & ActionsDAG::addAlias(Node & child, std::string alias, bool ca
node
.
result_type
=
child
.
result_type
;
node
.
result_name
=
std
::
move
(
alias
);
node
.
column
=
child
.
column
;
node
.
allow_constant_folding
=
child
.
allow_constant_folding
;
node
.
children
.
emplace_back
(
&
child
);
return
addNode
(
std
::
move
(
node
),
can_replace
);
...
...
@@ -184,7 +193,6 @@ ActionsDAG::Node & ActionsDAG::addFunction(
for
(
size_t
i
=
0
;
i
<
num_arguments
;
++
i
)
{
auto
&
child
=
*
node
.
children
[
i
];
node
.
allow_constant_folding
=
node
.
allow_constant_folding
&&
child
.
allow_constant_folding
;
ColumnWithTypeAndName
argument
;
argument
.
column
=
child
.
column
;
...
...
@@ -349,10 +357,15 @@ void ActionsDAG::removeUnusedActions()
stack
.
push
(
node
);
}
/// We cannot remove arrayJoin because it changes the number of rows.
for
(
auto
&
node
:
nodes
)
{
if
(
node
.
type
==
ActionType
::
ARRAY_JOIN
&&
visited_nodes
.
count
(
&
node
)
==
0
)
/// We cannot remove function with side effects even if it returns constant (e.g. ignore(...)).
bool
prevent_constant_folding
=
node
.
column
&&
isColumnConst
(
*
node
.
column
)
&&
!
node
.
allow_constant_folding
;
/// We cannot remove arrayJoin because it changes the number of rows.
bool
is_array_join
=
node
.
type
==
ActionType
::
ARRAY_JOIN
;
bool
must_keep_node
=
is_array_join
||
prevent_constant_folding
;
if
(
must_keep_node
&&
visited_nodes
.
count
(
&
node
)
==
0
)
{
visited_nodes
.
insert
(
&
node
);
stack
.
push
(
&
node
);
...
...
@@ -410,7 +423,6 @@ void ActionsDAG::addAliases(const NamesWithAliases & aliases, std::vector<Node *
node
.
result_type
=
child
->
result_type
;
node
.
result_name
=
std
::
move
(
item
.
second
);
node
.
column
=
child
->
column
;
node
.
allow_constant_folding
=
child
->
allow_constant_folding
;
node
.
children
.
emplace_back
(
child
);
auto
&
alias
=
addNode
(
std
::
move
(
node
),
true
);
...
...
src/Storages/MergeTree/MergeTreeRangeReader.cpp
浏览文件 @
420f2958
...
...
@@ -867,7 +867,7 @@ void MergeTreeRangeReader::executePrewhereActionsAndFilterColumns(ReadResult & r
if
(
result
.
totalRowsPerGranule
()
==
0
)
result
.
setFilterConstFalse
();
/// If we need to filter in PREWHERE
else
if
(
prewhere
->
need_filter
||
result
.
need_filter
)
else
if
(
prewhere
->
need_filter
||
result
.
need_filter
||
prewhere
->
remove_prewhere_column
)
{
/// If there is a filter and without optimized
if
(
result
.
getFilter
()
&&
last_reader_in_chain
)
...
...
tests/queries/0_stateless/01671_merge_join_and_constants.reference
浏览文件 @
420f2958
...
...
@@ -3,3 +3,4 @@
│ b │ 2018-01-01 │ B │ 2018-01-01 │ 0.10 │
│ c │ 2018-01-01 │ C │ 2018-01-01 │ 0.10 │
└───┴────────────┴───┴────────────┴───────────┘
\N \N \N \N 0 0
tests/queries/0_stateless/01671_merge_join_and_constants.sql
浏览文件 @
420f2958
...
...
@@ -11,5 +11,7 @@ set join_algorithm = 'partial_merge';
SELECT
*
FROM
table1
AS
t1
ALL
LEFT
JOIN
(
SELECT
*
,
'0.10'
,
c
,
d
AS
b
FROM
table2
)
AS
t2
USING
(
a
,
b
)
ORDER
BY
d
ASC
FORMAT
PrettyCompact
settings
max_rows_in_join
=
1
;
SELECT
pow
(
'0.0000000257'
,
NULL
),
pow
(
pow
(
NULL
,
NULL
),
NULL
)
-
NULL
,
(
val
+
NULL
)
=
(
rval
*
0
),
*
FROM
(
SELECT
(
val
+
256
)
=
(
NULL
*
NULL
),
toLowCardinality
(
toNullable
(
dummy
))
AS
val
FROM
system
.
one
)
AS
s1
ANY
LEFT
JOIN
(
SELECT
toLowCardinality
(
dummy
)
AS
rval
FROM
system
.
one
)
AS
s2
ON
(
val
+
0
)
=
(
rval
*
255
)
settings
max_rows_in_join
=
1
;
DROP
TABLE
IF
EXISTS
table1
;
DROP
TABLE
IF
EXISTS
table2
;
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录