Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb::Planner Class Reference
Collaboration diagram for duckdb::Planner:

Public Member Functions

 Planner (ClientContext &context)
void CreatePlan (unique_ptr< SQLStatement > statement)

Static Public Member Functions

static void VerifyPlan (ClientContext &context, unique_ptr< LogicalOperator > &op, optional_ptr< bound_parameter_map_t > map=nullptr)

Public Attributes

unique_ptr< LogicalOperator > plan
vector< string > names
vector< LogicalType > types
case_insensitive_map_t< BoundParameterData > parameter_data
shared_ptr< Binder > binder
ClientContext & context
StatementProperties properties
bound_parameter_map_t value_map

Private Member Functions

void CreatePlan (SQLStatement &statement)
shared_ptr< PreparedStatementData > PrepareSQLStatement (unique_ptr< SQLStatement > statement)

Friends

class Binder

Detailed Description

The planner creates a logical query plan from the parsed SQL statements using the Binder and LogicalPlanGenerator.

Constructor & Destructor Documentation

◆ Planner()

duckdb::Planner::Planner ( ClientContext & context)
explicit
383529 : binder(Binder::CreateBinder(context)), context(context) {
383530}

Member Function Documentation

◆ CreatePlan() [1/2]

void duckdb::Planner::CreatePlan ( unique_ptr< SQLStatement > statement)
383638 {
383639 D_ASSERT(statement);
383640 switch (statement->type) {
383641 case StatementType::SELECT_STATEMENT:
383642 case StatementType::INSERT_STATEMENT:
383643 case StatementType::COPY_STATEMENT:
383644 case StatementType::DELETE_STATEMENT:
383645 case StatementType::UPDATE_STATEMENT:
383646 case StatementType::CREATE_STATEMENT:
383647 case StatementType::DROP_STATEMENT:
383648 case StatementType::ALTER_STATEMENT:
383649 case StatementType::TRANSACTION_STATEMENT:
383650 case StatementType::EXPLAIN_STATEMENT:
383651 case StatementType::VACUUM_STATEMENT:
383652 case StatementType::RELATION_STATEMENT:
383653 case StatementType::CALL_STATEMENT:
383654 case StatementType::EXPORT_STATEMENT:
383655 case StatementType::PRAGMA_STATEMENT:
383656 case StatementType::SET_STATEMENT:
383657 case StatementType::LOAD_STATEMENT:
383658 case StatementType::EXTENSION_STATEMENT:
383659 case StatementType::PREPARE_STATEMENT:
383660 case StatementType::EXECUTE_STATEMENT:
383661 case StatementType::LOGICAL_PLAN_STATEMENT:
383662 case StatementType::ATTACH_STATEMENT:
383663 case StatementType::DETACH_STATEMENT:
383664 case StatementType::COPY_DATABASE_STATEMENT:
383665 case StatementType::UPDATE_EXTENSIONS_STATEMENT:
383666 case StatementType::MERGE_INTO_STATEMENT:
383667 CreatePlan(*statement);
383668 break;
383669 default:
383670 throw NotImplementedException("Cannot plan statement of type %s!", StatementTypeToString(statement->type));
383671 }
383672}

◆ VerifyPlan()

void duckdb::Planner::VerifyPlan ( ClientContext & context,
unique_ptr< LogicalOperator > & op,
optional_ptr< bound_parameter_map_t > map = nullptr )
static

SELECT only for now

383684 {
383685 auto &config = DBConfig::GetConfig(context);
383686#ifdef DUCKDB_ALTERNATIVE_VERIFY
383687 {
383688 auto &serialize_comp = config.options.serialization_compatibility;
383689 auto latest_version = SerializationCompatibility::Latest();
383690 if (serialize_comp.manually_set &&
383691 serialize_comp.serialization_version != latest_version.serialization_version) {
383692 // Serialization should not be skipped, this test relies on the serialization to remove certain fields for
383693 // compatibility with older versions. This might change behavior, not doing this might make this test fail.
383694 } else {
383695 // if alternate verification is enabled we run the original operator
383696 return;
383697 }
383698 }
383699#endif
383700 if (!op || !ClientConfig::GetConfig(context).verify_serializer) {
383701 return;
383702 }
383704 if (!OperatorSupportsSerialization(*op)) {
383705 return;
383706 }
383707 // verify the column bindings of the plan
383708 ColumnBindingResolver::Verify(*op);
383709
383710 // format (de)serialization of this operator
383711 try {
383712 MemoryStream stream(Allocator::Get(context));
383713
383714 SerializationOptions options;
383715 if (config.options.serialization_compatibility.manually_set) {
383716 // Override the default of 'latest' if this was manually set (for testing, mostly)
383717 options.serialization_compatibility = config.options.serialization_compatibility;
383718 } else {
383719 options.serialization_compatibility = SerializationCompatibility::Latest();
383720 }
383721
383722 BinarySerializer::Serialize(*op, stream, options);
383723 stream.Rewind();
383724 bound_parameter_map_t parameters;
383725 auto new_plan = BinaryDeserializer::Deserialize<LogicalOperator>(stream, context, parameters);
383726
383727 if (map) {
383728 *map = std::move(parameters);
383729 }
383730 op = std::move(new_plan);
383731 } catch (std::exception &ex) {
383732 ErrorData error(ex);
383733 switch (error.Type()) {
383734 case ExceptionType::NOT_IMPLEMENTED: // NOLINT: explicitly allowing these errors (for now)
383735 break; // pass
383736 default:
383737 throw;
383738 }
383739 }
383740}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreatePlan() [2/2]

