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

Commit 6abdb85

Browse files
committed
Table scan cleanup
1 parent f023dd0 commit 6abdb85

File tree

3 files changed

+109
-99
lines changed

3 files changed

+109
-99
lines changed

src/codegen/operator/table_scan_translator.cpp

Lines changed: 99 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,105 @@
2626
namespace peloton {
2727
namespace codegen {
2828

29+
////////////////////////////////////////////////////////////////////////////////
30+
///
31+
/// AttributeAccess
32+
///
33+
////////////////////////////////////////////////////////////////////////////////
34+
35+
/**
36+
* This class enables deferred access to any one available attribute in an input
37+
* row. The main (overridden) function, Access(), is responsible for loading the
38+
* attribute the class was constructed with from the input row provided to the
39+
* function.
40+
*/
41+
class TableScanTranslator::AttributeAccess : public RowBatch::AttributeAccess {
42+
public:
43+
AttributeAccess(const TileGroup::TileGroupAccess &access,
44+
const planner::AttributeInfo *ai)
45+
: tile_group_access_(access), ai_(ai) {}
46+
47+
// Access an attribute in the given row
48+
codegen::Value Access(CodeGen &codegen, RowBatch::Row &row) override {
49+
auto raw_row = tile_group_access_.GetRow(row.GetTID(codegen));
50+
return raw_row.LoadColumn(codegen, ai_->attribute_id);
51+
}
52+
53+
const planner::AttributeInfo *GetAttributeRef() const { return ai_; }
54+
55+
private:
56+
// The accessor we use to load column values
57+
const TileGroup::TileGroupAccess &tile_group_access_;
58+
// The attribute we will access
59+
const planner::AttributeInfo *ai_;
60+
};
61+
62+
////////////////////////////////////////////////////////////////////////////////
63+
///
64+
/// ScanConsumer
65+
///
66+
////////////////////////////////////////////////////////////////////////////////
67+
68+
/**
69+
* The ScanConsumer is the callback functor used when issuing a sequential scan
70+
* over a table. The meat of callback is in ProcessTuples(), which is called to
71+
* process a batch of tuples within a tile group of a table.
72+
*/
73+
class TableScanTranslator::ScanConsumer : public codegen::ScanCallback {
74+
public:
75+
// Constructor
76+
ScanConsumer(ConsumerContext &ctx, const planner::SeqScanPlan &plan,
77+
Vector &selection_vector)
78+
: ctx_(ctx),
79+
plan_(plan),
80+
selection_vector_(selection_vector),
81+
tile_group_id_(nullptr),
82+
tile_group_ptr_(nullptr) {}
83+
84+
// The callback when starting iteration over a new tile group
85+
void TileGroupStart(CodeGen &, llvm::Value *tile_group_id,
86+
llvm::Value *tile_group_ptr) override {
87+
tile_group_id_ = tile_group_id;
88+
tile_group_ptr_ = tile_group_ptr;
89+
}
90+
91+
// The code that forms the body of the scan loop
92+
void ProcessTuples(CodeGen &codegen, llvm::Value *tid_start,
93+
llvm::Value *tid_end,
94+
TileGroup::TileGroupAccess &tile_group_access) override;
95+
96+
// The callback when finishing iteration over a tile group
97+
void TileGroupFinish(CodeGen &, llvm::Value *) override {}
98+
99+
private:
100+
void SetupRowBatch(RowBatch &batch,
101+
TileGroup::TileGroupAccess &tile_group_access,
102+
std::vector<AttributeAccess> &access) const;
103+
104+
void FilterRowsByVisibility(CodeGen &codegen, llvm::Value *tid_start,
105+
llvm::Value *tid_end,
106+
Vector &selection_vector) const;
107+
108+
// Filter all the rows whose TIDs are in the range [tid_start, tid_end] and
109+
// store their TIDs in the output TID selection vector
110+
void FilterRowsByPredicate(CodeGen &codegen,
111+
const TileGroup::TileGroupAccess &access,
112+
llvm::Value *tid_start, llvm::Value *tid_end,
113+
Vector &selection_vector) const;
114+
115+
private:
116+
// The consumer context
117+
ConsumerContext &ctx_;
118+
// The plan node
119+
const planner::SeqScanPlan &plan_;
120+
// The selection vector used for vectorized scans
121+
Vector &selection_vector_;
122+
// The current tile group id we're scanning over
123+
llvm::Value *tile_group_id_;
124+
// The current tile group we're scanning over
125+
llvm::Value *tile_group_ptr_;
126+
};
127+
29128
////////////////////////////////////////////////////////////////////////////////
30129
///
31130
/// Table Scan Translator
@@ -171,11 +270,6 @@ const planner::SeqScanPlan &TableScanTranslator::GetScanPlan() const {
171270
///
172271
////////////////////////////////////////////////////////////////////////////////
173272

174-
TableScanTranslator::ScanConsumer::ScanConsumer(
175-
ConsumerContext &ctx, const planner::SeqScanPlan &plan,
176-
Vector &selection_vector)
177-
: ctx_(ctx), plan_(plan), selection_vector_(selection_vector) {}
178-
179273
// Generate the body of the vectorized scan
180274
void TableScanTranslator::ScanConsumer::ProcessTuples(
181275
CodeGen &codegen, llvm::Value *tid_start, llvm::Value *tid_end,
@@ -280,21 +374,5 @@ void TableScanTranslator::ScanConsumer::FilterRowsByPredicate(
280374
});
281375
}
282376

283-
////////////////////////////////////////////////////////////////////////////////
284-
///
285-
/// Attribute Access
286-
///
287-
////////////////////////////////////////////////////////////////////////////////
288-
289-
TableScanTranslator::AttributeAccess::AttributeAccess(
290-
const TileGroup::TileGroupAccess &access, const planner::AttributeInfo *ai)
291-
: tile_group_access_(access), ai_(ai) {}
292-
293-
codegen::Value TableScanTranslator::AttributeAccess::Access(
294-
CodeGen &codegen, RowBatch::Row &row) {
295-
auto raw_row = tile_group_access_.GetRow(row.GetTID(codegen));
296-
return raw_row.LoadColumn(codegen, ai_->attribute_id);
297-
}
298-
299377
} // namespace codegen
300378
} // namespace peloton

