Skip to content

Commit

Permalink
Revert "Convert StorageInterface to be initialized at pipeline level …
Browse files Browse the repository at this point in the history
…instead of inside a pipeline."

This reverts commit 66fb4d2.
  • Loading branch information
lmwnshn committed Feb 22, 2021
1 parent 8e6ffc6 commit bc95c9d
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 100 deletions.
3 changes: 2 additions & 1 deletion src/execution/compiler/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1222,8 +1222,9 @@ ast::Expr *CodeGen::CSVReaderClose(ast::Expr *reader) {
return call;
}

ast::Expr *CodeGen::StorageInterfaceInit(ast::Expr *si_ptr, ast::Expr *exec_ctx, uint32_t table_oid,
ast::Expr *CodeGen::StorageInterfaceInit(ast::Identifier si, ast::Expr *exec_ctx, uint32_t table_oid,
ast::Identifier col_oids, bool need_indexes) {
ast::Expr *si_ptr = AddressOf(si);
ast::Expr *table_oid_expr = Const64(static_cast<int64_t>(table_oid));
ast::Expr *col_oids_expr = MakeExpr(col_oids);
ast::Expr *need_indexes_expr = ConstBool(need_indexes);
Expand Down
30 changes: 15 additions & 15 deletions src/execution/compiler/operator/delete_translator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace noisepage::execution::compiler {
DeleteTranslator::DeleteTranslator(const planner::DeletePlanNode &plan, CompilationContext *compilation_context,
Pipeline *pipeline)
: OperatorTranslator(plan, compilation_context, pipeline, selfdriving::ExecutionOperatingUnitType::DELETE),
deleter_(GetCodeGen()->MakeFreshIdentifier("deleter")),
col_oids_(GetCodeGen()->MakeFreshIdentifier("col_oids")) {
pipeline->RegisterSource(this, Pipeline::Parallelism::Serial);
// Prepare the child.
Expand All @@ -29,17 +30,15 @@ DeleteTranslator::DeleteTranslator(const planner::DeletePlanNode &plan, Compilat
}

num_deletes_ = CounterDeclare("num_deletes", pipeline);
ast::Expr *storage_interface_type = GetCodeGen()->BuiltinType(ast::BuiltinType::StorageInterface);
si_deleter_ = pipeline->DeclarePipelineStateEntry("storageInterface", storage_interface_type);
}

void DeleteTranslator::InitializePipelineState(const Pipeline &pipeline, FunctionBuilder *function) const {
DeclareDeleter(function);
CounterSet(function, num_deletes_, 0);
}

void DeleteTranslator::PerformPipelineWork(WorkContext *context, FunctionBuilder *function) const {
// Delete from table
DeclareDeleter(function);
GenTableDelete(function);
function->Append(GetCodeGen()->ExecCtxAddRowsAffected(GetExecutionContext(), 1));

Expand All @@ -49,9 +48,7 @@ void DeleteTranslator::PerformPipelineWork(WorkContext *context, FunctionBuilder
for (const auto &index_oid : indexes) {
GenIndexDelete(function, context, index_oid);
}
}

void DeleteTranslator::TearDownPipelineState(const Pipeline &pipeline, FunctionBuilder *function) const {
GenDeleterFree(function);
}

Expand All @@ -66,27 +63,30 @@ void DeleteTranslator::FinishPipelineWork(const Pipeline &pipeline, FunctionBuil
void DeleteTranslator::DeclareDeleter(FunctionBuilder *builder) const {
// var col_oids : [0]uint32
SetOids(builder);
// @storageInterfaceInit(&pipelineState.storageInterface, execCtx, table_oid, col_oids, true)
// var deleter : StorageInterface
auto *storage_interface_type = GetCodeGen()->BuiltinType(ast::BuiltinType::Kind::StorageInterface);
builder->Append(GetCodeGen()->DeclareVarNoInit(deleter_, storage_interface_type));
// @storageInterfaceInit(&deleter, execCtx, table_oid, col_oids, true)
const auto &op = GetPlanAs<planner::DeletePlanNode>();
ast::Expr *deleter_setup = GetCodeGen()->StorageInterfaceInit(si_deleter_.GetPtr(GetCodeGen()), GetExecutionContext(),
ast::Expr *deleter_setup = GetCodeGen()->StorageInterfaceInit(deleter_, GetExecutionContext(),
op.GetTableOid().UnderlyingValue(), col_oids_, true);
builder->Append(GetCodeGen()->MakeStmt(deleter_setup));
}

void DeleteTranslator::GenDeleterFree(FunctionBuilder *builder) const {
// @storageInterfaceFree(&pipelineState.storageInterface)
// @storageInterfaceFree(&deleter)
ast::Expr *deleter_free =
GetCodeGen()->CallBuiltin(ast::Builtin::StorageInterfaceFree, {si_deleter_.GetPtr(GetCodeGen())});
GetCodeGen()->CallBuiltin(ast::Builtin::StorageInterfaceFree, {GetCodeGen()->AddressOf(deleter_)});
builder->Append(GetCodeGen()->MakeStmt(deleter_free));
}

void DeleteTranslator::GenTableDelete(FunctionBuilder *builder) const {
// if (!@tableDelete(&pipelineState.storageInterface, &slot)) { Abort(); }
// if (!@tableDelete(&deleter, &slot)) { Abort(); }
const auto &op = GetPlanAs<planner::DeletePlanNode>();
const auto &child = GetCompilationContext()->LookupTranslator(*op.GetChild(0));
NOISEPAGE_ASSERT(child != nullptr, "delete should have a child");
const auto &delete_slot = child->GetSlotAddress();
std::vector<ast::Expr *> delete_args{si_deleter_.GetPtr(GetCodeGen()), delete_slot};
std::vector<ast::Expr *> delete_args{GetCodeGen()->AddressOf(deleter_), delete_slot};
auto *delete_call = GetCodeGen()->CallBuiltin(ast::Builtin::TableDelete, delete_args);
auto *delete_failed = GetCodeGen()->UnaryOp(parsing::Token::Type::BANG, delete_call);
If check(builder, delete_failed);
Expand All @@ -102,9 +102,9 @@ void DeleteTranslator::GenTableDelete(FunctionBuilder *builder) const {

void DeleteTranslator::GenIndexDelete(FunctionBuilder *builder, WorkContext *context,
const catalog::index_oid_t &index_oid) const {
// var delete_index_pr = @getIndexPR(&pipelineState.storageInterface, oid)
// var delete_index_pr = @getIndexPR(&deleter, oid)
auto delete_index_pr = GetCodeGen()->MakeFreshIdentifier("delete_index_pr");
std::vector<ast::Expr *> pr_call_args{si_deleter_.GetPtr(GetCodeGen()),
std::vector<ast::Expr *> pr_call_args{GetCodeGen()->AddressOf(deleter_),
GetCodeGen()->Const32(index_oid.UnderlyingValue())};
auto *get_index_pr_call = GetCodeGen()->CallBuiltin(ast::Builtin::GetIndexPR, pr_call_args);
builder->Append(GetCodeGen()->DeclareVar(delete_index_pr, nullptr, get_index_pr_call));
Expand All @@ -126,8 +126,8 @@ void DeleteTranslator::GenIndexDelete(FunctionBuilder *builder, WorkContext *con
builder->Append(GetCodeGen()->MakeStmt(pr_set_call));
}

// @indexDelete(&pipelineState.storageInterface)
std::vector<ast::Expr *> delete_args{si_deleter_.GetPtr(GetCodeGen()), child->GetSlotAddress()};
// @indexDelete(&deleter)
std::vector<ast::Expr *> delete_args{GetCodeGen()->AddressOf(deleter_), child->GetSlotAddress()};
auto *index_delete_call = GetCodeGen()->CallBuiltin(ast::Builtin::IndexDelete, delete_args);
builder->Append(GetCodeGen()->MakeStmt(index_delete_call));
}
Expand Down
52 changes: 28 additions & 24 deletions src/execution/compiler/operator/insert_translator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace noisepage::execution::compiler {
InsertTranslator::InsertTranslator(const planner::InsertPlanNode &plan, CompilationContext *compilation_context,
Pipeline *pipeline)
: OperatorTranslator(plan, compilation_context, pipeline, selfdriving::ExecutionOperatingUnitType::INSERT),
inserter_(GetCodeGen()->MakeFreshIdentifier("inserter")),
insert_pr_(GetCodeGen()->MakeFreshIdentifier("insert_pr")),
col_oids_(GetCodeGen()->MakeFreshIdentifier("col_oids")),
table_schema_(GetCodeGen()->GetCatalogAccessor()->GetSchema(GetPlanAs<planner::InsertPlanNode>().GetTableOid())),
Expand All @@ -44,28 +45,27 @@ InsertTranslator::InsertTranslator(const planner::InsertPlanNode &plan, Compilat
}

num_inserts_ = CounterDeclare("num_inserts", pipeline);
ast::Expr *storage_interface_type = GetCodeGen()->BuiltinType(ast::BuiltinType::StorageInterface);
si_inserter_ = pipeline->DeclarePipelineStateEntry("storageInterface", storage_interface_type);
}

void InsertTranslator::InitializePipelineState(const Pipeline &pipeline, FunctionBuilder *function) const {
// var col_oids: [num_cols]uint32
// col_oids[i] = ...
// @storageInterfaceInit(&pipelineState.storageInterface, execCtx, table_oid, col_oids, true)
DeclareInserter(function);
CounterSet(function, num_inserts_, 0);
}

void InsertTranslator::PerformPipelineWork(WorkContext *context, FunctionBuilder *function) const {
// var col_oids: [num_cols]uint32
// col_oids[i] = ...
// var inserter : StorageInterface
// @storageInterfaceInit(inserter, execCtx, table_oid, col_oids, true)
DeclareInserter(function);
// var insert_pr : *ProjectedRow
DeclareInsertPR(function);

for (uint32_t idx = 0; idx < GetPlanAs<planner::InsertPlanNode>().GetBulkInsertCount(); idx++) {
// var insert_pr = @getTablePR(&pipelineState.storageInterface)
// var insert_pr = @getTablePR(&inserter)
GetInsertPR(function);
// For each attribute, @prSet(insert_pr, ...)
GenSetTablePR(function, context, idx);
// var insert_slot = @tableInsert(&pipelineState.storageInterface)
// var insert_slot = @tableInsert(&inserter)
GenTableInsert(function);
function->Append(GetCodeGen()->ExecCtxAddRowsAffected(GetExecutionContext(), 1));
const auto &index_oids = GetPlanAs<planner::InsertPlanNode>().GetIndexOids();
Expand All @@ -81,27 +81,28 @@ void InsertTranslator::PerformPipelineWork(WorkContext *context, FunctionBuilder
selfdriving::ExecutionOperatingUnitFeatureAttribute::CARDINALITY, context->GetPipeline(),
CounterVal(num_inserts_));
FeatureArithmeticRecordMul(function, context->GetPipeline(), GetTranslatorId(), CounterVal(num_inserts_));
}

void InsertTranslator::TearDownPipelineState(const Pipeline &pipeline, FunctionBuilder *function) const {
GenInserterFree(function);
}

void InsertTranslator::DeclareInserter(noisepage::execution::compiler::FunctionBuilder *builder) const {
// var col_oids: [num_cols]uint32
// col_oids[i] = ...
SetOids(builder);
// @storageInterfaceInit(&pipeline.storageInterface, execCtx, table_oid, col_oids, true)
// var inserter : StorageInterface
auto *storage_interface_type = GetCodeGen()->BuiltinType(ast::BuiltinType::Kind::StorageInterface);
builder->Append(GetCodeGen()->DeclareVar(inserter_, storage_interface_type, nullptr));
// @storageInterfaceInit(inserter, execCtx, table_oid, col_oids, true)
ast::Expr *inserter_setup = GetCodeGen()->StorageInterfaceInit(
si_inserter_.GetPtr(GetCodeGen()), GetExecutionContext(),
GetPlanAs<planner::InsertPlanNode>().GetTableOid().UnderlyingValue(), col_oids_, true);
inserter_, GetExecutionContext(), GetPlanAs<planner::InsertPlanNode>().GetTableOid().UnderlyingValue(), col_oids_,
true);
builder->Append(GetCodeGen()->MakeStmt(inserter_setup));
}

void InsertTranslator::GenInserterFree(noisepage::execution::compiler::FunctionBuilder *builder) const {
// Call @storageInterfaceFree(&pipelineState.storageInterface)
// Call @storageInterfaceFree
ast::Expr *inserter_free =
GetCodeGen()->CallBuiltin(ast::Builtin::StorageInterfaceFree, {si_inserter_.GetPtr(GetCodeGen())});
GetCodeGen()->CallBuiltin(ast::Builtin::StorageInterfaceFree, {GetCodeGen()->AddressOf(inserter_)});
builder->Append(GetCodeGen()->MakeStmt(inserter_free));
}

Expand Down Expand Up @@ -139,8 +140,8 @@ void InsertTranslator::DeclareInsertPR(noisepage::execution::compiler::FunctionB
}

void InsertTranslator::GetInsertPR(noisepage::execution::compiler::FunctionBuilder *builder) const {
// var insert_pr = @getTablePR(&pipelineState.storageInterface)
auto *get_pr_call = GetCodeGen()->CallBuiltin(ast::Builtin::GetTablePR, {si_inserter_.GetPtr(GetCodeGen())});
// var insert_pr = @getTablePR(&inserter)
auto *get_pr_call = GetCodeGen()->CallBuiltin(ast::Builtin::GetTablePR, {GetCodeGen()->AddressOf(inserter_)});
builder->Append(GetCodeGen()->Assign(GetCodeGen()->MakeExpr(insert_pr_), get_pr_call));
}

Expand All @@ -161,19 +162,19 @@ void InsertTranslator::GenSetTablePR(FunctionBuilder *builder, WorkContext *cont
}

void InsertTranslator::GenTableInsert(FunctionBuilder *builder) const {
// var insert_slot = @tableInsert(&pipelineState.storageInterface)
// var insert_slot = @tableInsert(&inserter)
const auto &insert_slot = GetCodeGen()->MakeFreshIdentifier("insert_slot");
auto *insert_call = GetCodeGen()->CallBuiltin(ast::Builtin::TableInsert, {si_inserter_.GetPtr(GetCodeGen())});
auto *insert_call = GetCodeGen()->CallBuiltin(ast::Builtin::TableInsert, {GetCodeGen()->AddressOf(inserter_)});
builder->Append(GetCodeGen()->DeclareVar(insert_slot, nullptr, insert_call));

CounterAdd(builder, num_inserts_, 1);
}

void InsertTranslator::GenIndexInsert(WorkContext *context, FunctionBuilder *builder,
const catalog::index_oid_t &index_oid) const {
// var insert_index_pr = @getIndexPR(&pipelineState.storageInterface, oid)
// var insert_index_pr = @getIndexPR(&inserter, oid)
const auto &insert_index_pr = GetCodeGen()->MakeFreshIdentifier("insert_index_pr");
std::vector<ast::Expr *> pr_call_args{si_inserter_.GetPtr(GetCodeGen()),
std::vector<ast::Expr *> pr_call_args{GetCodeGen()->AddressOf(inserter_),
GetCodeGen()->Const32(index_oid.UnderlyingValue())};
auto *get_index_pr_call = GetCodeGen()->CallBuiltin(ast::Builtin::GetIndexPR, pr_call_args);
builder->Append(GetCodeGen()->DeclareVar(insert_index_pr, nullptr, get_index_pr_call));
Expand All @@ -193,12 +194,15 @@ void InsertTranslator::GenIndexInsert(WorkContext *context, FunctionBuilder *bui
builder->Append(GetCodeGen()->MakeStmt(set_key_call));
}

// if (!@indexInsert(&pipelineState.storageInterface)) { abortTxn(queryState.execCtx); }
// if (!@indexInsert(&inserter)) { storageInterfaceFree(&inserter); abortTxn(queryState.execCtx); }
const auto &builtin = index_schema.Unique() ? ast::Builtin::IndexInsertUnique : ast::Builtin::IndexInsert;
auto *index_insert_call = GetCodeGen()->CallBuiltin(builtin, {si_inserter_.GetPtr(GetCodeGen())});
auto *index_insert_call = GetCodeGen()->CallBuiltin(builtin, {GetCodeGen()->AddressOf(inserter_)});
auto *cond = GetCodeGen()->UnaryOp(parsing::Token::Type::BANG, index_insert_call);
If success(builder, cond);
{ builder->Append(GetCodeGen()->AbortTxn(GetExecutionContext())); }
{
GenInserterFree(builder);
builder->Append(GetCodeGen()->AbortTxn(GetExecutionContext()));
}
success.EndIf();
}

Expand Down
Loading

0 comments on commit bc95c9d

Please sign in to comment.