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

Commit 4f95ea6

Browse files
committed
Merge branch 'master' into catalog_update
2 parents f3eb826 + 9401245 commit 4f95ea6

File tree

220 files changed

+7448
-3927
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

220 files changed

+7448
-3927
lines changed

src/catalog/abstract_catalog.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "planner/insert_plan.h"
2929
#include "planner/seq_scan_plan.h"
3030

31+
#include "executor/executor_context.h"
3132
#include "executor/delete_executor.h"
3233
#include "executor/index_scan_executor.h"
3334
#include "executor/insert_executor.h"

src/catalog/catalog.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "catalog/table_catalog.h"
2828
#include "catalog/table_metrics_catalog.h"
2929
#include "catalog/trigger_catalog.h"
30+
#include "codegen/code_context.h"
3031
#include "concurrency/transaction_manager_factory.h"
3132
#include "function/date_functions.h"
3233
#include "function/decimal_functions.h"

src/catalog/layout_catalog.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "executor/logical_tile.h"
1919
#include "storage/data_table.h"
2020
#include "storage/layout.h"
21+
#include "type/value_factory.h"
2122

2223
namespace peloton {
2324
namespace catalog {

src/codegen/aggregation.cpp

Lines changed: 27 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
//
77
// Identification: src/codegen/aggregation.cpp
88
//
9-
// Copyright (c) 2015-2017, Carnegie Mellon University Database Group
9+
// Copyright (c) 2015-2018, Carnegie Mellon University Database Group
1010
//
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "codegen/aggregation.h"
1414

15+
#include "codegen/lang/if.h"
1516
#include "codegen/proxy/oa_hash_table_proxy.h"
1617
#include "codegen/type/boolean_type.h"
1718
#include "codegen/type/bigint_type.h"
@@ -136,7 +137,7 @@ void Aggregation::Setup(
136137
}
137138

138139
// Register the hash-table instance in the runtime state
139-
auto hash_table_id = runtime_state_.RegisterState(
140+
auto hash_table_id = query_state_.RegisterState(
140141
"agg_hash" + std::to_string(agg_info.source_index),
141142
OAHashTableProxy::GetType(codegen));
142143

@@ -177,30 +178,28 @@ void Aggregation::Setup(
177178
}
178179

179180
// Codegen any initialization work for the hash tables
180-
void Aggregation::InitializeState(CodeGen &codegen) {
181+
void Aggregation::InitializeQueryState(CodeGen &codegen) {
181182
for (auto hash_table_info : hash_table_infos_) {
182183
auto &hash_table = hash_table_info.first;
183184
auto hash_table_id = hash_table_info.second;
184-
hash_table.Init(codegen,
185-
runtime_state_.LoadStatePtr(codegen, hash_table_id));
185+
hash_table.Init(codegen, query_state_.LoadStatePtr(codegen, hash_table_id));
186186
}
187187
}
188188

189189
// Cleanup by destroying the aggregation hash tables
190-
void Aggregation::TearDownState(CodeGen &codegen) {
190+
void Aggregation::TearDownQueryState(CodeGen &codegen) {
191191
for (auto hash_table_info : hash_table_infos_) {
192192
auto &hash_table = hash_table_info.first;
193193
auto hash_table_id = hash_table_info.second;
194194
hash_table.Destroy(codegen,
195-
runtime_state_.LoadStatePtr(codegen, hash_table_id));
195+
query_state_.LoadStatePtr(codegen, hash_table_id));
196196
}
197197
}
198198

199199
void Aggregation::CreateInitialGlobalValues(CodeGen &codegen,
200200
llvm::Value *space) const {
201201
PELOTON_ASSERT(IsGlobal());
202-
auto null_bitmap =
203-
UpdateableStorage::NullBitmap{codegen, GetAggregateStorage(), space};
202+
UpdateableStorage::NullBitmap null_bitmap{codegen, storage_, space};
204203
null_bitmap.InitAllNull(codegen);
205204
null_bitmap.WriteBack(codegen);
206205
}
@@ -260,23 +259,20 @@ void Aggregation::CreateInitialValues(
260259
auto &hash_table = hash_table_infos_[agg_info.hast_table_index].first;
261260
auto hash_table_id = hash_table_infos_[agg_info.hast_table_index].second;
262261

263-
// Get runtime state pointer for this hash table
262+
// Get the hash table for this hash table
264263
llvm::Value *state_pointer =
265-
runtime_state_.LoadStatePtr(codegen, hash_table_id);
266-
267-
// TODO(marcel): is it possible to cache the hash value for this
268-
// expression?
269-
llvm::Value *hash = nullptr;
264+
query_state_.LoadStatePtr(codegen, hash_table_id);
270265

271266
// Prepare the hash keys
272267
std::vector<codegen::Value> key = grouping_keys;
273268
key.push_back(input_val);
274269

275270
// Perform the dummy lookup in the hash table that creates the entry
271+
llvm::Value *hash = nullptr;
276272
HashTable::NoOpInsertCallback insert_callback;
277273
hash_table.Insert(codegen, state_pointer, hash, key, insert_callback);
278274
}
279-
} // iterate aggregations
275+
}
280276
}
281277

282278
void Aggregation::DoInitializeValue(
@@ -288,11 +284,7 @@ void Aggregation::DoInitializeValue(
288284
case ExpressionType::AGGREGATE_MIN:
289285
case ExpressionType::AGGREGATE_MAX: {
290286
// For the above aggregations, the initial value is the attribute value
291-
if (null_bitmap.IsNullable(storage_index)) {
292-
storage_.SetValue(codegen, space, storage_index, initial, null_bitmap);
293-
} else {
294-
storage_.SetValueSkipNull(codegen, space, storage_index, initial);
295-
}
287+
storage_.SetValue(codegen, space, storage_index, initial, null_bitmap);
296288
break;
297289
}
298290
case ExpressionType::AGGREGATE_COUNT: {
@@ -303,13 +295,13 @@ void Aggregation::DoInitializeValue(
303295
} else {
304296
raw_initial = codegen.Const64(1);
305297
}
306-
auto initial_val = codegen::Value{type::BigInt::Instance(), raw_initial};
298+
codegen::Value initial_val{type::BigInt::Instance(), raw_initial};
307299
storage_.SetValueSkipNull(codegen, space, storage_index, initial_val);
308300
break;
309301
}
310302
case ExpressionType::AGGREGATE_COUNT_STAR: {
311303
// The initial value for COUNT(*) is 1
312-
auto one = codegen::Value{type::BigInt::Instance(), codegen.Const64(1)};
304+
codegen::Value one{type::BigInt::Instance(), codegen.Const64(1)};
313305
storage_.SetValueSkipNull(codegen, space, storage_index, one);
314306
break;
315307
}
@@ -364,7 +356,7 @@ void Aggregation::DoAdvanceValue(CodeGen &codegen, llvm::Value *space,
364356
}
365357
case ExpressionType::AGGREGATE_COUNT_STAR: {
366358
auto curr = storage_.GetValueSkipNull(codegen, space, storage_index);
367-
auto delta = Value{type::BigInt::Instance(), codegen.Const64(1)};
359+
auto delta = codegen::Value{type::BigInt::Instance(), codegen.Const64(1)};
368360
next = curr.Add(codegen, delta);
369361
break;
370362
}
@@ -494,7 +486,7 @@ void Aggregation::AdvanceValue(
494486
LOG_ERROR("%s", message.c_str());
495487
throw Exception{ExceptionType::UNKNOWN_TYPE, message};
496488
}
497-
} // switch
489+
}
498490
}
499491

