Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

[15721] Pre-compiled catalog access #1281

Closed
wants to merge 102 commits into from
Closed
Show file tree
Hide file tree
Changes from 60 commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
273d1ec
check code path
nwang57 Mar 24, 2018
3981f21
add in predicate
nwang57 Mar 25, 2018
34d05ef
fix
nwang57 Mar 25, 2018
4d0a9fb
enable debug
nwang57 Mar 25, 2018
c60b5ba
enable debug logger
nwang57 Mar 25, 2018
f615a49
use seq scan for get table
nwang57 Mar 25, 2018
967c72a
test compile
nwang57 Mar 29, 2018
bb72896
fix unused
nwang57 Mar 29, 2018
08916ed
write table object constructor
nwang57 Mar 29, 2018
2784ad6
fix bug
nwang57 Mar 29, 2018
5fd930e
query execute
nwang57 Mar 29, 2018
2352d68
fix bug
nwang57 Mar 29, 2018
22f8dc9
fix bug
nwang57 Apr 7, 2018
8de72bc
fix bug
nwang57 Apr 7, 2018
52e7fc9
fix query param
nwang57 Apr 7, 2018
fa20fe1
print wrapped tuple
nwang57 Apr 7, 2018
7be27d4
fix bug
nwang57 Apr 7, 2018
b69c801
cache
ruogudu Apr 7, 2018
fd92290
cache
ruogudu Apr 7, 2018
35b4c6d
fix try
nwang57 Apr 7, 2018
78bfc92
fix shared pointer
nwang57 Apr 7, 2018
d6088cc
clean up
nwang57 Apr 7, 2018
b1d6b98
GetDatabaseObject
ruogudu Apr 7, 2018
11ab2e6
performance test
nwang57 Apr 7, 2018
ae8f6fa
merge
nwang57 Apr 7, 2018
6b3b90e
database_catalog
ruogudu Apr 8, 2018
de2b7a8
Merge branch 'pcq' of https://github.com/nwang57/peloton into pcq
ruogudu Apr 8, 2018
f9a0355
fix seqscan
ruogudu Apr 8, 2018
0a101fe
fix
nwang57 Apr 8, 2018
7fa94cd
Merge branch 'pcq' of https://github.com/nwang57/peloton into pcq
ruogudu Apr 8, 2018
5f2c30a
db_catalog
ruogudu Apr 8, 2018
bcdbd5e
db_catalog
ruogudu Apr 8, 2018
308c124
fix bug
nwang57 Apr 8, 2018
78a64f2
Merge branch 'pcq' of https://github.com/nwang57/peloton into pcq
ruogudu Apr 8, 2018
a4afec2
db_catalog
ruogudu Apr 8, 2018
175e81f
column_catalog.pp/h
Zeninma Apr 8, 2018
e687ae5
Merge branch 'pcq' of https://github.com/nwang57/peloton into HEAD
Zeninma Apr 8, 2018
6309f4a
column_catalog.cpp/h
Zeninma Apr 8, 2018
cb0887b
index catalog
ruogudu Apr 8, 2018
9de228d
lan catalog
ruogudu Apr 8, 2018
e17af13
column stat
nwang57 Apr 8, 2018
b84c4c0
lang catalog
ruogudu Apr 8, 2018
6e0c12e
settings catalog
ruogudu Apr 8, 2018
be7abc9
trigger catalog
ruogudu Apr 8, 2018
a246491
zone map catalog
nwang57 Apr 8, 2018
b8bd9a1
zone map catalog
nwang57 Apr 8, 2018
74309d9
proc_catolog.cpp/h
Zeninma Apr 8, 2018
f12bc06
Merge branch 'pcq' of https://github.com/nwang57/peloton into pcq
Zeninma Apr 8, 2018
42a1a91
delete code
ruogudu Apr 11, 2018
bb353ed
restore catalog test
ruogudu Apr 11, 2018
38ea8ef
clean up db and trigger
nwang57 Apr 11, 2018
878b0c5
Merge branch 'pcq' of https://github.com/nwang57/peloton into pcq
ruogudu Apr 11, 2018
f1a5514
cleanup settings catalog
nwang57 Apr 11, 2018
97533df
delete code
ruogudu Apr 11, 2018
50cf8a3
merge to master
ruogudu Apr 11, 2018
6a24d11
format
ruogudu Apr 11, 2018
0f8e163
fix include format
ruogudu Apr 12, 2018
c74f089
fix bug in scan plan by prashanth
ruogudu Apr 12, 2018
e69406e
Merge remote-tracking branch 'andy/master' into pcq-cp
ruogudu Apr 12, 2018
b2c5569
add index test
nwang57 Apr 13, 2018
6a3ecd9
fixed binding for tuple_value_expression, and changed query_cache_test
Zeninma Apr 22, 2018
e340a80
added Insert and Delete with Compiled Query in abstract_catalog and t…
Zeninma Apr 23, 2018
44371e2
compiled seq plan for table catalog by looking up table_oid
nwang57 Apr 23, 2018
88facc3
fix trigger
nwang57 Apr 23, 2018
d2447ff
changed trigger_test, changed the wrong assumption that triggers are …
Zeninma Apr 23, 2018
0ebfd38
fix settings catalog
ruogudu Apr 28, 2018
b1e1ca3
query metrics catalog
ruogudu Apr 28, 2018
2a6a3a8
query metrics catalog
ruogudu Apr 28, 2018
98759d7
Changed zone_map_catalog, having issue running zone_map_scan_test
Zeninma Apr 28, 2018
fd6eafb
Merge branch 'pcq-cp' of https://github.com/nwang57/peloton into pcq-cp
ruogudu Apr 28, 2018
107b9b0
database catalog insert
ruogudu Apr 28, 2018
25bb234
using expressionPtr
nwang57 Apr 28, 2018
371b27f
Merge branch 'pcq-cp' of https://github.com/nwang57/peloton into pcq-cp
ruogudu Apr 28, 2018
2fae5d1
database catalog bound
ruogudu Apr 28, 2018
edeee66
index metrics catalog insert
ruogudu Apr 28, 2018
b7f2df2
query history catalog
ruogudu Apr 28, 2018
71224a4
table metrics insert
ruogudu Apr 28, 2018
22fe699
database catalog delete
ruogudu Apr 28, 2018
65f0ea1
modify catalog inserts
nwang57 Apr 28, 2018
5b40176
Merge branch 'pcq-cp' of https://github.com/nwang57/peloton into pcq-cp
ruogudu Apr 28, 2018
e70be9a
change to complied insert plan
nwang57 Apr 28, 2018
699d400
Merge branch 'pcq-cp' of https://github.com/nwang57/peloton into pcq-cp
ruogudu Apr 28, 2018
0a02fbf
intex metrics catalog delete
ruogudu Apr 28, 2018
8da46b5
table metrics catalog delete
ruogudu Apr 28, 2018
9c4a1ee
Edited cloumn_catalog, index_catalog, proc_catalog, settings_catalog
Zeninma Apr 28, 2018
b2eaf9a
Merge branch 'pcq-cp' of https://github.com/nwang57/peloton into pcq-cp
Zeninma Apr 28, 2018
2d86aff
update catalog to use compiled delete plan
nwang57 Apr 28, 2018
6ecd138
fixed code review addressed issue
Zeninma Apr 29, 2018
0572567
trigger catalog bound
ruogudu Apr 29, 2018
540f8d5
table catalog bound
ruogudu Apr 29, 2018
888b8c4
clean up
nwang57 Apr 29, 2018
e542b58
added insert, delete and bouding for zone_map_catalog
Zeninma Apr 29, 2018
6924e0a
Merge branch 'pcq-cp' of https://github.com/nwang57/peloton into pcq-cp
Zeninma Apr 29, 2018
9e8d8a9
language catalog bound
ruogudu Apr 29, 2018
5d20500
index cache uncomment
nwang57 Apr 29, 2018
671367b
deleted redundant comments in index_catalog
Zeninma Apr 29, 2018
7ac587e
resolved trivial conflicts
Zeninma Apr 29, 2018
e9440d4
Merge branch 'pcq-cp' of https://github.com/nwang57/peloton into pcq-cp
ruogudu Apr 29, 2018
7ae1c5a
fix proc catalog
ruogudu Apr 29, 2018
2f82391
fix proc catalog
ruogudu Apr 29, 2018
ee68c8d
added bind in language_catalog's delete
Zeninma Apr 29, 2018
7dadd74
add comment to zone map manager
nwang57 Apr 29, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 54 additions & 1 deletion src/catalog/abstract_catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -235,6 +237,57 @@ 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
*/
Copy link
Contributor

