Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
f7aedd22
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,发现更多精彩内容 >>
提交
f7aedd22
编写于
6月 03, 2013
作者:
M
Michael Kolupaev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Merge
上级
952f177e
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
34 addition
and
24 deletion
+34
-24
dbms/include/DB/Interpreters/ExpressionAnalyzer.h
dbms/include/DB/Interpreters/ExpressionAnalyzer.h
+3
-1
dbms/include/DB/Interpreters/Limits.h
dbms/include/DB/Interpreters/Limits.h
+1
-1
dbms/include/DB/Storages/MergeTree/PKCondition.h
dbms/include/DB/Storages/MergeTree/PKCondition.h
+0
-1
dbms/include/DB/Storages/StorageMergeTree.h
dbms/include/DB/Storages/StorageMergeTree.h
+3
-3
dbms/src/Interpreters/ExpressionAnalyzer.cpp
dbms/src/Interpreters/ExpressionAnalyzer.cpp
+12
-4
dbms/src/Storages/MergeTree/PKCondition.cpp
dbms/src/Storages/MergeTree/PKCondition.cpp
+3
-2
dbms/src/Storages/StorageMergeTree.cpp
dbms/src/Storages/StorageMergeTree.cpp
+12
-12
未找到文件。
dbms/include/DB/Interpreters/ExpressionAnalyzer.h
浏览文件 @
f7aedd22
...
...
@@ -68,7 +68,9 @@ public:
void
appendProjectResult
(
ExpressionActionsChain
&
chain
);
/// Если ast не запрос SELECT, просто получает все действия для вычисления выражения.
ExpressionActionsPtr
getActions
();
/// Если project_result, в выходном блоке останутся только вычисленные значения в нужном порядке, переименованные в алиасы.
/// Иначе, из блока будут удаляться только временные столбцы.
ExpressionActionsPtr
getActions
(
bool
project_result
);
/// Действия, которые можно сделать над пустым блоком: добавление констант и применение функций, зависящих только от констант.
/// Не выполняет подзапросы.
...
...
dbms/include/DB/Interpreters/Limits.h
浏览文件 @
f7aedd22
...
...
@@ -61,7 +61,7 @@ struct Limits
size_t
max_subquery_depth
;
size_t
max_pipeline_depth
;
size_t
max_ast_depth
;
/// Проверяются не во время парсинга,
size_t
max_ast_elements
;
/// а уже после парсинга запроса.
TODO: циклы при разборе алиасов в Expression.
size_t
max_ast_elements
;
/// а уже после парсинга запроса.
bool
readonly
;
...
...
dbms/include/DB/Storages/MergeTree/PKCondition.h
浏览文件 @
f7aedd22
...
...
@@ -3,7 +3,6 @@
#include <sstream>
#include <DB/Interpreters/Context.h>
#include <DB/Interpreters/Expression.h>
#include <DB/Storages/IStorage.h>
#include <DB/Core/SortDescription.h>
#include <DB/Parsers/ASTExpressionList.h>
...
...
dbms/include/DB/Storages/StorageMergeTree.h
浏览文件 @
f7aedd22
...
...
@@ -5,7 +5,7 @@
#include <DB/Core/SortDescription.h>
#include <DB/Interpreters/Context.h>
#include <DB/Interpreters/Expression.h>
#include <DB/Interpreters/Expression
Actions
.h>
#include <DB/Storages/IStorage.h>
...
...
@@ -172,7 +172,7 @@ private:
StorageMergeTreeSettings
settings
;
SharedPtr
<
Expression
>
primary_expr
;
ExpressionActionsPtr
primary_expr
;
SortDescription
sort_descr
;
Block
primary_key_sample
;
...
...
@@ -298,7 +298,7 @@ private:
BlockInputStreams
spreadMarkRangesAmongThreadsFinal
(
RangesInDataParts
parts
,
size_t
threads
,
const
Names
&
column_names
,
size_t
max_block_size
);
/// Создать выражение "Sign == 1".
void
createPositiveSignCondition
(
ExpressionPtr
&
out_expression
,
String
&
out_column
);
void
createPositiveSignCondition
(
Expression
Actions
Ptr
&
out_expression
,
String
&
out_column
);
/// Загрузить множество кусков с данными с диска. Вызывается один раз - при создании объекта.
void
loadDataParts
();
...
...
dbms/src/Interpreters/ExpressionAnalyzer.cpp
浏览文件 @
f7aedd22
...
...
@@ -912,7 +912,7 @@ void ExpressionAnalyzer::getActionsBeforeAggregationImpl(ASTPtr ast, ExpressionA
}
ExpressionActionsPtr
ExpressionAnalyzer
::
getActions
()
ExpressionActionsPtr
ExpressionAnalyzer
::
getActions
(
bool
project_result
)
{
ExpressionActionsPtr
actions
=
new
ExpressionActions
(
columns
,
settings
);
NamesWithAliases
result_columns
;
...
...
@@ -924,18 +924,26 @@ ExpressionActionsPtr ExpressionAnalyzer::getActions()
for
(
size_t
i
=
0
;
i
<
asts
.
size
();
++
i
)
{
result_columns
.
push_back
(
NameWithAlias
(
asts
[
i
]
->
getColumnName
(),
asts
[
i
]
->
getAlias
()));
result_names
.
push_back
(
result_columns
.
back
().
first
);
result_names
.
push_back
(
result_columns
.
back
().
second
);
getActionsImpl
(
asts
[
i
],
false
,
false
,
*
actions
);
}
}
else
{
result_columns
.
push_back
(
NameWithAlias
(
ast
->
getColumnName
(),
ast
->
getAlias
()));
result_names
.
push_back
(
result_columns
.
back
().
first
);
result_names
.
push_back
(
result_columns
.
back
().
second
);
getActionsImpl
(
ast
,
false
,
false
,
*
actions
);
}
if
(
project_result
)
{
actions
->
add
(
ExpressionActions
::
Action
::
project
(
result_columns
));
}
else
{
for
(
NamesAndTypesList
::
iterator
it
=
columns
.
begin
();
it
!=
columns
.
end
();
++
it
)
result_names
.
push_back
(
it
->
first
);
}
actions
->
finalize
(
result_names
);
...
...
dbms/src/Storages/MergeTree/PKCondition.cpp
浏览文件 @
f7aedd22
#include <DB/Storages/MergeTree/PKCondition.h>
#include <DB/DataTypes/DataTypesNumberFixed.h>
#include <DB/Interpreters/ExpressionAnalyzer.h>
namespace
DB
{
...
...
@@ -15,7 +16,7 @@ PKCondition::PKCondition(ASTPtr query, const Context & context_, const NamesAndT
/** Вычисление выражений, зависящих только от констант.
* Чтобы индекс мог использоваться, если написано, например WHERE Date = toDate(now()).
*/
Expression
expr_for_constant_folding
(
query
,
context_
,
all_columns
);
Expression
ActionsPtr
expr_for_constant_folding
=
ExpressionAnalyzer
(
query
,
context_
,
all_columns
).
getConstActions
(
);
Block
block_with_constants
;
/// В блоке должен быть хотя бы один столбец, чтобы у него было известно число строк.
...
...
@@ -25,7 +26,7 @@ PKCondition::PKCondition(ASTPtr query, const Context & context_, const NamesAndT
dummy_column
.
column
=
new
ColumnConstUInt8
(
1
,
0
);
block_with_constants
.
insert
(
dummy_column
);
expr_for_constant_folding
.
execute
(
block_with_constants
,
0
,
true
);
expr_for_constant_folding
->
execute
(
block_with_constants
);
/// Преобразуем секцию WHERE в обратную польскую строку.
ASTSelectQuery
&
select
=
dynamic_cast
<
ASTSelectQuery
&>
(
*
query
);
...
...
dbms/src/Storages/StorageMergeTree.cpp
浏览文件 @
f7aedd22
...
...
@@ -31,7 +31,6 @@
#include <DB/DataStreams/narrowBlockInputStreams.h>
#include <DB/DataStreams/copyData.h>
#include <DB/DataStreams/FilterBlockInputStream.h>
#include <DB/DataStreams/OldExpressionBlockInputStream.h>
#include <DB/Parsers/ASTExpressionList.h>
#include <DB/Parsers/ASTSelectQuery.h>
...
...
@@ -40,6 +39,7 @@
#include <DB/Parsers/ASTIdentifier.h>
#include <DB/Interpreters/sortBlock.h>
#include <DB/Interpreters/ExpressionAnalyzer.h>
#include <DB/Storages/StorageMergeTree.h>
#include <DB/Storages/MergeTree/PKCondition.h>
...
...
@@ -83,7 +83,7 @@ StorageMergeTree::StorageMergeTree(
sort_descr
.
push_back
(
SortColumnDescription
(
name
,
1
));
}
primary_expr
=
new
Expression
(
primary_expr_ast
,
context
,
*
columns
);
primary_expr
=
ExpressionAnalyzer
(
primary_expr_ast
,
context
,
*
columns
).
getActions
(
false
);
primary_key_sample
=
primary_expr
->
getSampleBlock
();
merge_threads
=
new
boost
::
threadpool
::
pool
(
settings
.
merging_threads
);
...
...
@@ -147,7 +147,7 @@ BlockInputStreams StorageMergeTree::read(
UInt64
sampling_column_value_limit
=
0
;
typedef
Poco
::
SharedPtr
<
ASTFunction
>
ASTFunctionPtr
;
ASTFunctionPtr
filter_function
;
ExpressionPtr
filter_expression
;
Expression
Actions
Ptr
filter_expression
;
ASTSelectQuery
&
select
=
*
dynamic_cast
<
ASTSelectQuery
*>
(
&*
query
);
if
(
select
.
sample_size
)
...
...
@@ -181,7 +181,7 @@ BlockInputStreams StorageMergeTree::read(
}
UInt64
sampling_column_max
=
0
;
DataTypePtr
type
=
Expression
(
sampling_expression
,
context
,
*
columns
).
getReturnTypes
()[
0
]
;
DataTypePtr
type
=
primary_expr
->
getSampleBlock
().
getByName
(
sampling_expression
->
getColumnName
()).
type
;
if
(
type
->
getName
()
==
"UInt64"
)
sampling_column_max
=
std
::
numeric_limits
<
UInt64
>::
max
();
...
...
@@ -211,7 +211,7 @@ BlockInputStreams StorageMergeTree::read(
filter_function
->
arguments
=
filter_function_args
;
filter_function
->
children
.
push_back
(
filter_function
->
arguments
);
filter_expression
=
new
Expression
(
filter_function
,
context
,
*
columns
);
filter_expression
=
ExpressionAnalyzer
(
filter_function
,
context
,
*
columns
).
getActions
(
false
);
/// Добавим столбцы, нужные для sampling_expression.
std
::
vector
<
String
>
add_columns
=
filter_expression
->
getRequiredColumns
();
...
...
@@ -274,7 +274,7 @@ BlockInputStreams StorageMergeTree::read(
for
(
size_t
i
=
0
;
i
<
res
.
size
();
++
i
)
{
BlockInputStreamPtr
original_stream
=
res
[
i
];
BlockInputStreamPtr
expression_stream
=
new
Old
ExpressionBlockInputStream
(
original_stream
,
filter_expression
);
BlockInputStreamPtr
expression_stream
=
new
ExpressionBlockInputStream
(
original_stream
,
filter_expression
);
BlockInputStreamPtr
filter_stream
=
new
FilterBlockInputStream
(
expression_stream
,
filter_function
->
getColumnName
());
res
[
i
]
=
filter_stream
;
}
...
...
@@ -391,7 +391,7 @@ BlockInputStreams StorageMergeTree::spreadMarkRangesAmongThreads(RangesInDataPar
/// Распределить засечки между потоками и сделать, чтобы в ответе (почти) все данные были сколлапсированы (модификатор FINAL).
BlockInputStreams
StorageMergeTree
::
spreadMarkRangesAmongThreadsFinal
(
RangesInDataParts
parts
,
size_t
threads
,
const
Names
&
column_names
,
size_t
max_block_size
)
{
ExpressionPtr
sign_filter_expression
;
Expression
Actions
Ptr
sign_filter_expression
;
String
sign_filter_column
;
createPositiveSignCondition
(
sign_filter_expression
,
sign_filter_column
);
...
...
@@ -405,12 +405,12 @@ BlockInputStreams StorageMergeTree::spreadMarkRangesAmongThreadsFinal(RangesInDa
max_block_size
,
column_names
,
*
this
,
part
.
data_part
,
part
.
ranges
,
thisPtr
());
to_collapse
.
push_back
(
new
Old
ExpressionBlockInputStream
(
source_stream
,
primary_expr
));
to_collapse
.
push_back
(
new
ExpressionBlockInputStream
(
source_stream
,
primary_expr
));
}
BlockInputStreams
res
;
if
(
to_collapse
.
size
()
==
1
)
res
.
push_back
(
new
FilterBlockInputStream
(
new
Old
ExpressionBlockInputStream
(
to_collapse
[
0
],
sign_filter_expression
),
sign_filter_column
));
res
.
push_back
(
new
FilterBlockInputStream
(
new
ExpressionBlockInputStream
(
to_collapse
[
0
],
sign_filter_expression
),
sign_filter_column
));
else
if
(
to_collapse
.
size
()
>
1
)
res
.
push_back
(
new
CollapsingFinalBlockInputStream
(
to_collapse
,
sort_descr
,
sign_column
));
...
...
@@ -418,7 +418,7 @@ BlockInputStreams StorageMergeTree::spreadMarkRangesAmongThreadsFinal(RangesInDa
}
void
StorageMergeTree
::
createPositiveSignCondition
(
ExpressionPtr
&
out_expression
,
String
&
out_column
)
void
StorageMergeTree
::
createPositiveSignCondition
(
Expression
Actions
Ptr
&
out_expression
,
String
&
out_column
)
{
ASTFunction
*
function
=
new
ASTFunction
;
ASTPtr
function_ptr
=
function
;
...
...
@@ -445,7 +445,7 @@ void StorageMergeTree::createPositiveSignCondition(ExpressionPtr & out_expressio
one
->
type
=
new
DataTypeInt8
;
one
->
value
=
Field
(
static_cast
<
Int64
>
(
1
));
out_expression
=
new
Expression
(
function_ptr
,
context
,
*
columns
);
out_expression
=
ExpressionAnalyzer
(
function_ptr
,
context
,
*
columns
).
getActions
(
false
);
out_column
=
function
->
getColumnName
();
}
...
...
@@ -839,7 +839,7 @@ void StorageMergeTree::mergeParts(std::vector<DataPartPtr> parts)
for
(
size_t
i
=
0
;
i
<
parts
.
size
();
++
i
)
{
MarkRanges
ranges
(
1
,
MarkRange
(
0
,
parts
[
i
]
->
size
));
src_streams
.
push_back
(
new
Old
ExpressionBlockInputStream
(
new
MergeTreeBlockInputStream
(
src_streams
.
push_back
(
new
ExpressionBlockInputStream
(
new
MergeTreeBlockInputStream
(
full_path
+
parts
[
i
]
->
name
+
'/'
,
DEFAULT_BLOCK_SIZE
,
all_column_names
,
*
this
,
parts
[
i
],
ranges
,
StoragePtr
()),
primary_expr
));
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录