|
26 | 26 | namespace peloton {
|
27 | 27 | namespace codegen {
|
28 | 28 |
|
| 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 | + |
29 | 128 | ////////////////////////////////////////////////////////////////////////////////
|
30 | 129 | ///
|
31 | 130 | /// Table Scan Translator
|
@@ -171,11 +270,6 @@ const planner::SeqScanPlan &TableScanTranslator::GetScanPlan() const {
|
171 | 270 | ///
|
172 | 271 | ////////////////////////////////////////////////////////////////////////////////
|
173 | 272 |
|
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 |
| - |
179 | 273 | // Generate the body of the vectorized scan
|
180 | 274 | void TableScanTranslator::ScanConsumer::ProcessTuples(
|
181 | 275 | CodeGen &codegen, llvm::Value *tid_start, llvm::Value *tid_end,
|
@@ -280,21 +374,5 @@ void TableScanTranslator::ScanConsumer::FilterRowsByPredicate(
|
280 | 374 | });
|
281 | 375 | }
|
282 | 376 |
|
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 |
| - |
299 | 377 | } // namespace codegen
|
300 | 378 | } // namespace peloton
|
0 commit comments