Choose a reason for hiding this comment

The 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);
Copy link
Contributor

Choose a reason for hiding this comment

The 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);
cached = false;
// LOG_DEBUG("cache %d", cached);
// 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)
Expand Down
84 changes: 40 additions & 44 deletions src/catalog/catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -552,14 +552,14 @@ 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);
LOG_WARN("Dropping table %d from database %d", database_oid, table_oid);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try not to include it in the PR if you change log level for local debugging. The same below.

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());
LOG_WARN("dropping #%d indexes", (int)index_objects.size());

for (auto it : index_objects) DropIndex(it.second->GetIndexOid(), txn);
ColumnCatalog::GetInstance()->DeleteColumns(table_oid, txn);
Expand Down Expand Up @@ -614,18 +614,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);
Copy link
Member

Choose a reason for hiding this comment

The 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;
}

//===--------------------------------------------------------------------===//
Expand Down Expand Up @@ -1064,11 +1064,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,
Expand Down Expand Up @@ -1105,33 +1105,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,
Copy link
Member

Choose a reason for hiding this comment

The 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,
Expand Down
59 changes: 43 additions & 16 deletions src/catalog/column_catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
//===----------------------------------------------------------------------===//

#include "catalog/column_catalog.h"
#include "concurrency/transaction_context.h"

