SeqScanPlan::SeqScanPlan(parser::SelectStatement *select_node) { LOG_DEBUG("Creating a Sequential Scan Plan"); auto target_table = static_cast<storage::DataTable *>( catalog::Catalog::GetInstance()->GetTableWithName( select_node->from_table->GetDatabaseName(), select_node->from_table->GetTableName())); SetTargetTable(target_table); ColumnIds().clear(); // Check if there is an aggregate function in query bool function_found = false; for (auto elem : *select_node->select_list) { if (elem->GetExpressionType() == EXPRESSION_TYPE_FUNCTION_REF) { function_found = true; break; } } // Pass all columns // TODO: This isn't efficient. Needs to be fixed if (function_found) { for (auto column : GetTable()->GetSchema()->GetColumns()) { oid_t col_id = SeqScanPlan::GetColumnID(column.column_name); SetColumnId(col_id); } } // Pass columns in select_list else { if (select_node->select_list->at(0)->GetExpressionType() != EXPRESSION_TYPE_STAR) { for (auto col : *select_node->select_list) { LOG_TRACE("ExpressionType: %s", ExpressionTypeToString(col->GetExpressionType()).c_str()); auto col_name = col->GetName(); oid_t col_id = SeqScanPlan::GetColumnID(std::string(col_name)); SetColumnId(col_id); } } else { auto allColumns = GetTable()->GetSchema()->GetColumns(); for (uint i = 0; i < allColumns.size(); i++) SetColumnId(i); } } // Check for "For Update" flag if(select_node->is_for_update == true){ SetForUpdateFlag(true); } // Keep a copy of the where clause to be binded to values if (select_node->where_clause != NULL) { auto predicate = select_node->where_clause->Copy(); // Replace COLUMN_REF expressions with TupleValue expressions expression::ExpressionUtil::ReplaceColumnExpressions(GetTable()->GetSchema(), predicate); predicate_with_params_ = std::unique_ptr<expression::AbstractExpression>(predicate->Copy()); SetPredicate(predicate); } }
PlanContext LogicalSort::GetPlanContext() { lock_->acquire(); if (NULL != plan_context_) { lock_->release(); return *plan_context_; } // Get the information from its child PlanContext child_plan_context_ = child_->GetPlanContext(); PlanContext ret; ret.attribute_list_ = child_plan_context_.attribute_list_; ret.commu_cost_ = child_plan_context_.commu_cost_; ret.plan_partitioner_.set_partition_func( child_plan_context_.plan_partitioner_.get_partition_func()); ret.plan_partitioner_.set_partition_key(Attribute()); NodeID location = 0; unsigned long data_cardinality = 0; PartitionOffset offset = 0; PlanPartitionInfo par(offset, data_cardinality, location); vector<PlanPartitionInfo> partition_list; partition_list.push_back(par); ret.plan_partitioner_.set_partition_list(partition_list); SetColumnId(child_plan_context_); LogicInitCnxt licnxt; licnxt.schema0_ = GetSchema(child_plan_context_.attribute_list_); GetColumnToId(child_plan_context_.attribute_list_, licnxt.column_id0_); for (int i = 0; i < order_by_attrs_.size(); ++i) { licnxt.return_type_ = order_by_attrs_[i].first->actual_type_; order_by_attrs_[i].first->InitExprAtLogicalPlan(licnxt); } plan_context_ = new PlanContext(); *plan_context_ = ret; lock_->release(); return ret; }
/** * Therefore a SeqScanPlan is serialized as: * [(int) total size] * [(int8_t) plan type] * [(int) database_id] * [(int) table_id] * [(int) num column_id] * [(int) column id...] * [(int8_t) expr type] : if invalid, predicate is null * [(bytes) predicate] : predicate is Expression * [(int8_t) plan type] : if invalid, parent is null * [(bytes) parent] : parent is also a plan */ bool SeqScanPlan::DeserializeFrom(SerializeInput &input) { // Read the size of SeqScanPlan class input.ReadInt(); // Read the type UNUSED_ATTRIBUTE PlanNodeType plan_type = (PlanNodeType)input.ReadEnumInSingleByte(); PL_ASSERT(plan_type == GetPlanNodeType()); // Read database id oid_t database_oid = input.ReadInt(); // Read table id oid_t table_oid = input.ReadInt(); // Get table and set it to the member storage::DataTable *target_table = static_cast<storage::DataTable *>( catalog::Catalog::GetInstance()->GetTableWithOid(database_oid, table_oid)); SetTargetTable(target_table); // Read the number of column_id and set them to column_ids_ oid_t columnid_count = input.ReadInt(); for (oid_t it = 0; it < columnid_count; it++) { oid_t column_id = input.ReadInt(); SetColumnId(column_id); } // Read the type ExpressionType expr_type = (ExpressionType)input.ReadEnumInSingleByte(); // Predicate deserialization if (expr_type != EXPRESSION_TYPE_INVALID) { switch (expr_type) { // case EXPRESSION_TYPE_COMPARE_IN: // predicate_ = // std::unique_ptr<EXPRESSION_TYPE_COMPARE_IN>(new // ComparisonExpression (101)); // predicate_.DeserializeFrom(input); // break; default: { LOG_ERROR( "Expression deserialization :: Unsupported EXPRESSION_TYPE: %u ", expr_type); break; } } } // Read the type of parent PlanNodeType parent_type = (PlanNodeType)input.ReadEnumInSingleByte(); // Parent deserialization if (parent_type != PLAN_NODE_TYPE_INVALID) { switch (expr_type) { // case EXPRESSION_TYPE_COMPARE_IN: // predicate_ = // std::unique_ptr<EXPRESSION_TYPE_COMPARE_IN>(new // ComparisonExpression (101)); // predicate_.DeserializeFrom(input); // break; default: { LOG_ERROR("Parent deserialization :: Unsupported PlanNodeType: %u ", expr_type); break; } } } return true; }