Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
0cd49d74
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,发现更多精彩内容 >>
提交
0cd49d74
编写于
4月 09, 2020
作者:
A
Artem Zuikov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
several fixes
上级
10aad522
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
46 addition
and
19 deletion
+46
-19
src/Interpreters/DictionaryReader.h
src/Interpreters/DictionaryReader.h
+2
-0
src/Interpreters/ExpressionAnalyzer.cpp
src/Interpreters/ExpressionAnalyzer.cpp
+20
-19
src/Interpreters/TableJoin.cpp
src/Interpreters/TableJoin.cpp
+23
-0
src/Interpreters/TableJoin.h
src/Interpreters/TableJoin.h
+1
-0
未找到文件。
src/Interpreters/DictionaryReader.h
浏览文件 @
0cd49d74
...
...
@@ -41,6 +41,7 @@ public:
result
.
type
=
prepare_function
->
getReturnType
();
if
(
result
.
type
->
getTypeId
()
!=
expected_type
)
throw
Exception
(
"Type mismatch in dictionary reader for: "
+
column_name
,
ErrorCodes
::
TYPE_MISMATCH
);
block
.
insert
(
result
);
function
=
prepare_function
->
prepare
(
block
,
arg_positions
,
result_pos
);
}
...
...
@@ -113,6 +114,7 @@ public:
{
size_t
column_name_pos
=
key_size
+
i
;
auto
&
column
=
result_header
.
getByPosition
(
i
);
arguments_get
[
1
].
column
=
DataTypeString
().
createColumnConst
(
1
,
src_column_names
[
i
]);
ColumnNumbers
positions_get
{
0
,
column_name_pos
,
key_position
};
functions_get
.
emplace_back
(
FunctionWrapper
(
*
dict_get
,
arguments_get
,
sample_block
,
positions_get
,
column
.
name
,
column
.
type
->
getTypeId
()));
...
...
src/Interpreters/ExpressionAnalyzer.cpp
浏览文件 @
0cd49d74
...
...
@@ -520,18 +520,9 @@ static ExpressionActionsPtr createJoinedBlockActions(const Context & context, co
return
ExpressionAnalyzer
(
expression_list
,
syntax_result
,
context
).
getActions
(
true
,
false
);
}
static
bool
allowDictJoin
(
const
TableJoin
&
table_join
,
const
Context
&
context
,
String
&
dict
_name
)
static
bool
allowDictJoin
(
StoragePtr
joined_storage
,
const
Context
&
context
,
String
&
dict_name
,
String
&
key
_name
)
{
if
(
!
table_join
.
joined_storage
)
return
false
;
const
Names
&
right_keys
=
table_join
.
keyNamesRight
();
if
(
right_keys
.
size
()
!=
1
)
return
false
;
const
String
&
key_name
=
right_keys
[
0
];
/// TODO: compound name
auto
*
dict
=
dynamic_cast
<
const
StorageDictionary
*>
(
table_join
.
joined_storage
.
get
());
auto
*
dict
=
dynamic_cast
<
const
StorageDictionary
*>
(
joined_storage
.
get
());
if
(
!
dict
)
return
false
;
...
...
@@ -541,20 +532,30 @@ static bool allowDictJoin(const TableJoin & table_join, const Context & context,
return
false
;
const
DictionaryStructure
&
structure
=
dictionary
->
getStructure
();
return
structure
.
id
&&
(
structure
.
id
->
name
==
key_name
);
/// key is UInt64
if
(
structure
.
id
)
{
key_name
=
structure
.
id
->
name
;
return
true
;
}
return
false
;
}
static
std
::
shared_ptr
<
IJoin
>
makeJoin
(
std
::
shared_ptr
<
TableJoin
>
analyzed_join
,
const
Block
&
sample_block
,
const
Names
&
original_right_columns
,
const
Context
&
context
)
static
std
::
shared_ptr
<
IJoin
>
makeJoin
(
std
::
shared_ptr
<
TableJoin
>
analyzed_join
,
const
Block
&
sample_block
,
const
Context
&
context
)
{
bool
allow_merge_join
=
analyzed_join
->
allowMergeJoin
();
/// HashJoin with Dictionary optimisation
String
dict_name
;
if
(
allowDictJoin
(
*
analyzed_join
,
context
,
dict_name
))
String
key_name
;
if
(
analyzed_join
->
joined_storage
&&
allowDictJoin
(
analyzed_join
->
joined_storage
,
context
,
dict_name
,
key_name
))
{
analyzed_join
->
dictionary_reader
=
std
::
make_shared
<
DictionaryReader
>
(
dict_name
,
original_right_columns
,
sample_block
.
getNamesAndTypesList
(),
context
);
return
std
::
make_shared
<
HashJoin
>
(
analyzed_join
,
sample_block
);
Names
original_names
;
NamesAndTypesList
result_columns
;
if
(
analyzed_join
->
allowDictJoin
(
key_name
,
sample_block
,
original_names
,
result_columns
))
{
analyzed_join
->
dictionary_reader
=
std
::
make_shared
<
DictionaryReader
>
(
dict_name
,
original_names
,
result_columns
,
context
);
return
std
::
make_shared
<
HashJoin
>
(
analyzed_join
,
sample_block
);
}
}
if
(
analyzed_join
->
forceHashJoin
()
||
(
analyzed_join
->
preferMergeJoin
()
&&
!
allow_merge_join
))
...
...
@@ -601,7 +602,7 @@ JoinPtr SelectQueryExpressionAnalyzer::makeTableJoin(const ASTTablesInSelectQuer
/// TODO You do not need to set this up when JOIN is only needed on remote servers.
subquery_for_join
.
setJoinActions
(
joined_block_actions
);
/// changes subquery_for_join.sample_block inside
subquery_for_join
.
join
=
makeJoin
(
syntax
->
analyzed_join
,
subquery_for_join
.
sample_block
,
original_right_columns
,
context
);
subquery_for_join
.
join
=
makeJoin
(
syntax
->
analyzed_join
,
subquery_for_join
.
sample_block
,
context
);
/// Do not make subquery for join over dictionary.
if
(
syntax
->
analyzed_join
->
dictionary_reader
)
...
...
src/Interpreters/TableJoin.cpp
浏览文件 @
0cd49d74
...
...
@@ -238,4 +238,27 @@ bool TableJoin::allowMergeJoin() const
return
allow_merge_join
;
}
bool
TableJoin
::
allowDictJoin
(
const
String
&
dict_key
,
const
Block
&
sample_block
,
Names
&
names
,
NamesAndTypesList
&
result_columns
)
const
{
const
Names
&
right_keys
=
keyNamesRight
();
if
(
right_keys
.
size
()
!=
1
)
return
false
;
for
(
auto
&
col
:
sample_block
)
{
String
original
=
original_names
.
find
(
col
.
name
)
->
second
;
if
(
col
.
name
==
right_keys
[
0
])
{
if
(
original
!=
dict_key
)
return
false
;
/// JOIN key != Dictionary key
continue
;
/// do not extract key column
}
names
.
push_back
(
original
);
result_columns
.
push_back
({
col
.
name
,
col
.
type
});
}
return
true
;
}
}
src/Interpreters/TableJoin.h
浏览文件 @
0cd49d74
...
...
@@ -96,6 +96,7 @@ public:
const
SizeLimits
&
sizeLimits
()
const
{
return
size_limits
;
}
VolumePtr
getTemporaryVolume
()
{
return
tmp_volume
;
}
bool
allowMergeJoin
()
const
;
bool
allowDictJoin
(
const
String
&
dict_key
,
const
Block
&
sample_block
,
Names
&
,
NamesAndTypesList
&
)
const
;
bool
preferMergeJoin
()
const
{
return
join_algorithm
==
JoinAlgorithm
::
PREFER_PARTIAL_MERGE
;
}
bool
forceMergeJoin
()
const
{
return
join_algorithm
==
JoinAlgorithm
::
PARTIAL_MERGE
;
}
bool
forceHashJoin
()
const
{
return
join_algorithm
==
JoinAlgorithm
::
HASH
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录