#include "catalog/table_catalog.h"
#include "codegen/buffering_consumer.h"
#include "concurrency/transaction_context.h"
#include "storage/data_table.h"
#include "type/value_factory.h"
#include "expression/expression_util.h"

namespace peloton {
namespace catalog {
Expand All @@ -41,9 +43,29 @@ ColumnCatalogObject::ColumnCatalogObject(executor::LogicalTile *tile,
is_not_null(tile->GetValue(tupleId, ColumnCatalog::ColumnId::IS_NOT_NULL)
.GetAs<bool>()) {}

ColumnCatalog *ColumnCatalog::GetInstance(storage::Database *pg_catalog,
type::AbstractPool *pool,
concurrency::TransactionContext *txn) {
ColumnCatalogObject::ColumnCatalogObject(codegen::WrappedTuple wrapped_tuple)
: table_oid(wrapped_tuple.GetValue(ColumnCatalog::ColumnId::TABLE_OID)
.GetAs<oid_t>()),
column_name(wrapped_tuple.GetValue(ColumnCatalog::ColumnId::COLUMN_NAME)
.ToString()),
column_id(wrapped_tuple.GetValue(ColumnCatalog::ColumnId::COLUMN_ID)
.GetAs<oid_t>()),
column_offset(
wrapped_tuple.GetValue(ColumnCatalog::ColumnId::COLUMN_OFFSET)
.GetAs<oid_t>()),
column_type(StringToTypeId(
wrapped_tuple.GetValue(ColumnCatalog::ColumnId::COLUMN_TYPE)
.ToString())),
is_inlined(wrapped_tuple.GetValue(ColumnCatalog::ColumnId::IS_INLINED)
.GetAs<bool>()),
is_primary(wrapped_tuple.GetValue(ColumnCatalog::ColumnId::IS_PRIMARY)
.GetAs<bool>()),
is_not_null(wrapped_tuple.GetValue(ColumnCatalog::ColumnId::IS_NOT_NULL)
.GetAs<bool>()) {}

ColumnCatalog *ColumnCatalog::GetInstance(
storage::Database *pg_catalog, type::AbstractPool *pool,
concurrency::TransactionContext *txn) {
static ColumnCatalog column_catalog{pg_catalog, pool, txn};
return &column_catalog;
}
Expand Down Expand Up @@ -232,19 +254,24 @@ ColumnCatalog::GetColumnObjects(oid_t table_oid,

// cache miss, get from pg_attribute
std::vector<oid_t> column_ids(all_column_ids);
oid_t index_offset = IndexId::SKEY_TABLE_OID; // Index of table_oid
std::vector<type::Value> values;
values.push_back(type::ValueFactory::GetIntegerValue(table_oid).Copy());

auto result_tiles =
GetResultWithIndexScan(column_ids, index_offset, values, txn);

for (auto &tile : (*result_tiles)) {
for (auto tuple_id : *tile) {
auto column_object =
std::make_shared<ColumnCatalogObject>(tile.get(), tuple_id);
table_object->InsertColumnObject(column_object);
}
expression::AbstractExpression *tb_oid_expr =
expression::ExpressionUtil::TupleValueFactory(type::TypeId::INTEGER, 0,
ColumnId::TABLE_OID);
expression::AbstractExpression *tb_oid_const_expr =
expression::ExpressionUtil::ConstantValueFactory(
type::ValueFactory::GetIntegerValue(table_oid).Copy());
expression::AbstractExpression *col_oid_equality_expr =
expression::ExpressionUtil::ComparisonFactory(
ExpressionType::COMPARE_EQUAL, tb_oid_expr, tb_oid_const_expr);

expression::AbstractExpression *predicate = col_oid_equality_expr;
std::vector<codegen::WrappedTuple> result_tuples =
GetResultWithCompiledSeqScan(column_ids, predicate, txn);

for (auto tuple : result_tuples) {
auto column_object = std::make_shared<ColumnCatalogObject>(tuple);
table_object->InsertColumnObject(column_object);
}

return table_object->GetColumnObjects();
Expand Down
Loading