Skip to content

Commit

Permalink
add test caes for update and delete
Browse files Browse the repository at this point in the history
  • Loading branch information
sinkinben committed Oct 21, 2021
1 parent c1b5899 commit d7e5db7
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
2 changes: 2 additions & 0 deletions btree.h
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,8 @@ void *internal_create_new_root(table_t *table, uint32_t right_child_page_num)
*node_parent(left_child) = table->root_page_num;
*node_parent(right_child) = table->root_page_num;

// above code is the same as `create_new_root`

// adjust its children's parent
for (uint32_t idx = 0; idx < *internal_node_num_keys(left_child); idx++)
{
Expand Down
2 changes: 1 addition & 1 deletion docs/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ The input to the front-end is a SQL query. the output is sqlite virtual machine
- 实现 Linux Kernel 的侵入式容器(实现一个链表)。
- 基于这个链表,实现一个操作 log 链表,然后支持 commit/rollback 等操作。
- 支持 `commit` :把内存中修改过的内容持久化到磁盘(目前是 `.exit` 的时候覆盖写入)
- 支持 `delete` :删除某个 `key` .
- 支持 `delete` :删除某个 `key` .
- 目前的 `delete` 是伪删除。
- 目前只是简单从 leaf node 中删除,不会调整 parent 指针,也不会重新调整 B+Tree 的结构。
- 这意味着,即使某一行从表中删除,但它依旧会占用磁盘空间。
Expand Down
36 changes: 36 additions & 0 deletions spec/main_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,42 @@ def run_script(commands)
])
end

it 'test udpate' do
n = 20
list = Array(1..n)
script = list.map do |i| "insert #{i} #{i} #{i}@sjtu.edu.cn" end
script += list.map do |i| "update #{i} #{i} #{i}" end
script << "select"
script << ".exit"
result = run_script(script)

expected_values = list.map do |i| "(#{i}, #{i}, #{i})" end
expected_values[0] = "tinydb > " + expected_values[0]
expected_values.append(
"total #{n} rows", "Executed.", "tinydb > "
)
# print(result.last(n+3))
expect(result.last(n+3)).to match_array(expected_values)
end

it 'test delete' do
n = 20
list = Array(1..n)
script = list.map do |i| "insert #{i} #{i} #{i}" end
script += list.find_all{|e| e % 2 == 0}.map do |i| "delete #{i}" end
script << "select"
script << ".exit"

result = run_script(script)

expected_values = list.find_all{|e| e % 2 != 0}.map do |i| "(#{i}, #{i}, #{i})" end
expected_values[0] = "tinydb > " + expected_values[0]
expected_values.append(
"total #{n / 2} rows", "Executed.", "tinydb > "
)
expect(result.last(n / 2 + 3)).to match_array(expected_values)
end

# insert n rows (or with shuffle)
def run_batch_insertion(n, need_shuffle)
print("\n#{n} rows, ", "shuffle: #{need_shuffle} \n")
Expand Down

0 comments on commit d7e5db7

Please sign in to comment.