This repository was archived by the owner on Sep 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 619
[15721] Pre-compiled catalog access #1281
Closed
Closed
Changes from all commits
Commits
Show all changes
102 commits
Select commit
Hold shift + click to select a range
273d1ec
check code path
nwang57 3981f21
add in predicate
nwang57 34d05ef
fix
nwang57 4d0a9fb
enable debug
nwang57 c60b5ba
enable debug logger
nwang57 f615a49
use seq scan for get table
nwang57 967c72a
test compile
nwang57 bb72896
fix unused
nwang57 08916ed
write table object constructor
nwang57 2784ad6
fix bug
nwang57 5fd930e
query execute
nwang57 2352d68
fix bug
nwang57 22f8dc9
fix bug
nwang57 8de72bc
fix bug
nwang57 52e7fc9
fix query param
nwang57 fa20fe1
print wrapped tuple
nwang57 7be27d4
fix bug
nwang57 b69c801
cache
ruogudu fd92290
cache
ruogudu 35b4c6d
fix try
nwang57 78bfc92
fix shared pointer
nwang57 d6088cc
clean up
nwang57 b1d6b98
GetDatabaseObject
ruogudu 11ab2e6
performance test
nwang57 ae8f6fa
merge
nwang57 6b3b90e
database_catalog
ruogudu de2b7a8
Merge branch 'pcq' of https://github.com/nwang57/peloton into pcq
ruogudu f9a0355
fix seqscan
ruogudu 0a101fe
fix
nwang57 7fa94cd
Merge branch 'pcq' of https://github.com/nwang57/peloton into pcq
ruogudu 5f2c30a
db_catalog
ruogudu bcdbd5e
db_catalog
ruogudu 308c124
fix bug
nwang57 78a64f2
Merge branch 'pcq' of https://github.com/nwang57/peloton into pcq
ruogudu a4afec2
db_catalog
ruogudu 175e81f
column_catalog.pp/h
Zeninma e687ae5
Merge branch 'pcq' of https://github.com/nwang57/peloton into HEAD
Zeninma 6309f4a
column_catalog.cpp/h
Zeninma cb0887b
index catalog
ruogudu 9de228d
lan catalog
ruogudu e17af13
column stat
nwang57 b84c4c0
lang catalog
ruogudu 6e0c12e
settings catalog
ruogudu be7abc9
trigger catalog
ruogudu a246491
zone map catalog
nwang57 b8bd9a1
zone map catalog
nwang57 74309d9
proc_catolog.cpp/h
Zeninma f12bc06
Merge branch 'pcq' of https://github.com/nwang57/peloton into pcq
Zeninma 42a1a91
delete code
ruogudu bb353ed
restore catalog test
ruogudu 38ea8ef
clean up db and trigger
nwang57 878b0c5
Merge branch 'pcq' of https://github.com/nwang57/peloton into pcq
ruogudu f1a5514
cleanup settings catalog
nwang57 97533df
delete code
ruogudu 50cf8a3
merge to master
ruogudu 6a24d11
format
ruogudu 0f8e163
fix include format
ruogudu c74f089
fix bug in scan plan by prashanth
ruogudu e69406e
Merge remote-tracking branch 'andy/master' into pcq-cp
ruogudu b2c5569
add index test
nwang57 6a3ecd9
fixed binding for tuple_value_expression, and changed query_cache_test
Zeninma e340a80
added Insert and Delete with Compiled Query in abstract_catalog and t…
Zeninma 44371e2
compiled seq plan for table catalog by looking up table_oid
nwang57 88facc3
fix trigger
nwang57 d2447ff
changed trigger_test, changed the wrong assumption that triggers are …
Zeninma 0ebfd38
fix settings catalog
ruogudu b1e1ca3
query metrics catalog
ruogudu 2a6a3a8
query metrics catalog
ruogudu 98759d7
Changed zone_map_catalog, having issue running zone_map_scan_test
Zeninma fd6eafb
Merge branch 'pcq-cp' of https://github.com/nwang57/peloton into pcq-cp
ruogudu 107b9b0
database catalog insert
ruogudu 25bb234
using expressionPtr
nwang57 371b27f
Merge branch 'pcq-cp' of https://github.com/nwang57/peloton into pcq-cp
ruogudu 2fae5d1
database catalog bound
ruogudu edeee66
index metrics catalog insert
ruogudu b7f2df2
query history catalog
ruogudu 71224a4
table metrics insert
ruogudu 22fe699
database catalog delete
ruogudu 65f0ea1
modify catalog inserts
nwang57 5b40176
Merge branch 'pcq-cp' of https://github.com/nwang57/peloton into pcq-cp
ruogudu e70be9a
change to complied insert plan
nwang57 699d400
Merge branch 'pcq-cp' of https://github.com/nwang57/peloton into pcq-cp
ruogudu 0a02fbf
intex metrics catalog delete
ruogudu 8da46b5
table metrics catalog delete
ruogudu 9c4a1ee
Edited cloumn_catalog, index_catalog, proc_catalog, settings_catalog
Zeninma b2eaf9a
Merge branch 'pcq-cp' of https://github.com/nwang57/peloton into pcq-cp
Zeninma 2d86aff
update catalog to use compiled delete plan
nwang57 6ecd138
fixed code review addressed issue
Zeninma 0572567
trigger catalog bound
ruogudu 540f8d5
table catalog bound
ruogudu 888b8c4
clean up
nwang57 e542b58
added insert, delete and bouding for zone_map_catalog
Zeninma 6924e0a
Merge branch 'pcq-cp' of https://github.com/nwang57/peloton into pcq-cp
Zeninma 9e8d8a9
language catalog bound
ruogudu 5d20500
index cache uncomment
nwang57 671367b
deleted redundant comments in index_catalog
Zeninma 7ac587e
resolved trivial conflicts
Zeninma e9440d4
Merge branch 'pcq-cp' of https://github.com/nwang57/peloton into pcq-cp
ruogudu 7ae1c5a
fix proc catalog
ruogudu 2f82391
fix proc catalog
ruogudu ee68c8d
added bind in language_catalog's delete
Zeninma 7dadd74
add comment to zone map manager
nwang57 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.