Hack in SelectOperator.
diff --git a/query_optimizer/ExecutionGenerator.cpp b/query_optimizer/ExecutionGenerator.cpp
index 3dcc825..037735f 100644
--- a/query_optimizer/ExecutionGenerator.cpp
+++ b/query_optimizer/ExecutionGenerator.cpp
@@ -492,21 +492,17 @@
// Use the "simple" form of the selection operator (a pure projection that
// doesn't require any expression evaluation or intermediate copies) if
// possible.
- std::unique_ptr<std::vector<attribute_id>> attributes(new std::vector<attribute_id>());
- SelectOperator *op
- = convertSimpleProjection(project_expressions_group_index, attributes.get())
- ? new SelectOperator(*input_relation_info->relation,
- *output_relation,
- insert_destination_index,
- execution_predicate_index,
- attributes.release(),
- input_relation_info->isStoredRelation())
- : new SelectOperator(*input_relation_info->relation,
- *output_relation,
- insert_destination_index,
- execution_predicate_index,
- project_expressions_group_index,
- input_relation_info->isStoredRelation());
+ std::vector<attribute_id> attributes;
+ convertSimpleProjection(project_expressions_group_index, &attributes);
+
+ SelectOperator *op =
+ new SelectOperator(*input_relation_info->relation,
+ *output_relation,
+ insert_destination_index,
+ execution_predicate_index,
+ move(attributes),
+ project_expressions_group_index,
+ input_relation_info->isStoredRelation());
const QueryPlan::DAGNodeIndex select_index =
execution_plan_->addRelationalOperator(op);
@@ -1080,12 +1076,12 @@
findRelationInfoOutputByPhysical(physical_plan->selection());
// Prepare the attributes, which are output columns of the selection relation.
- std::unique_ptr<std::vector<attribute_id>> attributes(new std::vector<attribute_id>());
+ std::vector<attribute_id> attributes;
for (E::AttributeReferencePtr attr_ref : physical_plan->selection()->getOutputAttributes()) {
unique_ptr<const Scalar> attribute(attr_ref->concretize(attribute_substitution_map_));
DCHECK_EQ(Scalar::kAttribute, attribute->getDataSource());
- attributes->emplace_back(
+ attributes.emplace_back(
static_cast<const ScalarAttribute*>(attribute.get())->getAttribute().getID());
}
@@ -1101,7 +1097,8 @@
destination_relation,
insert_destination_index,
QueryContext::kInvalidPredicateId,
- attributes.release(),
+ move(attributes),
+ QueryContext::kInvalidScalarGroupId,
selection_relation_info->isStoredRelation());
const QueryPlan::DAGNodeIndex insert_selection_index =
diff --git a/relational_operators/SelectOperator.cpp b/relational_operators/SelectOperator.cpp
index 3c2462d..e15f0c5 100644
--- a/relational_operators/SelectOperator.cpp
+++ b/relational_operators/SelectOperator.cpp
@@ -63,7 +63,7 @@
input_block_id,
predicate,
simple_projection_,
- *simple_selection_,
+ simple_selection_,
selection,
output_destination,
storage_manager),
@@ -80,7 +80,7 @@
input_relation_block_ids_[num_workorders_generated_],
predicate,
simple_projection_,
- *simple_selection_,
+ simple_selection_,
selection,
output_destination,
storage_manager),
@@ -121,7 +121,7 @@
proto->SetExtension(serialization::SelectWorkOrder::block_id, block);
proto->SetExtension(serialization::SelectWorkOrder::simple_projection, simple_projection_);
if (simple_projection_) {
- for (const attribute_id attr_id : *simple_selection_) {
+ for (const attribute_id attr_id : simple_selection_) {
proto->AddExtension(serialization::SelectWorkOrder::simple_selection, attr_id);
}
}
diff --git a/relational_operators/SelectOperator.hpp b/relational_operators/SelectOperator.hpp
index c060c7f..b810c14 100644
--- a/relational_operators/SelectOperator.hpp
+++ b/relational_operators/SelectOperator.hpp
@@ -68,6 +68,8 @@
* @param predicate_index The index of selection predicate in QueryContext.
* All tuples matching pred will be selected (or kInvalidPredicateId to
* select all tuples).
+ * @param selection A projection list of attribute IDs. The operator takes
+ * ownership of selection.
* @param selection_index The group index of Scalars in QueryContext, which
* will be evaluated to project input tuples.
* @param input_relation_is_stored If input_relation is a stored relation and
@@ -78,55 +80,19 @@
const CatalogRelation &output_relation,
const QueryContext::insert_destination_id output_destination_index,
const QueryContext::predicate_id predicate_index,
+ std::vector<attribute_id> &&selection,
const QueryContext::scalar_group_id selection_index,
- bool input_relation_is_stored)
+ const bool input_relation_is_stored)
: input_relation_(input_relation),
output_relation_(output_relation),
output_destination_index_(output_destination_index),
predicate_index_(predicate_index),
selection_index_(selection_index),
- simple_selection_(nullptr),
+ simple_selection_(std::move(selection)),
input_relation_block_ids_(input_relation_is_stored ? input_relation.getBlocksSnapshot()
: std::vector<block_id>()),
num_workorders_generated_(0),
- simple_projection_(false),
- input_relation_is_stored_(input_relation_is_stored),
- started_(false) {}
-
- /**
- * @brief Constructor for selection with simple projection of attributes.
- *
- * @note selection_index_ is invalid, and will not be used for projection.
- *
- * @param input_relation The relation to perform selection over.
- * @param output_relation The output relation.
- * @param output_destination_index The index of the InsertDestination in the
- * QueryContext to insert the selection results.
- * @param selection A projection list of attribute IDs. The operator takes
- * ownership of selection.
- * @param predicate_index The index of selection predicate in QueryContext.
- * All tuples matching pred will be selected (or kInvalidPredicateId to
- * select all tuples).
- * @param input_relation_is_stored If input_relation is a stored relation and
- * is fully available to the operator before it can start generating
- * workorders.
- **/
- SelectOperator(const CatalogRelation &input_relation,
- const CatalogRelation &output_relation,
- const QueryContext::insert_destination_id output_destination_index,
- const QueryContext::predicate_id predicate_index,
- std::vector<attribute_id> *selection,
- bool input_relation_is_stored)
- : input_relation_(input_relation),
- output_relation_(output_relation),
- output_destination_index_(output_destination_index),
- predicate_index_(predicate_index),
- selection_index_(QueryContext::kInvalidScalarGroupId),
- simple_selection_(selection),
- input_relation_block_ids_(input_relation_is_stored ? input_relation.getBlocksSnapshot()
- : std::vector<block_id>()),
- num_workorders_generated_(0),
- simple_projection_(true),
+ simple_projection_(!simple_selection_.empty()),
input_relation_is_stored_(input_relation_is_stored),
started_(false) {}
@@ -173,7 +139,7 @@
const QueryContext::predicate_id predicate_index_;
const QueryContext::scalar_group_id selection_index_;
- std::unique_ptr<std::vector<attribute_id> > simple_selection_;
+ const std::vector<attribute_id> simple_selection_;
std::vector<block_id> input_relation_block_ids_;
@@ -195,8 +161,8 @@
/**
* @brief Constructor.
*
- * @note Reference parameters simple_selection and selection are NOT owned by
- * this class and must remain valid until after execute() is called.
+ * @note Reference parameter selection is NOT owned by this class and must
+ * remain valid until after execute() is called.
*
* @param input_relation The relation to perform selection over.
* @param input_block_id The block id.
@@ -231,8 +197,8 @@
/**
* @brief Constructor for the distributed version.
*
- * @note Reference parameters simple_selection and selection are NOT owned by
- * this class and must remain valid until after execute() is called.
+ * @note Reference parameter selection is NOT owned by this class and must
+ * remain valid until after execute() is called.
*
* @param input_relation The relation to perform selection over.
* @param input_block_id The block id.
@@ -263,6 +229,7 @@
selection_(selection),
output_destination_(DCHECK_NOTNULL(output_destination)),
storage_manager_(DCHECK_NOTNULL(storage_manager)) {}
+
~SelectWorkOrder() override {}
/**
diff --git a/relational_operators/WorkOrderFactory.cpp b/relational_operators/WorkOrderFactory.cpp
index 73dc232..3dc96b8 100644
--- a/relational_operators/WorkOrderFactory.cpp
+++ b/relational_operators/WorkOrderFactory.cpp
@@ -503,11 +503,13 @@
}
}
+ /*
if (proto.GetExtension(serialization::SelectWorkOrder::simple_projection) ==
query_context.isValidScalarGroupId(
proto.GetExtension(serialization::SelectWorkOrder::selection_index))) {
return false;
}
+ */
return proto.HasExtension(serialization::SelectWorkOrder::insert_destination_index)
&& query_context.isValidInsertDestinationId(