void duckdb::Planner::CreatePlan ( SQLStatement & statement)
private
383550 {
383551 auto &profiler = QueryProfiler::Get(context);
383552 auto parameter_count = statement.named_param_map.size();
383553
383554 BoundParameterMap bound_parameters(parameter_data);
383555
383556 // first bind the tables and columns to the catalog
383557 bool parameters_resolved = true;
383558 try {
383559 profiler.StartPhase(MetricType::PLANNER_BINDING);
383560 binder->SetParameters(bound_parameters);
383561 auto bound_statement = binder->Bind(statement);
383562 profiler.EndPhase();
383563
383564 RunPostBindExtensions(context, *binder, bound_statement);
383565
383566 this->names = bound_statement.names;
383567 this->types = bound_statement.types;
383568 this->plan = std::move(bound_statement.plan);
383569 } catch (const std::exception &ex) {
383570 ErrorData error(ex);
383571 this->plan = nullptr;
383572 if (error.Type() == ExceptionType::PARAMETER_NOT_RESOLVED) {
383573 // parameter types could not be resolved
383574 this->names = {"unknown"};
383575 this->types = {LogicalTypeId::UNKNOWN};
383576 parameters_resolved = false;
383577 } else if (error.Type() != ExceptionType::INVALID) {
383578 // different exception type - try operator_extensions
383579 for (auto &extension_op : OperatorExtension::Iterate(context)) {
383580 auto bound_statement =
383581 extension_op->Bind(context, *this->binder, extension_op->operator_info.get(), statement);
383582 if (bound_statement.plan != nullptr) {
383583 RunPostBindExtensions(context, *this->binder, bound_statement);
383584
383585 this->names = bound_statement.names;
383586 this->types = bound_statement.types;
383587 this->plan = std::move(bound_statement.plan);
383588 break;
383589 }
383590 }
383591 if (!this->plan) {
383592 throw;
383593 }
383594 } else {
383595 throw;
383596 }
383597 }
383598 if (this->plan) {
383599 auto max_tree_depth = Settings::Get<MaxExpressionDepthSetting>(context);
383600 CheckTreeDepth(*plan, max_tree_depth);
383601
383602 this->plan = FlattenDependentJoins::DecorrelateIndependent(*this->binder, std::move(this->plan));
383603 }
383604 this->properties = binder->GetStatementProperties();
383605 this->properties.parameter_count = parameter_count;
383606 properties.bound_all_parameters = !bound_parameters.rebind && parameters_resolved;
383607
383608 Planner::VerifyPlan(context, plan, bound_parameters.GetParametersPtr());
383609
383610 // set up a map of parameter number -> value entries
383611 for (auto &kv : bound_parameters.GetParameters()) {
383612 auto &identifier = kv.first;
383613 auto &param = kv.second;
383614 // check if the type of the parameter could be resolved
383615 if (!param->return_type.IsValid()) {
383616 properties.bound_all_parameters = false;
383617 continue;
383618 }
383619 param->SetValue(Value(param->return_type));
383620 value_map[identifier] = param;
383621 }
383622}
static void VerifyPlan(ClientContext &context, unique_ptr< LogicalOperator > &op, optional_ptr< bound_parameter_map_t > map=nullptr)
Definition duckdb.cpp:383683

◆ PrepareSQLStatement()

shared_ptr< PreparedStatementData > duckdb::Planner::PrepareSQLStatement ( unique_ptr< SQLStatement > statement)
private
383624 {
383625 auto copied_statement = statement->Copy();
383626 // create a plan of the underlying statement
383627 CreatePlan(std::move(statement));
383628 // now create the logical prepare
383629 auto prepared_data = make_shared_ptr<PreparedStatementData>(copied_statement->type);
383630 prepared_data->unbound_statement = std::move(copied_statement);
383631 prepared_data->names = names;
383632 prepared_data->types = types;
383633 prepared_data->value_map = std::move(value_map);
383634 prepared_data->properties = properties;
383635 return prepared_data;
383636}

The documentation for this class was generated from the following file: