[BUG]索引扫描删除记录不能完全删除
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 4.4k
- Forks
- 1.6k
- PR merge metrics
- No merged PRs in 30d
Description
Describe the bug
走索引扫描删除记录时删除不能全部删除
Environment
- OS Version: ubuntu22.04
- CPU Arch(x86/arm): x86
- Compiler: GCC 11.4.0 x86_64-linux-gnu
- Others:
Fast Reproduce Steps(Required)
Steps to reproduce the behavior:
miniob> create table t (id int,age int);
SUCCESS
miniob> create index t_id_idx on t (id);
SUCCESS
miniob> insert into t values (1,10);
SUCCESS
miniob > insert into t values (1,11);
SUCCESS
miniob > insert into t values (1,12);
SUCCESS
miniob > select from t;
id|age
1|10
1|11
1|12
miniob > delete from t where id 1;
SUCCESS
Expected behavior
记录应该全部被删除
miniob > select from t;
id|age
Actual Behavior
What is the result? picture is allowed
中间的记录被跳过没有被删除
miniob > select from t;
id|age
1|11
Additional context
- 导致该问题的原因是在
RC BplusTreeScanner::next_entry(RID& rid, bool idx_need_increase)这个函数中查找下一个entry时,会把iter_index_++,但删除一条记录会将其对应的索引向前覆盖memmove(__item_at(index), __item_at(index + 1), (size() - index - 1) * item_size()),iter_index_++就直接跳过了下一条要获取的记录了。
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with BplusTreeScanner::next_entry(RID& rid, bool idx_need_increase) and reproduce the shown duplicate-key DELETE scenario in the miniob prompt. Trace how the scanner advances while an index entry is removed, then verify that deleting all rows matching id 1 leaves no records in the final SELECT result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100