-
Couldn't load subscription status.
- Fork 619
[15721] Pre-compiled catalog access #1281
Changes from all commits
273d1ec
3981f21
34d05ef
4d0a9fb
c60b5ba
f615a49
967c72a
bb72896
08916ed
2784ad6
5fd930e
2352d68
22f8dc9
8de72bc
52e7fc9
fa20fe1
7be27d4
b69c801
fd92290
35b4c6d
78bfc92
d6088cc
b1d6b98
11ab2e6
ae8f6fa
6b3b90e
de2b7a8
f9a0355
0a101fe
7fa94cd
5f2c30a
bcdbd5e
308c124
78a64f2
a4afec2
175e81f
e687ae5
6309f4a
cb0887b
9de228d
e17af13
b84c4c0
6e0c12e
be7abc9
a246491
b8bd9a1
74309d9
f12bc06
42a1a91
bb353ed
38ea8ef
878b0c5
f1a5514
97533df
50cf8a3
6a24d11
0f8e163
c74f089
e69406e
b2c5569
6a3ecd9
e340a80
44371e2
88facc3
d2447ff
0ebfd38
b1e1ca3
2a6a3a8
98759d7
fd6eafb
107b9b0
25bb234
371b27f
2fae5d1
edeee66
b7f2df2
71224a4
22fe699
65f0ea1
5b40176
e70be9a
699d400
0a02fbf
8da46b5
9c4a1ee
b2eaf9a
2d86aff
6ecd138
0572567
540f8d5
888b8c4
e542b58
6924e0a
9e8d8a9
5d20500
671367b
7ac587e
e9440d4
7ae1c5a
2f82391
ee68c8d
7dadd74
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,9 @@ | |
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "catalog/abstract_catalog.h" | ||
|
|
||
| #include "executor/plan_executor.h" | ||
| #include "codegen/buffering_consumer.h" | ||
| #include "common/internal_types.h" | ||
| #include "common/statement.h" | ||
|
|
||
| #include "catalog/catalog.h" | ||
|
|
@@ -103,6 +105,58 @@ bool AbstractCatalog::InsertTuple(std::unique_ptr<storage::Tuple> tuple, | |
| return status; | ||
| } | ||
|
|
||
| /*@brief insert tuple(reord) helper function | ||
| * @param tuple tuple to be inserted | ||
| * @param txn TransactionContext | ||
| * @return Whether insertion is Successful | ||
| */ | ||
| bool AbstractCatalog::InsertTupleWithCompiledPlan(const std::vector<std::vector< | ||
| std::unique_ptr<expression::AbstractExpression>>> *insert_values, | ||
| concurrency::TransactionContext *txn) { | ||
| if (txn == nullptr) | ||
| throw CatalogException("Insert tuple requires transaction"); | ||
|
|
||
| std::vector<std::string> columns; | ||
| std::shared_ptr<planner::InsertPlan> insert_plan( | ||
| new planner::InsertPlan(catalog_table_, &columns, insert_values)); | ||
|
|
||
| // Bind the plan | ||
| planner::BindingContext context; | ||
| insert_plan->PerformBinding(context); | ||
|
|
||
| // Prepare a consumer to collect the result | ||
| codegen::BufferingConsumer buffer{{}, context}; | ||
|
|
||
|
|
||
| bool cached; | ||
|
|
||
| codegen::QueryParameters parameters(*insert_plan, {}); | ||
| std::unique_ptr<executor::ExecutorContext> executor_context( | ||
| new executor::ExecutorContext(txn, std::move(parameters))); | ||
|
|
||
| // search for query | ||
| codegen::Query *query = codegen::QueryCache::Instance().Find(insert_plan);; | ||
| std::unique_ptr<codegen::Query> compiled_query(nullptr); | ||
| cached = (query != nullptr); | ||
| // cached = false; | ||
| // LOG_DEBUG("cache %d", cached); | ||
| // if not cached, compile the query and save it into cache | ||
| executor::ExecutionResult ret; | ||
| if (!cached) { | ||
| compiled_query = codegen::QueryCompiler().Compile( | ||
| *insert_plan, executor_context->GetParams().GetQueryParametersMap(), | ||
| buffer); | ||
| query = compiled_query.get(); | ||
| codegen::QueryCache::Instance().Add(insert_plan, std::move(compiled_query)); | ||
| } | ||
|
|
||
| query->Execute(std::move(executor_context), buffer, | ||
| [&ret](executor::ExecutionResult result) { ret = result; }); | ||
|
|
||
| return ret.m_result == peloton::ResultType::SUCCESS; | ||
| } | ||
|
|
||
|
|
||
| /*@brief Delete a tuple using index scan | ||
| * @param index_offset Offset of index for scan | ||
| * @param values Values for search | ||
|
|
@@ -152,6 +206,63 @@ bool AbstractCatalog::DeleteWithIndexScan( | |
| return status; | ||
| } | ||
|
|
||
|
|
||
| /*@brief Delete a tuple using index scan | ||
| * @param index_offset Offset of index for scan | ||
| * @param values Values for search | ||
| * @param txn TransactionContext | ||
| * @return Whether deletion is Successful | ||
| */ | ||
| bool AbstractCatalog::DeleteWithCompiledSeqScan( | ||
| std::vector<oid_t> column_offsets, | ||
| expression::AbstractExpression *predicate, | ||
| concurrency::TransactionContext *txn) { | ||
| if (txn == nullptr) | ||
| throw CatalogException("Delete tuple requires transaction"); | ||
|
|
||
| std::shared_ptr<planner::DeletePlan> delete_plan{ | ||
| new planner::DeletePlan(catalog_table_)}; | ||
|
|
||
| std::unique_ptr<planner::AbstractPlan> scan{new planner::SeqScanPlan( | ||
| catalog_table_, predicate, column_offsets)}; | ||
| delete_plan->AddChild(std::move(scan)); | ||
|
|
||
| // Do binding | ||
| planner::BindingContext context; | ||
| delete_plan->PerformBinding(context); | ||
|
|
||
| codegen::BufferingConsumer buffer{column_offsets, context}; | ||
|
|
||
| bool cached; | ||
|
|
||
| codegen::QueryParameters parameters(*delete_plan, {}); | ||
| std::unique_ptr<executor::ExecutorContext> executor_context( | ||
| new executor::ExecutorContext(txn, std::move(parameters))); | ||
|
|
||
| // search for query | ||
| codegen::Query *query = codegen::QueryCache::Instance().Find(delete_plan);; | ||
| std::unique_ptr<codegen::Query> compiled_query(nullptr); | ||
| cached = (query != nullptr); | ||
|
|
||
| // if not cached, compile the query and save it into cache | ||
| executor::ExecutionResult ret; | ||
| if (!cached) { | ||
| compiled_query = codegen::QueryCompiler().Compile( | ||
| *delete_plan, executor_context->GetParams().GetQueryParametersMap(), | ||
| buffer); | ||
| query = compiled_query.get(); | ||
| codegen::QueryCache::Instance().Add(delete_plan, std::move(compiled_query)); | ||
| } | ||
|
|
||
| query->Execute(std::move(executor_context), buffer, | ||
| [&ret](executor::ExecutionResult result) { ret = result; }); | ||
|
|
||
| return ret.m_result == peloton::ResultType::SUCCESS; | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
| /*@brief Index scan helper function | ||
| * @param column_offsets Column ids for search (projection) | ||
| * @param index_offset Offset of index for scan | ||
|
|
@@ -235,6 +346,56 @@ AbstractCatalog::GetResultWithSeqScan(std::vector<oid_t> column_offsets, | |
| return result_tiles; | ||
| } | ||
|
|
||
| /*@brief Complied Sequential scan helper function | ||
| * NOTE: try to use efficient index scan instead of sequential scan, but you | ||
| * shouldn't build too many indexes on one catalog table | ||
| * @param column_offsets Column ids for search (projection) | ||
| * @param predicate predicate for this sequential scan query | ||
| * @param txn TransactionContext | ||
| * | ||
| * @return Unique pointer of vector of logical tiles | ||
| */ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move the doxygen comments to the header file. |
||
| std::vector<codegen::WrappedTuple> | ||
| AbstractCatalog::GetResultWithCompiledSeqScan( | ||
| std::vector<oid_t> column_offsets, | ||
| expression::AbstractExpression *predicate, | ||
| concurrency::TransactionContext *txn) const { | ||
| if (txn == nullptr) throw CatalogException("Scan table requires transaction"); | ||
|
|
||
| // Create sequential scan | ||
| auto plan_ptr = std::make_shared<planner::SeqScanPlan>( | ||
| catalog_table_, predicate, column_offsets); | ||
| planner::BindingContext scan_context; | ||
| plan_ptr->PerformBinding(scan_context); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a test if you've fixed the binding bug. |
||
|
|
||
| // Create consumer | ||
| codegen::BufferingConsumer buffer{column_offsets, scan_context}; | ||
| bool cached; | ||
|
|
||
| codegen::QueryParameters parameters(*plan_ptr, {}); | ||
| std::unique_ptr<executor::ExecutorContext> executor_context( | ||
| new executor::ExecutorContext(txn, std::move(parameters))); | ||
|
|
||
| // search for query | ||
| codegen::Query *query = codegen::QueryCache::Instance().Find(plan_ptr); | ||
| std::unique_ptr<codegen::Query> compiled_query(nullptr); | ||
| cached = (query != nullptr); | ||
|
|
||
| // if not cached, compile the query and save it into cache | ||
| if (!cached) { | ||
| compiled_query = codegen::QueryCompiler().Compile( | ||
| *plan_ptr, executor_context->GetParams().GetQueryParametersMap(), | ||
| buffer); | ||
| query = compiled_query.get(); | ||
| codegen::QueryCache::Instance().Add(plan_ptr, std::move(compiled_query)); | ||
| } | ||
|
|
||
| query->Execute(std::move(executor_context), buffer, | ||
| [](executor::ExecutionResult result) { return result; }); | ||
|
|
||
| return buffer.GetOutputTuples(); | ||
| } | ||
|
|
||
| /*@brief Add index on catalog table | ||
| * @param key_attrs indexed column offset(position) | ||
| * @param index_oid index id(global unique) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -148,12 +148,12 @@ void Catalog::Bootstrap() { | |
| DatabaseMetricsCatalog::GetInstance(txn); | ||
| TableMetricsCatalog::GetInstance(txn); | ||
| IndexMetricsCatalog::GetInstance(txn); | ||
| QueryMetricsCatalog::GetInstance(txn); | ||
| QueryMetricsCatalog::GetInstance(txn); | ||
| SettingsCatalog::GetInstance(txn); | ||
| TriggerCatalog::GetInstance(txn); | ||
| LanguageCatalog::GetInstance(txn); | ||
| ProcCatalog::GetInstance(txn); | ||
|
|
||
| if (settings::SettingsManager::GetBool(settings::SettingId::brain)) { | ||
| QueryHistoryCatalog::GetInstance(txn); | ||
| } | ||
|
|
@@ -552,14 +552,12 @@ ResultType Catalog::DropTable(const std::string &database_name, | |
| */ | ||
| ResultType Catalog::DropTable(oid_t database_oid, oid_t table_oid, | ||
| concurrency::TransactionContext *txn) { | ||
| LOG_TRACE("Dropping table %d from database %d", database_oid, table_oid); | ||
| auto storage_manager = storage::StorageManager::GetInstance(); | ||
| auto database = storage_manager->GetDatabaseWithOid(database_oid); | ||
| auto database_object = | ||
| DatabaseCatalog::GetInstance()->GetDatabaseObject(database_oid, txn); | ||
| auto table_object = database_object->GetTableObject(table_oid); | ||
| auto index_objects = table_object->GetIndexObjects(); | ||
| LOG_TRACE("dropping #%d indexes", (int)index_objects.size()); | ||
|
|
||
| for (auto it : index_objects) DropIndex(it.second->GetIndexOid(), txn); | ||
| ColumnCatalog::GetInstance()->DeleteColumns(table_oid, txn); | ||
|
|
@@ -614,18 +612,18 @@ ResultType Catalog::DropIndex(oid_t index_oid, | |
|
|
||
| ResultType Catalog::DropIndex(const std::string &index_name, | ||
| concurrency::TransactionContext *txn) { | ||
| if(txn == nullptr) { | ||
| throw CatalogException("Do not have transaction to drop index " + | ||
| index_name); | ||
| } | ||
| auto index_object = catalog::IndexCatalog::GetInstance()->GetIndexObject( | ||
| index_name, txn); | ||
| if(index_object == nullptr) { | ||
| throw CatalogException("Index name " + index_name + " cannot be found"); | ||
| } | ||
| ResultType result = DropIndex(index_object->GetIndexOid(), txn); | ||
| if (txn == nullptr) { | ||
| throw CatalogException("Do not have transaction to drop index " + | ||
| index_name); | ||
| } | ||
| auto index_object = | ||
| catalog::IndexCatalog::GetInstance()->GetIndexObject(index_name, txn); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will change once #1302 is merged. |
||
| if (index_object == nullptr) { | ||
| throw CatalogException("Index name " + index_name + " cannot be found"); | ||
| } | ||
| ResultType result = DropIndex(index_object->GetIndexOid(), txn); | ||
|
|
||
| return result; | ||
| return result; | ||
| } | ||
|
|
||
| //===--------------------------------------------------------------------===// | ||
|
|
@@ -1064,11 +1062,11 @@ void Catalog::InitializeFunctions() { | |
| /** | ||
| * decimal functions | ||
| */ | ||
| AddBuiltinFunction( | ||
| "abs", {type::TypeId::DECIMAL}, type::TypeId::DECIMAL, internal_lang, | ||
| "Abs", function::BuiltInFuncType{OperatorId::Abs, | ||
| function::DecimalFunctions::_Abs}, | ||
| txn); | ||
| AddBuiltinFunction("abs", {type::TypeId::DECIMAL}, type::TypeId::DECIMAL, | ||
| internal_lang, "Abs", | ||
| function::BuiltInFuncType{ | ||
| OperatorId::Abs, function::DecimalFunctions::_Abs}, | ||
| txn); | ||
| AddBuiltinFunction( | ||
| "sqrt", {type::TypeId::TINYINT}, type::TypeId::DECIMAL, internal_lang, | ||
| "Sqrt", function::BuiltInFuncType{OperatorId::Sqrt, | ||
|
|
@@ -1105,33 +1103,29 @@ void Catalog::InitializeFunctions() { | |
| /** | ||
| * integer functions | ||
| */ | ||
| AddBuiltinFunction( | ||
| "abs", {type::TypeId::TINYINT}, type::TypeId::TINYINT, | ||
| internal_lang, "Abs", | ||
| function::BuiltInFuncType{OperatorId::Abs, | ||
| function::DecimalFunctions::_Abs}, | ||
| txn); | ||
| AddBuiltinFunction("abs", {type::TypeId::TINYINT}, type::TypeId::TINYINT, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary reformatting. |
||
| internal_lang, "Abs", | ||
| function::BuiltInFuncType{ | ||
| OperatorId::Abs, function::DecimalFunctions::_Abs}, | ||
| txn); | ||
|
|
||
| AddBuiltinFunction( | ||
| "abs", {type::TypeId::SMALLINT}, type::TypeId::SMALLINT, | ||
| internal_lang, "Abs", | ||
| function::BuiltInFuncType{OperatorId::Abs, | ||
| function::DecimalFunctions::_Abs}, | ||
| txn); | ||
| AddBuiltinFunction("abs", {type::TypeId::SMALLINT}, | ||
| type::TypeId::SMALLINT, internal_lang, "Abs", | ||
| function::BuiltInFuncType{ | ||
| OperatorId::Abs, function::DecimalFunctions::_Abs}, | ||
| txn); | ||
|
|
||
| AddBuiltinFunction( | ||
| "abs", {type::TypeId::INTEGER}, type::TypeId::INTEGER, | ||
| internal_lang, "Abs", | ||
| function::BuiltInFuncType{OperatorId::Abs, | ||
| function::DecimalFunctions::_Abs}, | ||
| txn); | ||
| AddBuiltinFunction("abs", {type::TypeId::INTEGER}, type::TypeId::INTEGER, | ||
| internal_lang, "Abs", | ||
| function::BuiltInFuncType{ | ||
| OperatorId::Abs, function::DecimalFunctions::_Abs}, | ||
| txn); | ||
|
|
||
| AddBuiltinFunction( | ||
| "abs", {type::TypeId::BIGINT}, type::TypeId::BIGINT, | ||
| internal_lang, "Abs", | ||
| function::BuiltInFuncType{OperatorId::Abs, | ||
| function::DecimalFunctions::_Abs}, | ||
| txn); | ||
| AddBuiltinFunction("abs", {type::TypeId::BIGINT}, type::TypeId::BIGINT, | ||
| internal_lang, "Abs", | ||
| function::BuiltInFuncType{ | ||
| OperatorId::Abs, function::DecimalFunctions::_Abs}, | ||
| txn); | ||
|
|
||
| AddBuiltinFunction( | ||
| "floor", {type::TypeId::INTEGER}, type::TypeId::DECIMAL, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove dead code.