auto index = std::make_unique<BPlusTreeIndex<KeyType, ValueType, KeyComparator>>(std::move(meta), bpm_);
// Populate the index with all tuples in table heap auto *table_meta = GetTable(table_name); auto *heap = table_meta->table_.get(); for (auto tuple = heap->Begin(txn); tuple != heap->End(); ++tuple) { index->InsertEntry(tuple->KeyFromTuple(schema, key_schema, key_attrs), tuple->GetRid(), txn); }
接下来就是把索引添加到catalog_中了。
1 2 3 4 5 6 7 8 9 10 11 12 13
// Get the next OID for the new index constauto index_oid = next_index_oid_.fetch_add(1);
// Construct index information; IndexInfo takes ownership of the Index itself auto index_info = std::make_unique<IndexInfo>(key_schema, index_name, std::move(index), index_oid, table_name, keysize); auto *tmp = index_info.get();