500492
// Advance each of the aggregates stored in the provided storage space
@@ -503,7 +495,7 @@ void Aggregation::AdvanceValues(
503495
const std::vector<codegen::Value> &next_vals,
504496
const std::vector<codegen::Value> &grouping_keys) const {
505497
// The null bitmap tracker
506-
UpdateableStorage::NullBitmap null_bitmap{codegen, storage_, space};
498+
UpdateableStorage::NullBitmap null_bitmap(codegen, storage_, space);
507499

508500
// Loop over all aggregates, advancing each
509501
for (const auto &aggregate_info : aggregate_infos_) {
@@ -522,7 +514,7 @@ void Aggregation::AdvanceValues(
522514
hash_table_infos_[aggregate_info.hast_table_index].second;
523515

524516
// Get runtime state pointer for this hash table
525-
llvm::Value *ht_ptr = runtime_state_.LoadStatePtr(codegen, hash_table_id);
517+
llvm::Value *ht_ptr = query_state_.LoadStatePtr(codegen, hash_table_id);
526518

527519
// TODO(marcel): is it possible to cache the hash value for this
528520
// expression?
@@ -586,39 +578,27 @@ void Aggregation::FinalizeValues(
586578
CodeGen &codegen, llvm::Value *space,
587579
std::vector<codegen::Value> &final_vals) const {
588580
// The null bitmap tracker
589-
UpdateableStorage::NullBitmap null_bitmap{codegen, storage_, space};
581+
UpdateableStorage::NullBitmap null_bitmap(codegen, storage_, space);
590582

591583
for (const auto &agg_info : aggregate_infos_) {
592584
ExpressionType agg_type = agg_info.aggregate_type;
593585
switch (agg_type) {
594586
case ExpressionType::AGGREGATE_SUM:
595587
case ExpressionType::AGGREGATE_MIN:
596588
case ExpressionType::AGGREGATE_MAX: {
597-
codegen::Value final_val;
598-
if (null_bitmap.IsNullable(agg_info.storage_indices[0])) {
599-
final_val = storage_.GetValue(
600-
codegen, space, agg_info.storage_indices[0], null_bitmap);
601-
} else {
602-
final_val = storage_.GetValueSkipNull(codegen, space,
603-
agg_info.storage_indices[0]);
604-
}
589+
codegen::Value final_val = storage_.GetValue(
590+
codegen, space, agg_info.storage_indices[0], null_bitmap);
605591

606592
// append final value to result vector
607593
final_vals.push_back(final_val);
608594
break;
609595
}
610596
case ExpressionType::AGGREGATE_AVG: {
611-
// collect the final values of the SUM and the COUNT components and
612-
// calculate the average
613-
codegen::Value sum;
614-
if (null_bitmap.IsNullable(agg_info.storage_indices[0])) {
615-
sum = storage_.GetValue(codegen, space, agg_info.storage_indices[0],
616-
null_bitmap);
617-
} else {
618-
sum = storage_.GetValueSkipNull(codegen, space,
619-
agg_info.storage_indices[0]);
620-
}
597+
// collect the final values of the SUM and the COUNT components
598+
codegen::Value sum = storage_.GetValue(
599+
codegen, space, agg_info.storage_indices[0], null_bitmap);
621600

601+
PELOTON_ASSERT(!null_bitmap.IsNullable(agg_info.storage_indices[1]));
622602
codegen::Value count = storage_.GetValueSkipNull(
623603
codegen, space, agg_info.storage_indices[1]);
624604

@@ -628,7 +608,7 @@ void Aggregation::FinalizeValues(
628608
codegen::Value count_casted =
629609
count.CastTo(codegen, type::Decimal::Instance());
630610

631-
// add the actual calculation
611+
// Compute the average
632612
codegen::Value final_val =
633613
sum_casted.Div(codegen, count_casted, OnError::ReturnNull);
634614

src/codegen/buffer_accessor.cpp

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Peloton
4+
//
5+
// buffer_accessor.cpp
6+
//
7+
// Identification: src/codegen/buffer_accessor.cpp
8+
//
9+
// Copyright (c) 2015-2017, Carnegie Mellon University Database Group
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include "codegen/buffer_accessor.h"
14+
15+
#include "codegen/lang/loop.h"
16+
#include "codegen/proxy/buffer_proxy.h"
17+
18+
namespace peloton {
19+
namespace codegen {
20+
21+
BufferAccessor::BufferAccessor() = default;
22+
23+
BufferAccessor::BufferAccessor(CodeGen &codegen,
24+
const std::vector<type::Type> &tuple_desc) {
25+
for (const auto &value_type : tuple_desc) {
26+
storage_format_.AddType(value_type);
27+
}
28+
storage_format_.Finalize(codegen);
29+
}
30+
31+
void BufferAccessor::Init(CodeGen &codegen, llvm::Value *buffer_ptr) const {
32+
codegen.Call(BufferProxy::Init, {buffer_ptr});
33+
}
34+
35+
void BufferAccessor::Append(CodeGen &codegen, llvm::Value *buffer_ptr,
36+
const std::vector<codegen::Value> &tuple) const {
37+
auto *size = codegen.Const32(storage_format_.GetStorageSize());
38+
auto *space = codegen.Call(BufferProxy::Append, {buffer_ptr, size});
39+
40+
// Now, individually store the attributes of the tuple into the free space
41+
UpdateableStorage::NullBitmap null_bitmap(codegen, storage_format_, space);
42+
for (uint32_t col_id = 0; col_id < tuple.size(); col_id++) {
43+
storage_format_.SetValue(codegen, space, col_id, tuple[col_id],
44+
null_bitmap);
45+
}
46+
null_bitmap.WriteBack(codegen);
47+
}
48+
49+
void BufferAccessor::Iterate(CodeGen &codegen, llvm::Value *buffer_ptr,
50+
BufferAccessor::IterateCallback &callback) const {
51+
auto *start = codegen.Load(BufferProxy::buffer_start, buffer_ptr);
52+
auto *end = codegen.Load(BufferProxy::buffer_pos, buffer_ptr);
53+
lang::Loop loop{codegen, codegen->CreateICmpNE(start, end), {{"pos", start}}};
54+
{
55+
auto *pos = loop.GetLoopVar(0);
56+
57+
// Read
58+
std::vector<codegen::Value> vals;
59+
UpdateableStorage::NullBitmap null_bitmap(codegen, storage_format_, pos);
60+
for (uint32_t col_id = 0; col_id < storage_format_.GetNumElements();
61+
col_id++) {
62+
auto val = storage_format_.GetValue(codegen, pos, col_id, null_bitmap);
63+
vals.emplace_back(val);
64+
}
65+
66+
// Invoke callback
67+
callback.ProcessEntry(codegen, vals);
68+
69+
// Move along
70+
auto *next = codegen->CreateConstInBoundsGEP1_64(
71+
pos, storage_format_.GetStorageSize());
72+
loop.LoopEnd(codegen->CreateICmpNE(next, end), {next});
73+
}
74+
}
75+
76+
void BufferAccessor::Reset(CodeGen &codegen, llvm::Value *buffer_ptr) const {
77+
codegen.Call(BufferProxy::Reset, {buffer_ptr});
78+
}
79+
80+
void BufferAccessor::Destroy(CodeGen &codegen, llvm::Value *buffer_ptr) const {
81+
codegen.Call(BufferProxy::Destroy, {buffer_ptr});
82+
}
83+
84+
llvm::Value *BufferAccessor::NumTuples(CodeGen &codegen,
85+
llvm::Value *buffer_ptr) const {
86+
auto *start = codegen.Load(BufferProxy::buffer_start, buffer_ptr);
87+
auto *end = codegen.Load(BufferProxy::buffer_pos, buffer_ptr);
88+
start = codegen->CreatePtrToInt(start, codegen.Int64Type());
89+
end = codegen->CreatePtrToInt(end, codegen.Int64Type());
90+
auto *diff = codegen->CreateSub(end, start);
91+
diff = codegen->CreateAShr(diff, 3, "numTuples", true);
92+
return codegen->CreateTrunc(diff, codegen.Int32Type());
93+
}
94+
95+
} // namespace codegen
96+
} // namespace peloton

0 commit comments

Comments
 (0)