Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
9d5ece27
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,发现更多精彩内容 >>
未验证
提交
9d5ece27
编写于
4月 03, 2020
作者:
A
Alexander Kuzmenkov
提交者:
GitHub
4月 03, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #10025 from ClickHouse/aku/shm-trailing-zeros
Support trailing zero bytes in string hash map
上级
3e185d24
cd76ba3c
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
52 addition
and
8 deletion
+52
-8
dbms/Common/HashTable/StringHashMap.h
dbms/Common/HashTable/StringHashMap.h
+14
-6
dbms/Common/HashTable/StringHashTable.h
dbms/Common/HashTable/StringHashTable.h
+11
-1
dbms/Common/HashTable/TwoLevelStringHashTable.h
dbms/Common/HashTable/TwoLevelStringHashTable.h
+11
-1
tests/queries/0_stateless/01109_sc0rp10_string_hash_map_zero_bytes.reference
...teless/01109_sc0rp10_string_hash_map_zero_bytes.reference
+1
-0
tests/queries/0_stateless/01109_sc0rp10_string_hash_map_zero_bytes.sql
.../0_stateless/01109_sc0rp10_string_hash_map_zero_bytes.sql
+15
-0
未找到文件。
dbms/Common/HashTable/StringHashMap.h
浏览文件 @
9d5ece27
...
...
@@ -25,9 +25,13 @@ struct StringHashMapCell<StringKey16, TMapped> : public HashMapCell<StringKey16,
using
Base
::
Base
;
static
constexpr
bool
need_zero_value_storage
=
false
;
bool
isZero
(
const
HashTableNoState
&
state
)
const
{
return
isZero
(
this
->
value
.
first
,
state
);
}
// Assuming String does not contain zero bytes. NOTE: Cannot be used in serialized method
static
bool
isZero
(
const
StringKey16
&
key
,
const
HashTableNoState
&
/*state*/
)
{
return
key
.
low
==
0
;
}
void
setZero
()
{
this
->
value
.
first
.
low
=
0
;
}
// Zero means unoccupied cells in hash table. Use key with last word = 0 as
// zero keys, because such keys are unrepresentable (no way to encode length).
static
bool
isZero
(
const
StringKey16
&
key
,
const
HashTableNoState
&
)
{
return
key
.
high
==
0
;
}
void
setZero
()
{
this
->
value
.
first
.
high
=
0
;
}
// external
const
StringRef
getKey
()
const
{
return
toStringRef
(
this
->
value
.
first
);
}
// internal
...
...
@@ -42,9 +46,13 @@ struct StringHashMapCell<StringKey24, TMapped> : public HashMapCell<StringKey24,
using
Base
::
Base
;
static
constexpr
bool
need_zero_value_storage
=
false
;
bool
isZero
(
const
HashTableNoState
&
state
)
const
{
return
isZero
(
this
->
value
.
first
,
state
);
}
// Assuming String does not contain zero bytes. NOTE: Cannot be used in serialized method
static
bool
isZero
(
const
StringKey24
&
key
,
const
HashTableNoState
&
/*state*/
)
{
return
key
.
a
==
0
;
}
void
setZero
()
{
this
->
value
.
first
.
a
=
0
;
}
// Zero means unoccupied cells in hash table. Use key with last word = 0 as
// zero keys, because such keys are unrepresentable (no way to encode length).
static
bool
isZero
(
const
StringKey24
&
key
,
const
HashTableNoState
&
)
{
return
key
.
c
==
0
;
}
void
setZero
()
{
this
->
value
.
first
.
c
=
0
;
}
// external
const
StringRef
getKey
()
const
{
return
toStringRef
(
this
->
value
.
first
);
}
// internal
...
...
dbms/Common/HashTable/StringHashTable.h
浏览文件 @
9d5ece27
...
...
@@ -18,14 +18,17 @@ struct StringKey24
inline
StringRef
ALWAYS_INLINE
toStringRef
(
const
StringKey8
&
n
)
{
assert
(
n
!=
0
);
return
{
reinterpret_cast
<
const
char
*>
(
&
n
),
8ul
-
(
__builtin_clzll
(
n
)
>>
3
)};
}
inline
StringRef
ALWAYS_INLINE
toStringRef
(
const
StringKey16
&
n
)
{
assert
(
n
.
high
!=
0
);
return
{
reinterpret_cast
<
const
char
*>
(
&
n
),
16ul
-
(
__builtin_clzll
(
n
.
high
)
>>
3
)};
}
inline
StringRef
ALWAYS_INLINE
toStringRef
(
const
StringKey24
&
n
)
{
assert
(
n
.
c
!=
0
);
return
{
reinterpret_cast
<
const
char
*>
(
&
n
),
24ul
-
(
__builtin_clzll
(
n
.
c
)
>>
3
)};
}
...
...
@@ -229,6 +232,7 @@ public:
template
<
typename
Self
,
typename
KeyHolder
,
typename
Func
>
static
auto
ALWAYS_INLINE
dispatch
(
Self
&
self
,
KeyHolder
&&
key_holder
,
Func
&&
func
)
{
StringHashTableHash
hash
;
const
StringRef
&
x
=
keyHolderGetKey
(
key_holder
);
const
size_t
sz
=
x
.
size
;
if
(
sz
==
0
)
...
...
@@ -237,6 +241,13 @@ public:
return
func
(
self
.
m0
,
VoidKey
{},
0
);
}
if
(
x
.
data
[
sz
-
1
]
==
0
)
{
// Strings with trailing zeros are not representable as fixed-size
// string keys. Put them to the generic table.
return
func
(
self
.
ms
,
std
::
forward
<
KeyHolder
>
(
key_holder
),
hash
(
x
));
}
const
char
*
p
=
x
.
data
;
// pending bits that needs to be shifted out
const
char
s
=
(
-
sz
&
7
)
*
8
;
...
...
@@ -247,7 +258,6 @@ public:
StringKey24
k24
;
UInt64
n
[
3
];
};
StringHashTableHash
hash
;
switch
((
sz
-
1
)
>>
3
)
{
case
0
:
// 1..8 bytes
...
...
dbms/Common/HashTable/TwoLevelStringHashTable.h
浏览文件 @
9d5ece27
...
...
@@ -77,6 +77,7 @@ public:
template
<
typename
Self
,
typename
Func
,
typename
KeyHolder
>
static
auto
ALWAYS_INLINE
dispatch
(
Self
&
self
,
KeyHolder
&&
key_holder
,
Func
&&
func
)
{
StringHashTableHash
hash
;
const
StringRef
&
x
=
keyHolderGetKey
(
key_holder
);
const
size_t
sz
=
x
.
size
;
if
(
sz
==
0
)
...
...
@@ -85,6 +86,16 @@ public:
return
func
(
self
.
impls
[
0
].
m0
,
VoidKey
{},
0
);
}
if
(
x
.
data
[
x
.
size
-
1
]
==
0
)
{
// Strings with trailing zeros are not representable as fixed-size
// string keys. Put them to the generic table.
auto
res
=
hash
(
x
);
auto
buck
=
getBucketFromHash
(
res
);
return
func
(
self
.
impls
[
buck
].
ms
,
std
::
forward
<
KeyHolder
>
(
key_holder
),
res
);
}
const
char
*
p
=
x
.
data
;
// pending bits that needs to be shifted out
const
char
s
=
(
-
sz
&
7
)
*
8
;
...
...
@@ -95,7 +106,6 @@ public:
StringKey24
k24
;
UInt64
n
[
3
];
};
StringHashTableHash
hash
;
switch
((
sz
-
1
)
>>
3
)
{
case
0
:
...
...
tests/queries/0_stateless/01109_sc0rp10_string_hash_map_zero_bytes.reference
0 → 100644
浏览文件 @
9d5ece27
1
tests/queries/0_stateless/01109_sc0rp10_string_hash_map_zero_bytes.sql
0 → 100644
浏览文件 @
9d5ece27
-- Test that the string hash map works properly with keys containing zero
-- bytes.
-- Keys with no central '1' are mostly duplicates. The unique keys
-- in this group are '', '\0', ...., '\0 x 34', to a total of 35. All other
-- keys are unique.
select
count
(
*
)
=
18
*
18
*
17
+
35
from
(
select
key
from
(
with
18
as
n
select
repeat
(
'
\0
'
,
number
%
n
)
||
repeat
(
'1'
,
intDiv
(
number
,
n
)
%
n
)
||
repeat
(
'
\0
'
,
intDiv
(
number
,
n
*
n
)
%
n
)
key
from
numbers
(
18
*
18
*
18
))
group
by
key
);
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录