//===----------------------------------------------------------------------===// // DuckDB // // duckdb/execution/physical_plan_generator.hpp // // //===----------------------------------------------------------------------===// #pragma once #include "duckdb/common/common.hpp" #include "duckdb/execution/physical_operator.hpp" #include "duckdb/planner/logical_operator.hpp" #include "duckdb/planner/logical_tokens.hpp" #include "duckdb/planner/operator/logical_limit_percent.hpp" #include "duckdb/catalog/dependency_list.hpp" #include "duckdb/common/unordered_map.hpp" #include "duckdb/common/unordered_set.hpp" namespace duckdb { class ClientContext; class ColumnDataCollection; //! The physical plan generator generates a physical execution plan from a //! logical query plan class PhysicalPlanGenerator { public: explicit PhysicalPlanGenerator(ClientContext &context); ~PhysicalPlanGenerator(); DependencyList dependencies; //! Recursive CTEs require at least one ChunkScan, referencing the working_table. //! This data structure is used to establish it. unordered_map> recursive_cte_tables; public: //! Creates a plan from the logical operator. This involves resolving column bindings and generating physical //! operator nodes. unique_ptr CreatePlan(unique_ptr logical); //! Whether or not we can (or should) use a batch-index based operator for executing the given sink static bool UseBatchIndex(ClientContext &context, PhysicalOperator &plan); //! Whether or not we should preserve insertion order for executing the given sink static bool PreserveInsertionOrder(ClientContext &context, PhysicalOperator &plan); protected: unique_ptr CreatePlan(LogicalOperator &op); unique_ptr CreatePlan(LogicalAggregate &op); unique_ptr CreatePlan(LogicalAnyJoin &op); unique_ptr CreatePlan(LogicalAsOfJoin &op); unique_ptr CreatePlan(LogicalColumnDataGet &op); unique_ptr CreatePlan(LogicalComparisonJoin &op); unique_ptr CreatePlan(LogicalCreate &op); unique_ptr CreatePlan(LogicalCreateTable &op); unique_ptr CreatePlan(LogicalCreateIndex &op); unique_ptr CreatePlan(LogicalCrossProduct &op); unique_ptr CreatePlan(LogicalDelete &op); unique_ptr CreatePlan(LogicalDelimGet &op); unique_ptr CreatePlan(LogicalDelimJoin &op); unique_ptr CreatePlan(LogicalDistinct &op); unique_ptr CreatePlan(LogicalDummyScan &expr); unique_ptr CreatePlan(LogicalEmptyResult &op); unique_ptr CreatePlan(LogicalExpressionGet &op); unique_ptr CreatePlan(LogicalExport &op); unique_ptr CreatePlan(LogicalFilter &op); unique_ptr CreatePlan(LogicalGet &op); unique_ptr CreatePlan(LogicalLimit &op); unique_ptr CreatePlan(LogicalLimitPercent &op); unique_ptr CreatePlan(LogicalOrder &op); unique_ptr CreatePlan(LogicalTopN &op); unique_ptr CreatePlan(LogicalPositionalJoin &op); unique_ptr CreatePlan(LogicalProjection &op); unique_ptr CreatePlan(LogicalInsert &op); unique_ptr CreatePlan(LogicalCopyToFile &op); unique_ptr CreatePlan(LogicalExplain &op); unique_ptr CreatePlan(LogicalSetOperation &op); unique_ptr CreatePlan(LogicalUpdate &op); unique_ptr CreatePlan(LogicalPrepare &expr); unique_ptr CreatePlan(LogicalWindow &expr); unique_ptr CreatePlan(LogicalExecute &op); unique_ptr CreatePlan(LogicalPragma &op); unique_ptr CreatePlan(LogicalSample &op); unique_ptr CreatePlan(LogicalSet &op); unique_ptr CreatePlan(LogicalReset &op); unique_ptr CreatePlan(LogicalShow &op); unique_ptr CreatePlan(LogicalSimple &op); unique_ptr CreatePlan(LogicalUnnest &op); unique_ptr CreatePlan(LogicalRecursiveCTE &op); unique_ptr CreatePlan(LogicalCTERef &op); unique_ptr CreatePlan(LogicalPivot &op); unique_ptr ExtractAggregateExpressions(unique_ptr child, vector> &expressions, vector> &groups); private: bool PreserveInsertionOrder(PhysicalOperator &plan); bool UseBatchIndex(PhysicalOperator &plan); private: ClientContext &context; }; } // namespace duckdb