Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
490722ad
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,发现更多精彩内容 >>
未验证
提交
490722ad
编写于
8月 29, 2019
作者:
A
alesapin
提交者:
GitHub
8月 29, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #6723 from yandex/bad_size_of_marks_skip_idx_bug
Fix segmentation fault in vertical merge with skip indices
上级
6d6851e7
dac55278
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
79 addition
and
26 deletion
+79
-26
dbms/src/Interpreters/ExpressionActions.cpp
dbms/src/Interpreters/ExpressionActions.cpp
+1
-1
dbms/src/Interpreters/MutationsInterpreter.cpp
dbms/src/Interpreters/MutationsInterpreter.cpp
+3
-1
dbms/src/Parsers/ASTIndexDeclaration.h
dbms/src/Parsers/ASTIndexDeclaration.h
+1
-1
dbms/src/Storages/MergeTree/IMergedBlockOutputStream.cpp
dbms/src/Storages/MergeTree/IMergedBlockOutputStream.cpp
+2
-2
dbms/src/Storages/MergeTree/MergeTreeData.cpp
dbms/src/Storages/MergeTree/MergeTreeData.cpp
+9
-7
dbms/src/Storages/MergeTree/MergeTreeData.h
dbms/src/Storages/MergeTree/MergeTreeData.h
+7
-7
dbms/src/Storages/MergeTree/MergeTreeDataMergerMutator.cpp
dbms/src/Storages/MergeTree/MergeTreeDataMergerMutator.cpp
+17
-7
dbms/src/Storages/MergeTree/MergeTreeIndices.cpp
dbms/src/Storages/MergeTree/MergeTreeIndices.cpp
+1
-0
dbms/src/Storages/MergeTree/MergeTreeIndices.h
dbms/src/Storages/MergeTree/MergeTreeIndices.h
+14
-0
dbms/tests/queries/0_stateless/00999_test_skip_indices_with_alter_and_merge.reference
...ss/00999_test_skip_indices_with_alter_and_merge.reference
+2
-0
dbms/tests/queries/0_stateless/00999_test_skip_indices_with_alter_and_merge.sql
...tateless/00999_test_skip_indices_with_alter_and_merge.sql
+22
-0
未找到文件。
dbms/src/Interpreters/ExpressionActions.cpp
浏览文件 @
490722ad
...
...
@@ -726,7 +726,7 @@ void ExpressionActions::addImpl(ExpressionAction action, Names & new_names)
new_names
.
push_back
(
action
.
result_name
);
new_names
.
insert
(
new_names
.
end
(),
action
.
array_joined_columns
.
begin
(),
action
.
array_joined_columns
.
end
());
/// Compiled functions are custom functions and the
m
don't need building
/// Compiled functions are custom functions and the
y
don't need building
if
(
action
.
type
==
ExpressionAction
::
APPLY_FUNCTION
&&
!
action
.
is_function_compiled
)
{
if
(
sample_block
.
has
(
action
.
result_name
))
...
...
dbms/src/Interpreters/MutationsInterpreter.cpp
浏览文件 @
490722ad
...
...
@@ -289,13 +289,15 @@ void MutationsInterpreter::prepare(bool dry_run)
throw
Exception
(
"Unknown mutation command type: "
+
DB
::
toString
<
int
>
(
command
.
type
),
ErrorCodes
::
UNKNOWN_MUTATION_COMMAND
);
}
/// We cares about affected indices because we also need to rewrite them
/// when one of index columns updated or filtered with delete
if
(
!
affected_indices_columns
.
empty
())
{
if
(
!
stages
.
empty
())
{
std
::
vector
<
Stage
>
stages_copy
;
/// Copy all filled stages except index calculation stage.
for
(
const
auto
&
stage
:
stages
)
for
(
const
auto
&
stage
:
stages
)
{
stages_copy
.
emplace_back
(
context
);
stages_copy
.
back
().
column_to_updated
=
stage
.
column_to_updated
;
...
...
dbms/src/Parsers/ASTIndexDeclaration.h
浏览文件 @
490722ad
...
...
@@ -41,7 +41,7 @@ public:
return
res
;
}
void
formatImpl
(
const
FormatSettings
&
s
,
FormatState
&
state
,
FormatStateStacked
frame
)
const
override
void
formatImpl
(
const
FormatSettings
&
s
,
FormatState
&
state
,
FormatStateStacked
frame
)
const
override
{
frame
.
need_parens
=
false
;
std
::
string
indent_str
=
s
.
one_line
?
""
:
std
::
string
(
4
*
frame
.
indent
,
' '
);
...
...
dbms/src/Storages/MergeTree/IMergedBlockOutputStream.cpp
浏览文件 @
490722ad
...
...
@@ -336,9 +336,9 @@ void IMergedBlockOutputStream::calculateAndSerializeSkipIndices(
size_t
skip_index_current_mark
=
0
;
/// Filling and writing skip indices like in IMergedBlockOutputStream::writeColumn
for
(
size_t
i
=
0
;
i
<
s
torage
.
s
kip_indices
.
size
();
++
i
)
for
(
size_t
i
=
0
;
i
<
skip_indices
.
size
();
++
i
)
{
const
auto
index
=
s
torage
.
s
kip_indices
[
i
];
const
auto
index
=
skip_indices
[
i
];
auto
&
stream
=
*
skip_indices_streams
[
i
];
size_t
prev_pos
=
0
;
skip_index_current_mark
=
skip_index_mark
;
...
...
dbms/src/Storages/MergeTree/MergeTreeData.cpp
浏览文件 @
490722ad
...
...
@@ -358,10 +358,10 @@ void MergeTreeData::setProperties(
const
auto
&
index_decl
=
std
::
dynamic_pointer_cast
<
ASTIndexDeclaration
>
(
index_ast
);
new_indices
.
push_back
(
MergeTreeIndexFactory
::
instance
().
get
(
all_columns
,
std
::
dynamic_pointer_cast
<
ASTIndexDeclaration
>
(
index_decl
->
clone
()),
global_context
));
MergeTreeIndexFactory
::
instance
().
get
(
all_columns
,
std
::
dynamic_pointer_cast
<
ASTIndexDeclaration
>
(
index_decl
->
clone
()),
global_context
));
if
(
indices_names
.
find
(
new_indices
.
back
()
->
name
)
!=
indices_names
.
end
())
throw
Exception
(
...
...
@@ -1293,7 +1293,7 @@ void MergeTreeData::checkAlter(const AlterCommands & commands, const Context & c
}
if
(
columns_alter_forbidden
.
count
(
command
.
column_name
))
throw
Exception
(
"
t
rying to ALTER key column "
+
command
.
column_name
,
ErrorCodes
::
ILLEGAL_COLUMN
);
throw
Exception
(
"
T
rying to ALTER key column "
+
command
.
column_name
,
ErrorCodes
::
ILLEGAL_COLUMN
);
if
(
columns_alter_metadata_only
.
count
(
command
.
column_name
))
{
...
...
@@ -1578,7 +1578,8 @@ void MergeTreeData::alterDataPart(
if
(
expression
)
{
BlockInputStreamPtr
part_in
=
std
::
make_shared
<
MergeTreeSequentialBlockInputStream
>
(
*
this
,
part
,
expression
->
getRequiredColumns
(),
false
,
/* take_column_types_from_storage = */
false
);
*
this
,
part
,
expression
->
getRequiredColumns
(),
false
,
/* take_column_types_from_storage = */
false
);
auto
compression_codec
=
global_context
.
chooseCompressionCodec
(
part
->
bytes_on_disk
,
...
...
@@ -1600,7 +1601,8 @@ void MergeTreeData::alterDataPart(
true
/* sync */
,
compression_codec
,
true
/* skip_offsets */
,
{},
/// Don't recalc indices because indices alter is restricted
std
::
vector
<
MergeTreeIndexPtr
>
{},
unused_written_offsets
,
part
->
index_granularity
,
&
part
->
index_granularity_info
);
...
...
dbms/src/Storages/MergeTree/MergeTreeData.h
浏览文件 @
490722ad
...
...
@@ -621,6 +621,13 @@ public:
(
settings
->
enable_mixed_granularity_parts
||
!
has_non_adaptive_index_granularity_parts
);
}
/// Get constant pointer to storage settings.
/// Copy this pointer into your scope and you will
/// get consistent settings.
MergeTreeSettingsPtr
getSettings
()
const
{
return
storage_settings
.
get
();
}
MergeTreeDataFormatVersion
format_version
;
...
...
@@ -679,13 +686,6 @@ public:
bool
has_non_adaptive_index_granularity_parts
=
false
;
/// Get constant pointer to storage settings.
/// Copy this pointer into your scope and you will
/// get consistent settings.
MergeTreeSettingsPtr
getSettings
()
const
{
return
storage_settings
.
get
();
}
protected:
...
...
dbms/src/Storages/MergeTree/MergeTreeDataMergerMutator.cpp
浏览文件 @
490722ad
...
...
@@ -379,7 +379,7 @@ static void extractMergingAndGatheringColumns(
std
::
set
<
String
>
key_columns
(
sort_key_columns_vec
.
cbegin
(),
sort_key_columns_vec
.
cend
());
for
(
const
auto
&
index
:
indexes
)
{
Names
index_columns_vec
=
index
->
expr
->
getRequiredColumns
();
Names
index_columns_vec
=
index
->
getColumnsRequiredForIndexCalc
();
std
::
copy
(
index_columns_vec
.
cbegin
(),
index_columns_vec
.
cend
(),
std
::
inserter
(
key_columns
,
key_columns
.
end
()));
}
...
...
@@ -828,6 +828,7 @@ MergeTreeData::MutableDataPartPtr MergeTreeDataMergerMutator::mergePartsToTempor
rows_sources_read_buf
.
seek
(
0
,
0
);
ColumnGathererStream
column_gathered_stream
(
column_name
,
column_part_streams
,
rows_sources_read_buf
);
MergedColumnOnlyOutputStream
column_to
(
data
,
column_gathered_stream
.
getHeader
(),
...
...
@@ -835,10 +836,13 @@ MergeTreeData::MutableDataPartPtr MergeTreeDataMergerMutator::mergePartsToTempor
false
,
compression_codec
,
false
,
{},
/// we don't need to recalc indices here
/// because all of them were already recalculated and written
/// as key part of vertical merge
std
::
vector
<
MergeTreeIndexPtr
>
{},
written_offset_columns
,
to
.
getIndexGranularity
()
);
to
.
getIndexGranularity
()
);
size_t
column_elems_written
=
0
;
column_to
.
writePrefix
();
...
...
@@ -1019,9 +1023,9 @@ MergeTreeData::MutableDataPartPtr MergeTreeDataMergerMutator::mutatePartToTempor
for
(
size_t
i
=
0
;
i
<
data
.
skip_indices
.
size
();
++
i
)
{
const
auto
&
index
=
data
.
skip_indices
[
i
];
const
auto
&
index_cols
=
index
->
expr
->
getRequiredColumns
();
auto
it
=
find
(
cbegin
(
index_cols
),
cend
(
index_cols
),
col
);
if
(
it
!=
cend
(
index_cols
)
&&
indices_to_recalc
.
insert
(
index
).
second
)
const
auto
&
index_cols
=
index
->
getColumnsRequiredForIndexCalc
();
auto
it
=
std
::
find
(
std
::
cbegin
(
index_cols
),
std
::
cend
(
index_cols
),
col
);
if
(
it
!=
std
::
cend
(
index_cols
)
&&
indices_to_recalc
.
insert
(
index
).
second
)
{
ASTPtr
expr_list
=
MergeTreeData
::
extractKeyExpressionList
(
storage_from_source_part
->
getIndices
().
indices
[
i
]
->
expr
->
clone
());
...
...
@@ -1038,6 +1042,12 @@ MergeTreeData::MutableDataPartPtr MergeTreeDataMergerMutator::mutatePartToTempor
auto
indices_recalc_expr
=
ExpressionAnalyzer
(
indices_recalc_expr_list
,
indices_recalc_syntax
,
context
).
getActions
(
false
);
/// We can update only one column, but some skip idx expression may depend on several
/// columns (c1 + c2 * c3). It works because in stream was created with help of
/// MutationsInterpreter which knows about skip indices and stream 'in' already has
/// all required columns.
/// TODO move this logic to single place.
in
=
std
::
make_shared
<
MaterializingBlockInputStream
>
(
std
::
make_shared
<
ExpressionBlockInputStream
>
(
in
,
indices_recalc_expr
));
}
...
...
dbms/src/Storages/MergeTree/MergeTreeIndices.cpp
浏览文件 @
490722ad
...
...
@@ -51,6 +51,7 @@ std::unique_ptr<IMergeTreeIndex> MergeTreeIndexFactory::get(
return
lft
+
", "
+
rht
.
first
;
}),
ErrorCodes
::
INCORRECT_QUERY
);
return
it
->
second
(
columns
,
node
,
context
);
}
...
...
dbms/src/Storages/MergeTree/MergeTreeIndices.h
浏览文件 @
490722ad
...
...
@@ -104,11 +104,25 @@ public:
virtual
MergeTreeIndexConditionPtr
createIndexCondition
(
const
SelectQueryInfo
&
query_info
,
const
Context
&
context
)
const
=
0
;
Names
getColumnsRequiredForIndexCalc
()
const
{
return
expr
->
getRequiredColumns
();
}
/// Index name
String
name
;
/// Index expression (x * y)
/// with columns arguments
ExpressionActionsPtr
expr
;
/// Names of columns for index
Names
columns
;
/// Data types of columns
DataTypes
data_types
;
/// Block with columns and data_types
Block
header
;
/// Skip index granularity
size_t
granularity
;
};
...
...
dbms/tests/queries/0_stateless/00999_test_skip_indices_with_alter_and_merge.reference
0 → 100644
浏览文件 @
490722ad
201
201
dbms/tests/queries/0_stateless/00999_test_skip_indices_with_alter_and_merge.sql
0 → 100644
浏览文件 @
490722ad
SET
allow_experimental_data_skipping_indices
=
1
;
DROP
TABLE
IF
EXISTS
test_vertical_merge
;
CREATE
TABLE
test_vertical_merge
(
k
UInt64
,
val1
UInt64
,
val2
UInt64
,
INDEX
idx1
val1
*
val2
TYPE
minmax
GRANULARITY
1
,
INDEX
idx2
val1
*
k
TYPE
minmax
GRANULARITY
1
)
ENGINE
MergeTree
()
ORDER
BY
k
SETTINGS
vertical_merge_algorithm_min_rows_to_activate
=
1
,
vertical_merge_algorithm_min_columns_to_activate
=
1
;
INSERT
INTO
test_vertical_merge
SELECT
number
,
number
+
5
,
number
*
12
from
numbers
(
1000
);
SELECT
COUNT
()
from
test_vertical_merge
WHERE
val2
<=
2400
;
OPTIMIZE
TABLE
test_vertical_merge
FINAL
;
SELECT
COUNT
()
from
test_vertical_merge
WHERE
val2
<=
2400
;
DROP
TABLE
IF
EXISTS
test_vertical_merge
;
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录