Skip to content

Commit

Permalink
update delete index_scan exec
Browse files Browse the repository at this point in the history
  • Loading branch information
chagelo committed Jan 16, 2024
1 parent 4a721ee commit b9361b9
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 13 deletions.
45 changes: 42 additions & 3 deletions src/execution/delete_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,57 @@
//
//===----------------------------------------------------------------------===//

#include <cstdint>
#include <memory>

#include "common/config.h"
#include "execution/executors/delete_executor.h"
#include "storage/table/tuple.h"
#include "type/type_id.h"
#include "type/value.h"

namespace bustub {

DeleteExecutor::DeleteExecutor(ExecutorContext *exec_ctx, const DeletePlanNode *plan,
std::unique_ptr<AbstractExecutor> &&child_executor)
: AbstractExecutor(exec_ctx) {}
: AbstractExecutor(exec_ctx), plan_(plan), child_executor_(child_executor.release()) {}

void DeleteExecutor::Init() { throw NotImplementedException("DeleteExecutor is not implemented"); }
void DeleteExecutor::Init() {
child_executor_->Init();
table_info_ = exec_ctx_->GetCatalog()->GetTable(plan_->TableOid());
index_info_ = exec_ctx_->GetCatalog()->GetTableIndexes(table_info_->name_);
}

auto DeleteExecutor::Next([[maybe_unused]] Tuple *tuple, RID *rid) -> bool { return false; }
auto DeleteExecutor::Next(Tuple *tuple, RID *rid) -> bool {
if (is_ok_) {
return false;
}

if (table_info_->schema_.GetColumnCount() != child_executor_->GetOutputSchema().GetColumnCount()) {
return false;
}

auto count = 0;
while (child_executor_->Next(tuple, rid)) {
if (rid->GetPageId() == INVALID_PAGE_ID) {
continue;
}

auto tuple_meta = table_info_->table_->GetTupleMeta(*rid);
tuple_meta.is_deleted_ = true;
table_info_->table_->UpdateTupleMeta(tuple_meta, *rid);

for (auto &index : index_info_) {
auto delete_key = tuple->KeyFromTuple(table_info_->schema_, index->key_schema_, index->index_->GetKeyAttrs());
index->index_->DeleteEntry(delete_key, *rid, nullptr);
}

count++;
}
is_ok_ = true;
auto shema = GetOutputSchema();
*tuple = Tuple{std::vector<Value>{{TypeId::INTEGER, count}}, &shema};
return true;
}

} // namespace bustub
5 changes: 1 addition & 4 deletions src/execution/index_scan_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ IndexScanExecutor::IndexScanExecutor(ExecutorContext *exec_ctx, const IndexScanP
void IndexScanExecutor::Init() {}

auto IndexScanExecutor::Next(Tuple *tuple, RID *rid) -> bool {
std::cout << index_info_->key_size_ << " " << index_info_->index_oid_ << " " << plan_->OutputSchema().ToString() << " " << std::endl;
std::cout << index_info_->key_schema_.ToString() << std::endl;

for (; !iter_.IsEnd(); ) {
for (; !iter_.IsEnd();) {
*rid = (*iter_).second;
++iter_;
auto [tuple_meta, tmp_tuple] = table_info_->table_->GetTuple(*rid);
Expand Down
4 changes: 4 additions & 0 deletions src/include/execution/executors/delete_executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <utility>
#include <vector>

#include "catalog/catalog.h"
#include "execution/executor_context.h"
#include "execution/executors/abstract_executor.h"
#include "execution/plans/delete_plan.h"
Expand Down Expand Up @@ -60,5 +61,8 @@ class DeleteExecutor : public AbstractExecutor {
const DeletePlanNode *plan_;
/** The child executor from which RIDs for deleted tuples are pulled */
std::unique_ptr<AbstractExecutor> child_executor_;
TableInfo *table_info_;
std::vector<IndexInfo *> index_info_;
bool is_ok_{false};
};
} // namespace bustub
6 changes: 0 additions & 6 deletions test/sql/p3.07-simple-agg.slt
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
# 4 pts

# How many TAs are there in 2023 Spring?
query
select count(*) from __mock_table_tas_2023;
----
9

# The real test process begins...

# Create a table
Expand Down

0 comments on commit b9361b9

Please sign in to comment.