PICK OF THE WEEK
提示:这里为什么一定区分叶子节点呢 https://en.wikipedia.org/wiki/B%2B_tree
## 插入逻辑 和索引的关系
case SCF_INSERT:
make_record(value_num, values, record_data);
Operation::Type::INSERT
index->insert_entry(record, &rid);
## 更新和索引的关系
## 更新和索引的关系
case SCF_UPDATE:
RC Table::commit_update(T
Record oldrecord;
rc = record_handler_->get_record(&rid, &oldrecord);
RC Table::scan_record_by_index(T
RC Trx::commit() {
RID rid;
rid.page_num = operation.page_num();
rid.slot_num = operation.slot_num();
RC Table::commit_insert(Trx *trx, const RID &rid)
rc = index->insert_entry(oldrecord.data, &oldrecord.rid);
/**
* 获取指定文件中标识符为rid的记录内容到rec指向的记录结构中
* @param rid
* @param rec
* @return
*/
RC get_record(const RID *rid, Record *rec);
## 查找和索引的关系
case SCF_SELECT:
RC SelectExeNode::execute(TupleSet &tuple_set)
return scan_record(trx, filter, limit, (void *)&adapter, scan_record_reader_adapter);
IndexScanner *Table::find_index_for_scan(const DefaultConditionFilter &filter)
RC Table::scan_record_by_index(
RC BplusTreeHandler::insert_entry(const char *pkey, const RID *rid) {
## 插入一行记录 case SCF_INSERT:
Table::insert_record(Trx *trx, int value_num, const Value *values)
Record
RC BplusTreeHandler::insert_entry(const char *pkey, const RID *rid) {
class BplusTreeIndex : public Index {
RC BplusTreeHandler::insert_entry(const char *pkey, const RID *rid)
RC BplusTreeScanner::open
## 干啥呢
int CmpKey(AttrType attr_type, int attr_length, const char *pdata, const char *pkey)
{
int result = CompareKey(pdata, pkey, attr_type, attr_length);
if (0 != result) {
return result;
}
RID *rid1 = (RID *) (pdata + attr_length);
RID *rid2 = (RID *) (pkey + attr_length);
return CmpRid(rid1, rid2);
}
RC BplusTreeHandler::insert_into_leaf(PageNum leaf_page, const char *pkey, const RID *rid)
参考:更新逻辑
rc = index->insert_entry(oldrecord.data, &oldrecord.rid);
f(rc ==RC::RECORD_DUPLICATE_KEY)
{
rc =RC::SUCCESS;
}
RC BplusTreeScanner::next_entry(RID *rid) {
## 查找叶子节点
breakpoint set --file bplus_tree.cpp --line 284
breakpoint set --file bplus_tree.cpp --line 818
breakpoint set --file default_storage_stage.cpp --line 239
insert into t values(1,11, "a","2021-3-1",1.1);
update t set birthday='2021-3-11' where birthday='2021-3-11';
unique: result file difference(`-` is yours and `+` is base)
1. UNIQUE TEST
CREATE UNIQUE INDEX INDEX_ID ON UNIQUE_TABLE(ID);
SUCCESS
INSERT INTO UNIQUE_TABLE VALUES (2,1,1);
SUCCESS
CREATE UNIQUE INDEX INDEX_ID ON UNIQUE_TABLE(ID);
FAILURE
INSERT INTO UNIQUE_TABLE VALUES (3,2,1);
SUCCESS
INSERT INTO UNIQUE_TABLE VALUES (1,2,1);
-SUCCESS
+FAILURE