src/include/codegen/operator/order_by_translator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class OrderByTranslator : public OperatorTranslator {
4949
void Consume(ConsumerContext &context, RowBatch::Row &row) const override;
5050

5151
private:
52-
// Helper class declarations
52+
// Helper class declarations (defined in implementation)
5353
class ProduceResults;
5454
class SorterAttributeAccess;
5555

src/include/codegen/operator/table_scan_translator.h

Lines changed: 9 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
// Identification: src/include/codegen/operator/table_scan_translator.h
88
//
9-
// Copyright (c) 2015-2017, Carnegie Mellon University Database Group
9+
// Copyright (c) 2015-2018, Carnegie Mellon University Database Group
1010
//
1111
//===----------------------------------------------------------------------===//
1212

@@ -31,14 +31,15 @@ class DataTable;
3131
namespace codegen {
3232

3333
//===----------------------------------------------------------------------===//
34-
// A translator for table scans
34+
// A translator for sequential table scans
3535
//===----------------------------------------------------------------------===//
3636
class TableScanTranslator : public OperatorTranslator {
3737
public:
3838
// Constructor
3939
TableScanTranslator(const planner::SeqScanPlan &scan,
4040
CompilationContext &context, Pipeline &pipeline);
4141

42+
// Nothing to do here
4243
void InitializeQueryState() override {}
4344

4445
// Table scans don't rely on any auxiliary functions
@@ -58,87 +59,18 @@ class TableScanTranslator : public OperatorTranslator {
5859
// Load the table pointer
5960
llvm::Value *LoadTablePtr(CodeGen &codegen) const;
6061

62+
// Functions to produce tuples serially or in parallel
6163
void ProduceSerial() const;
62-
6364
void ProduceParallel() const;
6465

65-
//===--------------------------------------------------------------------===//
66-
// An attribute accessor that uses the backing tile group to access columns
67-
//===--------------------------------------------------------------------===//
68-
class AttributeAccess : public RowBatch::AttributeAccess {
69-
public:
70-
// Constructor
71-
AttributeAccess(const TileGroup::TileGroupAccess &access,
72-
const planner::AttributeInfo *ai);
73-
74-
// Access an attribute in the given row
75-
codegen::Value Access(CodeGen &codegen, RowBatch::Row &row) override;
76-
77-
const planner::AttributeInfo *GetAttributeRef() const { return ai_; }
78-
79-
private:
80-
// The accessor we use to load column values
81-
const TileGroup::TileGroupAccess &tile_group_access_;
82-
// The attribute we will access
83-
const planner::AttributeInfo *ai_;
84-
};
85-
86-
//===--------------------------------------------------------------------===//
87-
// The class responsible for generating vectorized scan code over tile groups
88-
//===--------------------------------------------------------------------===//
89-
class ScanConsumer : public codegen::ScanCallback {
90-
public:
91-
// Constructor
92-
ScanConsumer(ConsumerContext &ctx, const planner::SeqScanPlan &plan,
93-
Vector &selection_vector);
94-
95-
// The callback when starting iteration over a new tile group
96-
void TileGroupStart(CodeGen &, llvm::Value *tile_group_id,
97-
llvm::Value *tile_group_ptr) override {
98-
tile_group_id_ = tile_group_id;
99-
tile_group_ptr_ = tile_group_ptr;
100-
}
101-
102-
// The code that forms the body of the scan loop
103-
void ProcessTuples(CodeGen &codegen, llvm::Value *tid_start,
104-
llvm::Value *tid_end,
105-
TileGroup::TileGroupAccess &tile_group_access) override;
106-
107-
// The callback when finishing iteration over a tile group
108-
void TileGroupFinish(CodeGen &, llvm::Value *) override {}
109-
110-
private:
111-
void SetupRowBatch(RowBatch &batch,
112-
TileGroup::TileGroupAccess &tile_group_access,
113-
std::vector<AttributeAccess> &access) const;
114-
115-
void FilterRowsByVisibility(CodeGen &codegen, llvm::Value *tid_start,
116-
llvm::Value *tid_end,
117-
Vector &selection_vector) const;
118-
119-
// Filter all the rows whose TIDs are in the range [tid_start, tid_end] and
120-
// store their TIDs in the output TID selection vector
121-
void FilterRowsByPredicate(CodeGen &codegen,
122-
const TileGroup::TileGroupAccess &access,
123-
llvm::Value *tid_start, llvm::Value *tid_end,
124-
Vector &selection_vector) const;
125-
126-
private:
127-
// The consumer context
128-
ConsumerContext &ctx_;
129-
// The plan node
130-
const planner::SeqScanPlan &plan_;
131-
// The selection vector used for vectorized scans
132-
Vector &selection_vector_;
133-
// The current tile group id we're scanning over
134-
llvm::Value *tile_group_id_;
135-
// The current tile group we're scanning over
136-
llvm::Value *tile_group_ptr_;
137-
};
138-
13966
// Plan accessor
14067
const planner::SeqScanPlan &GetScanPlan() const;
14168

69+
private:
70+
// Helper class declarations (defined in implementation)
71+
class AttributeAccess;
72+
class ScanConsumer;
73+
14274
private:
14375
// The code-generating table instance
14476
codegen::Table table_;

0 commit comments

Comments
 (0)