Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
oceanbase
miniob
提交
d499d900
M
miniob
项目概览
oceanbase
/
miniob
1 年多 前同步成功
通知
74
Star
1521
Fork
537
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
分析
仓库
DevOps
项目成员
Pages
M
miniob
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Pages
分析
分析
仓库分析
DevOps
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
提交
未验证
提交
d499d900
编写于
2月 17, 2022
作者:
羽飞
提交者:
GitHub
2月 17, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #26 from hnwyllmm/main
speed up the lookup
上级
5122a711
2e076250
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
57 addition
and
16 deletion
+57
-16
src/observer/storage/common/bplus_tree.cpp
src/observer/storage/common/bplus_tree.cpp
+57
-16
未找到文件。
src/observer/storage/common/bplus_tree.cpp
浏览文件 @
d499d900
...
@@ -66,6 +66,38 @@ int key_compare(AttrType attr_type, int attr_length, const char *first, const ch
...
@@ -66,6 +66,38 @@ int key_compare(AttrType attr_type, int attr_length, const char *first, const ch
RID
*
rid2
=
(
RID
*
)(
second
+
attr_length
);
RID
*
rid2
=
(
RID
*
)(
second
+
attr_length
);
return
RID
::
compare
(
rid1
,
rid2
);
return
RID
::
compare
(
rid1
,
rid2
);
}
}
int
lower_bound
(
AttrType
attr_type
,
int
attr_length
,
const
char
*
data
,
const
int
item_length
,
const
int
item_num
,
const
char
*
key
,
bool
*
_found
=
nullptr
)
{
int
left
=
0
;
int
right
=
item_num
;
int
med
=
0
;
bool
last_is_bigger
=
false
;
bool
found
=
false
;
for
(
;
left
<
right
;
)
{
med
=
(
left
+
right
)
/
2
;
const
char
*
item
=
data
+
item_length
*
med
;
int
cmp_result
=
key_compare
(
attr_type
,
attr_length
,
key
,
item
);
if
(
cmp_result
==
0
)
{
last_is_bigger
=
false
;
found
=
true
;
break
;
}
if
(
cmp_result
>
0
)
{
last_is_bigger
=
true
;
left
=
med
+
1
;
}
else
{
last_is_bigger
=
false
;
right
=
med
;
}
}
if
(
_found
)
*
_found
=
found
;
if
(
last_is_bigger
)
return
med
+
1
;
return
med
;
}
int
get_page_index_capacity
(
int
attr_length
)
int
get_page_index_capacity
(
int
attr_length
)
{
{
...
@@ -680,12 +712,13 @@ RC BplusTreeHandler::find_leaf(const char *pkey, PageNum *leaf_page)
...
@@ -680,12 +712,13 @@ RC BplusTreeHandler::find_leaf(const char *pkey, PageNum *leaf_page)
while
(
false
==
node
->
is_leaf
)
{
while
(
false
==
node
->
is_leaf
)
{
char
*
pdata
;
char
*
pdata
;
int
i
;
int
i
;
for
(
i
=
0
;
i
<
node
->
key_num
;
i
++
)
{
//for (i = 0; i < node->key_num; i++) {
int
tmp
=
// int tmp =
key_compare
(
file_header_
.
attr_type
,
file_header_
.
attr_length
,
pkey
,
node
->
keys
+
i
*
file_header_
.
key_length
);
// key_compare(file_header_.attr_type, file_header_.attr_length, pkey, node->keys + i * file_header_.key_length);
if
(
tmp
<
0
)
// if (tmp < 0)
break
;
// break;
}
//}
i
=
lower_bound
(
file_header_
.
attr_type
,
file_header_
.
attr_length
,
node
->
keys
,
file_header_
.
key_length
,
node
->
key_num
,
pkey
);
if
(
page_handle
.
open
==
true
)
{
if
(
page_handle
.
open
==
true
)
{
disk_buffer_pool_
->
unpin_page
(
&
page_handle
);
disk_buffer_pool_
->
unpin_page
(
&
page_handle
);
...
@@ -716,16 +749,24 @@ RC BplusTreeHandler::insert_entry_into_node(IndexNode *node, const char *pkey, c
...
@@ -716,16 +749,24 @@ RC BplusTreeHandler::insert_entry_into_node(IndexNode *node, const char *pkey, c
{
{
int
insert_pos
=
0
,
tmp
;
int
insert_pos
=
0
,
tmp
;
for
(;
insert_pos
<
node
->
key_num
;
insert_pos
++
)
{
//for (; insert_pos < node->key_num; insert_pos++) {
tmp
=
key_compare
(
// tmp = key_compare(
file_header_
.
attr_type
,
file_header_
.
attr_length
,
pkey
,
node
->
keys
+
insert_pos
*
file_header_
.
key_length
);
// file_header_.attr_type, file_header_.attr_length, pkey, node->keys + insert_pos * file_header_.key_length);
if
(
tmp
==
0
)
{
// if (tmp == 0) {
LOG_TRACE
(
"Insert into %d occur duplicated key, rid:%s."
,
file_id_
,
node
->
rids
[
insert_pos
].
to_string
().
c_str
());
// LOG_TRACE("Insert into %d occur duplicated key, rid:%s.", file_id_, node->rids[insert_pos].to_string().c_str());
return
RC
::
RECORD_DUPLICATE_KEY
;
// return RC::RECORD_DUPLICATE_KEY;
}
// }
if
(
tmp
<
0
)
// if (tmp < 0)
break
;
// break;
}
//}
bool
found
=
false
;
insert_pos
=
lower_bound
(
file_header_
.
attr_type
,
file_header_
.
attr_length
,
node
->
keys
,
file_header_
.
key_length
,
node
->
key_num
,
pkey
,
&
found
);
if
(
found
)
{
LOG_TRACE
(
"Insert into %d occur duplicated key, rid:%s."
,
file_id_
,
node
->
rids
[
insert_pos
].
to_string
().
c_str
());
return
RC
::
RECORD_DUPLICATE_KEY
;
}
char
*
from
=
node
->
keys
+
insert_pos
*
file_header_
.
key_length
;
char
*
from
=
node
->
keys
+
insert_pos
*
file_header_
.
key_length
;
char
*
to
=
from
+
file_header_
.
key_length
;
char
*
to
=
from
+
file_header_
.
key_length
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录