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

Commit 70f5195

Browse files
mbutrovichtli2
authored andcommitted
fix #1386: PerformVectorizedRead optimization (#1434)
* fix #1386 part 2: pass update boolean from scan plan to PerformRead correctly. * fix #1386 part 1: Perform predicate evaluation before recording reads with the transaction manager. * Rename new function RecordReads to PerformReads per PR feedback.
1 parent d3e3289 commit 70f5195

File tree

5 files changed

+51
-16
lines changed

5 files changed

+51
-16
lines changed

src/codegen/operator/table_scan_translator.cpp

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ class TableScanTranslator::ScanConsumer : public codegen::ScanCallback {
105105
llvm::Value *tid_end,
106106
Vector &selection_vector) const;
107107

108+
void PerformReads(CodeGen &codegen, Vector &selection_vector) const;
109+
108110
// Filter all the rows whose TIDs are in the range [tid_start, tid_end] and
109111
// store their TIDs in the output TID selection vector
110112
void FilterRowsByPredicate(CodeGen &codegen,
@@ -290,14 +292,17 @@ void TableScanTranslator::ScanConsumer::ProcessTuples(
290292
selection_vector_);
291293
}
292294

293-
// 3. Setup the (filtered) row batch and setup attribute accessors
295+
// 3. Record reads for all of the tuple that are visible and pass predicate
296+
PerformReads(codegen, selection_vector_);
297+
298+
// 4. Setup the (filtered) row batch and setup attribute accessors
294299
RowBatch batch{ctx_.GetCompilationContext(), tile_group_id_, tid_start,
295300
tid_end, selection_vector_, true};
296301

297302
std::vector<TableScanTranslator::AttributeAccess> attribute_accesses;
298303
SetupRowBatch(batch, tile_group_access, attribute_accesses);
299304

300-
// 4. Push the batch into the pipeline
305+
// 5. Push the batch into the pipeline
301306
ctx_.Consume(batch);
302307
}
303308

@@ -333,9 +338,9 @@ void TableScanTranslator::ScanConsumer::FilterRowsByVisibility(
333338
llvm::Value *txn = ec.GetTransactionPtr(ctx_.GetCompilationContext());
334339
llvm::Value *raw_sel_vec = selection_vector.GetVectorPtr();
335340

336-
// Invoke TransactionRuntime::PerformRead(...)
341+
// Invoke TransactionRuntime::PerformVisibilityCheck(...)
337342
llvm::Value *out_idx =
338-
codegen.Call(TransactionRuntimeProxy::PerformVectorizedRead,
343+
codegen.Call(TransactionRuntimeProxy::PerformVisibilityCheck,
339344
{txn, tile_group_ptr_, tid_start, tid_end, raw_sel_vec});
340345
selection_vector.SetNumElements(out_idx);
341346
}
@@ -379,5 +384,21 @@ void TableScanTranslator::ScanConsumer::FilterRowsByPredicate(
379384
});
380385
}
381386

387+
void TableScanTranslator::ScanConsumer::PerformReads(
388+
CodeGen &codegen, Vector &selection_vector) const {
389+
ExecutionConsumer &ec = ctx_.GetCompilationContext().GetExecutionConsumer();
390+
llvm::Value *txn = ec.GetTransactionPtr(ctx_.GetCompilationContext());
391+
llvm::Value *raw_sel_vec = selection_vector.GetVectorPtr();
392+
393+
llvm::Value *is_for_update = codegen.ConstBool(plan_.IsForUpdate());
394+
llvm::Value *end_idx = selection_vector.GetNumElements();
395+
396+
// Invoke TransactionRuntime::PerformVectorizedRead(...)
397+
llvm::Value *out_idx =
398+
codegen.Call(TransactionRuntimeProxy::PerformVectorizedRead,
399+
{txn, tile_group_ptr_, raw_sel_vec, end_idx, is_for_update});
400+
selection_vector.SetNumElements(out_idx);
401+
}
402+
382403
} // namespace codegen
383404
} // namespace peloton

src/codegen/proxy/transaction_runtime_proxy.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace peloton {
2222
namespace codegen {
2323

2424
DEFINE_METHOD(peloton::codegen, TransactionRuntime, PerformVectorizedRead);
25+
DEFINE_METHOD(peloton::codegen, TransactionRuntime, PerformVisibilityCheck);
2526

2627
} // namespace codegen
2728
} // namespace peloton

src/codegen/transaction_runtime.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@
2222
namespace peloton {
2323
namespace codegen {
2424

25-
// Perform a read operation for all tuples in the tile group in the given range
26-
// TODO: Right now, we split this check into two loops: a visibility check and
27-
// the actual reading. Can this be merged?
28-
uint32_t TransactionRuntime::PerformVectorizedRead(
25+
uint32_t TransactionRuntime::PerformVisibilityCheck(
2926
concurrency::TransactionContext &txn, storage::TileGroup &tile_group,
3027
uint32_t tid_start, uint32_t tid_end, uint32_t *selection_vector) {
3128
// Get the transaction manager
@@ -45,24 +42,34 @@ uint32_t TransactionRuntime::PerformVectorizedRead(
4542
selection_vector[out_idx] = i;
4643
out_idx += (visibility == VisibilityType::OK);
4744
}
45+
return out_idx;
46+
}
47+
48+
uint32_t TransactionRuntime::PerformVectorizedRead(
49+
concurrency::TransactionContext &txn, storage::TileGroup &tile_group,
50+
uint32_t *selection_vector, uint32_t end_idx, bool is_for_update) {
51+
// Get the transaction manager
52+
auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance();
53+
54+
// Get the tile group header
55+
auto tile_group_header = tile_group.GetHeader();
4856

4957
uint32_t tile_group_idx = tile_group.GetTileGroupId();
5058

5159
// Perform a read operation for every visible tuple we found
52-
uint32_t end_idx = out_idx;
53-
out_idx = 0;
60+
uint32_t out_idx = 0;
5461
for (uint32_t idx = 0; idx < end_idx; idx++) {
5562
// Construct the item location
5663
ItemPointer location{tile_group_idx, selection_vector[idx]};
5764

5865
// Perform the read
59-
bool can_read = txn_manager.PerformRead(&txn, location, tile_group_header, false);
66+
bool can_read = txn_manager.PerformRead(&txn, location, tile_group_header,
67+
is_for_update);
6068

6169
// Update the selection vector and output position
6270
selection_vector[out_idx] = selection_vector[idx];
6371
out_idx += static_cast<uint32_t>(can_read);
6472
}
65-
6673
return out_idx;
6774
}
6875

src/include/codegen/proxy/transaction_runtime_proxy.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ namespace peloton {
1818
namespace codegen {
1919

2020
PROXY(TransactionRuntime) {
21-
/// We only need to proxy PerformVectorizedRead()
22-
/// in codegen::TransactionRuntime.
2321
DECLARE_METHOD(PerformVectorizedRead);
22+
DECLARE_METHOD(PerformVisibilityCheck);
2423
};
2524

2625
} // namespace codegen

src/include/codegen/transaction_runtime.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,19 @@ namespace codegen {
4242
//===----------------------------------------------------------------------===//
4343
class TransactionRuntime {
4444
public:
45+
// Perform a visibility check for all tuples in the given tile group with IDs
46+
// in the range [tid_start, tid_end) in the context of the given transaction
47+
static uint32_t PerformVisibilityCheck(concurrency::TransactionContext &txn,
48+
storage::TileGroup &tile_group,
49+
uint32_t tid_start, uint32_t tid_end,
50+
uint32_t *selection_vector);
51+
4552
// Perform a read operation for all tuples in the given tile group with IDs
4653
// in the range [tid_start, tid_end) in the context of the given transaction
4754
static uint32_t PerformVectorizedRead(concurrency::TransactionContext &txn,
4855
storage::TileGroup &tile_group,
49-
uint32_t tid_start, uint32_t tid_end,
50-
uint32_t *selection_vector);
56+
uint32_t *selection_vector,
57+
uint32_t end_idx, bool is_for_update);
5158
// Check Ownership
5259
static bool IsOwner(concurrency::TransactionContext &txn,
5360
storage::TileGroupHeader *tile_group_header,

0 commit comments

Comments
 (0)