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

Commit fd4a31c

Browse files
linmagitapavlo
authored andcommitted
IndexScanDesc and IndexScanPlan Refactoring (#1301)
* Refactor some member variable and function names. * Fixes for the changed API. * HybridScanExecutor and tpcc_payment fix. * Fix the rest of the tpcc benchmark. * Fix the ycsb IndexScanDesc construction. * Fix the sdbench. It does not run though. * Delete unused code.
1 parent d583b5f commit fd4a31c

21 files changed

+1273
-1055
lines changed

src/catalog/abstract_catalog.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ bool AbstractCatalog::DeleteWithIndexScan(
134134
std::vector<expression::AbstractExpression *> runtime_keys;
135135

136136
planner::IndexScanPlan::IndexScanDesc index_scan_desc(
137-
index, key_column_offsets, expr_types, values, runtime_keys);
137+
index->GetOid(), key_column_offsets, expr_types, values, runtime_keys);
138138

139139
std::unique_ptr<planner::IndexScanPlan> index_scan_node(
140140
new planner::IndexScanPlan(catalog_table_, nullptr, column_offsets,
@@ -179,7 +179,7 @@ AbstractCatalog::GetResultWithIndexScan(
179179
std::vector<expression::AbstractExpression *> runtime_keys;
180180

181181
planner::IndexScanPlan::IndexScanDesc index_scan_desc(
182-
index, key_column_offsets, expr_types, values, runtime_keys);
182+
index->GetOid(), key_column_offsets, expr_types, values, runtime_keys);
183183

184184
planner::IndexScanPlan index_scan_node(catalog_table_, nullptr,
185185
column_offsets, index_scan_desc);

src/executor/hybrid_scan_executor.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#include "executor/hybrid_scan_executor.h"
1314
#include "common/container_tuple.h"
15+
#include "common/internal_types.h"
1416
#include "common/logger.h"
1517
#include "concurrency/transaction_manager_factory.h"
1618
#include "executor/executor_context.h"
17-
#include "executor/hybrid_scan_executor.h"
1819
#include "executor/logical_tile.h"
1920
#include "executor/logical_tile_factory.h"
2021
#include "planner/hybrid_scan_plan.h"
2122
#include "storage/data_table.h"
2223
#include "storage/tile.h"
2324
#include "storage/tile_group_header.h"
24-
#include "common/internal_types.h"
2525

2626
namespace peloton {
2727
namespace executor {
@@ -39,10 +39,15 @@ bool HybridScanExecutor::DInit() {
3939
const planner::HybridScanPlan &node = GetPlanNode<planner::HybridScanPlan>();
4040

4141
table_ = node.GetTable();
42-
index_ = node.GetDataIndex();
4342
type_ = node.GetHybridType();
4443
PELOTON_ASSERT(table_ != nullptr);
4544

45+
// Get the index object from the index id
46+
oid_t index_id = node.GetIndexId();
47+
if (index_id != INVALID_OID) {
48+
index_ = table_->GetIndexWithOid(index_id);
49+
}
50+
4651
// SEQUENTIAL SCAN
4752
if (type_ == HybridScanType::SEQUENTIAL) {
4853
LOG_TRACE("Sequential Scan");
@@ -57,7 +62,6 @@ bool HybridScanExecutor::DInit() {
5762
// INDEX SCAN
5863
else if (type_ == HybridScanType::INDEX) {
5964
LOG_TRACE("Index Scan");
60-
index_ = node.GetIndex();
6165

6266
result_itr_ = START_OID;
6367
index_done_ = false;
@@ -72,6 +76,9 @@ bool HybridScanExecutor::DInit() {
7276
predicate_ = node.GetPredicate();
7377
key_ready_ = false;
7478

79+
index_predicate_.AddConjunctionScanPredicate(index_.get(), values_,
80+
key_column_ids_, expr_types_);
81+
7582
if (runtime_keys_.size() != 0) {
7683
assert(runtime_keys_.size() == values_.size());
7784

@@ -146,14 +153,18 @@ bool HybridScanExecutor::DInit() {
146153
}
147154
}
148155

156+
index_predicate_.AddConjunctionScanPredicate(index_.get(), values_,
157+
key_column_ids_, expr_types_);
158+
149159
if (table_ != nullptr) {
150160
full_column_ids_.resize(table_->GetSchema()->GetColumnCount());
151161
std::iota(full_column_ids_.begin(), full_column_ids_.end(), 0);
152162
}
153163
}
154164
// FALLBACK
155165
else {
156-
throw Exception("Invalid hybrid scan type : " + HybridScanTypeToString(type_));
166+
throw Exception("Invalid hybrid scan type : " +
167+
HybridScanTypeToString(type_));
157168
}
158169

159170
return true;
@@ -313,7 +324,8 @@ bool HybridScanExecutor::DExecute() {
313324
}
314325
// FALLBACK
315326
else {
316-
throw Exception("Invalid hybrid scan type : " + HybridScanTypeToString(type_));
327+
throw Exception("Invalid hybrid scan type : " +
328+
HybridScanTypeToString(type_));
317329
}
318330
}
319331

@@ -337,7 +349,7 @@ bool HybridScanExecutor::ExecPrimaryIndexLookup() {
337349
LOG_TRACE("Scan");
338350
index_->Scan(values_, key_column_ids_, expr_type_,
339351
ScanDirectionType::FORWARD, tuple_location_ptrs,
340-
&node.GetIndexPredicate().GetConjunctionList()[0]);
352+
&index_predicate_.GetConjunctionList()[0]);
341353
}
342354

343355
LOG_TRACE("Result tuple count: %lu", tuple_location_ptrs.size());

src/executor/index_scan_executor.cpp

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212

1313
#include "executor/index_scan_executor.h"
1414

15+
#include "catalog/catalog.h"
1516
#include "catalog/manager.h"
1617
#include "common/container_tuple.h"
18+
#include "common/internal_types.h"
1719
#include "common/logger.h"
1820
#include "concurrency/transaction_manager_factory.h"
1921
#include "executor/executor_context.h"
@@ -26,7 +28,6 @@
2628
#include "storage/masked_tuple.h"
2729
#include "storage/tile_group.h"
2830
#include "storage/tile_group_header.h"
29-
#include "common/internal_types.h"
3031
#include "type/value.h"
3132

3233
namespace peloton {
@@ -58,11 +59,6 @@ bool IndexScanExecutor::DInit() {
5859
// Grab info from plan node and check it
5960
const planner::IndexScanPlan &node = GetPlanNode<planner::IndexScanPlan>();
6061

61-
index_ = node.GetIndex();
62-
PELOTON_ASSERT(index_ != nullptr);
63-
64-
index_predicate_ = node.GetIndexPredicate();
65-
6662
result_itr_ = START_OID;
6763
result_.clear();
6864
done_ = false;
@@ -107,6 +103,18 @@ bool IndexScanExecutor::DInit() {
107103
std::iota(full_column_ids_.begin(), full_column_ids_.end(), 0);
108104
}
109105

106+
oid_t index_id = node.GetIndexId();
107+
index_ = table_->GetIndexWithOid(index_id);
108+
PELOTON_ASSERT(index_ != nullptr);
109+
110+
// Then add the only conjunction predicate into the index predicate list
111+
// (at least for now we only supports single conjunction)
112+
//
113+
// Values that are left blank will be recorded for future binding
114+
// and their offset inside the value array will be remembered
115+
index_predicate_.AddConjunctionScanPredicate(index_.get(), values_,
116+
key_column_ids_, expr_types_);
117+
110118
return true;
111119
}
112120

@@ -371,7 +379,6 @@ bool IndexScanExecutor::ExecPrimaryIndexLookup() {
371379
result_.push_back(logical_tile.release());
372380
}
373381

374-
375382
done_ = true;
376383

377384
LOG_TRACE("Result tiles : %lu", result_.size());
@@ -486,8 +493,8 @@ bool IndexScanExecutor::ExecSecondaryIndexLookup() {
486493
tuple_location.offset);
487494

488495
// Further check if the version has the secondary key
489-
ContainerTuple<storage::TileGroup> candidate_tuple(tile_group.get(),
490-
tuple_location.offset);
496+
ContainerTuple<storage::TileGroup> candidate_tuple(
497+
tile_group.get(), tuple_location.offset);
491498

492499
LOG_TRACE("candidate_tuple size: %s",
493500
candidate_tuple.GetInfo().c_str());
@@ -506,8 +513,9 @@ bool IndexScanExecutor::ExecSecondaryIndexLookup() {
506513
bool eval = true;
507514
// if having predicate, then perform evaluation.
508515
if (predicate_ != nullptr) {
509-
eval = predicate_->Evaluate(&candidate_tuple, nullptr,
510-
executor_context_).IsTrue();
516+
eval =
517+
predicate_->Evaluate(&candidate_tuple, nullptr, executor_context_)
518+
.IsTrue();
511519
}
512520
// if passed evaluation, then perform write.
513521
if (eval == true) {
@@ -845,8 +853,8 @@ void IndexScanExecutor::UpdatePredicate(
845853
}
846854

847855
// Update the new value
848-
index_predicate_.GetConjunctionListToSetup()[0]
849-
.SetTupleColumnValue(index_.get(), key_column_ids, values);
856+
index_predicate_.GetConjunctionListToSetup()[0].SetTupleColumnValue(
857+
index_.get(), key_column_ids, values);
850858
}
851859

852860
void IndexScanExecutor::ResetState() {

src/include/executor/hybrid_scan_executor.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212

1313
#pragma once
1414

15-
#include "storage/data_table.h"
16-
#include "index/index.h"
1715
#include "executor/abstract_scan_executor.h"
16+
#include "index/index.h"
1817
#include "planner/hybrid_scan_plan.h"
18+
#include "storage/data_table.h"
1919

2020
#include <set>
2121

@@ -92,6 +92,9 @@ class HybridScanExecutor : public AbstractScanExecutor {
9292
std::set<ItemPointer> item_pointers_;
9393

9494
oid_t block_threshold = 0;
95+
96+
// The predicate used for scanning the index
97+
index::IndexScanPredicate index_predicate_;
9598
};
9699

97100
} // namespace executor

src/include/executor/index_scan_executor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class IndexScanExecutor : public AbstractScanExecutor {
9393
std::shared_ptr<index::Index> index_;
9494

9595
// the underlying table that the index is for
96-
const storage::AbstractTable *table_ = nullptr;
96+
storage::DataTable *table_ = nullptr;
9797

9898
// columns to be returned as results
9999
std::vector<oid_t> column_ids_;

src/include/planner/hybrid_scan_plan.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,13 @@ class HybridScanPlan : public AbstractScan {
3838

3939
~HybridScanPlan() {}
4040

41-
std::shared_ptr<index::Index> GetDataIndex() const { return index_; }
42-
4341
std::unique_ptr<AbstractPlan> Copy() const {
4442
return std::unique_ptr<AbstractPlan>(nullptr);
4543
}
4644

4745
PlanNodeType GetPlanNodeType() const { return PlanNodeType::SEQSCAN; }
4846

49-
std::shared_ptr<index::Index> GetIndex() const { return index_; }
47+
oid_t GetIndexId() const { return index_id_; }
5048

5149
const std::vector<oid_t> &GetColumnIds() const { return column_ids_; }
5250

@@ -81,7 +79,7 @@ class HybridScanPlan : public AbstractScan {
8179

8280
const std::vector<expression::AbstractExpression *> runtime_keys_;
8381

84-
std::shared_ptr<index::Index> index_;
82+
oid_t index_id_;
8583

8684
index::IndexScanPredicate index_predicate_;
8785

@@ -90,4 +88,4 @@ class HybridScanPlan : public AbstractScan {
9088
};
9189

9290
} // namespace planner
93-
} // namespace peloton
91+
} // namespace peloton

src/include/planner/index_scan_plan.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class IndexScanPlan : public AbstractScan {
4646
* We need to do this since this might be created even when an index
4747
* is not required, e.g. inside hybrid scan
4848
*/
49-
IndexScanDesc() : index_obj{nullptr} {}
49+
IndexScanDesc() : index_id{INVALID_OID} {}
5050

5151
/*
5252
* Constructor
@@ -56,12 +56,12 @@ class IndexScanPlan : public AbstractScan {
5656
* be called to notify later procedures of the absense of an index
5757
*/
5858
IndexScanDesc(
59-
std::shared_ptr<index::Index> p_index_obj,
59+
oid_t p_index_id,
6060
const std::vector<oid_t> &p_tuple_column_id_list,
6161
const std::vector<ExpressionType> &expr_list_p,
6262
const std::vector<type::Value> &p_value_list,
6363
const std::vector<expression::AbstractExpression *> &p_runtime_key_list)
64-
: index_obj(p_index_obj),
64+
: index_id(p_index_id),
6565
tuple_column_id_list(p_tuple_column_id_list),
6666
expr_list(expr_list_p),
6767
value_list(p_value_list),
@@ -79,8 +79,8 @@ class IndexScanPlan : public AbstractScan {
7979
// argument. This is a bad design but currently we have to live with it
8080
// In order to prevent the scan predicate optimizer from trying to
8181
// optimizing the index scan while the index pointer is not valid
82-
// this should be set to 0 for an empty initialization
83-
std::shared_ptr<index::Index> index_obj;
82+
// this should be set to INVALID_OID for an empty initialization
83+
oid_t index_id;
8484

8585
// A list of columns id in the base table that has a scan predicate
8686
// (only for indexed column in the base table)
@@ -113,7 +113,7 @@ class IndexScanPlan : public AbstractScan {
113113
LOG_TRACE("Destroyed a index scan plan!");
114114
}
115115

116-
std::shared_ptr<index::Index> GetIndex() const { return index_; }
116+
oid_t GetIndexId() const { return index_id_; }
117117

118118
const std::vector<oid_t> &GetColumnIds() const { return column_ids_; }
119119

@@ -167,7 +167,7 @@ class IndexScanPlan : public AbstractScan {
167167
new_runtime_keys.push_back(key->Copy());
168168
}
169169

170-
IndexScanDesc desc(index_, key_column_ids_, expr_types_, values_,
170+
IndexScanDesc desc(index_id_, key_column_ids_, expr_types_, values_,
171171
new_runtime_keys);
172172
IndexScanPlan *new_plan = new IndexScanPlan(
173173
GetTable(), GetPredicate()->Copy(), GetColumnIds(), desc, false);
@@ -176,7 +176,7 @@ class IndexScanPlan : public AbstractScan {
176176

177177
private:
178178
/** @brief index associated with index scan. */
179-
std::shared_ptr<index::Index> index_;
179+
oid_t index_id_;
180180

181181
// A list of column IDs involved in the index scan no matter whether
182182
// it is indexed or not (i.e. select statement)
@@ -233,4 +233,4 @@ class IndexScanPlan : public AbstractScan {
233233
};
234234

235235
} // namespace planner
236-
} // namespace peloton
236+
} // namespace peloton

0 commit comments

Comments
 (0)