//===----------------------------------------------------------------------===// // DuckDB // // duckdb/execution/operator/join/physical_index_join.hpp // // //===----------------------------------------------------------------------===// #pragma once #include "duckdb/common/types/chunk_collection.hpp" #include "duckdb/execution/operator/join/physical_comparison_join.hpp" #include "duckdb/execution/physical_operator.hpp" #include "duckdb/planner/operator/logical_join.hpp" #include "duckdb/storage/index.hpp" namespace duckdb { //! PhysicalIndexJoin represents an index join between two tables class PhysicalIndexJoin : public CachingPhysicalOperator { public: static constexpr const PhysicalOperatorType TYPE = PhysicalOperatorType::INDEX_JOIN; public: PhysicalIndexJoin(LogicalOperator &op, unique_ptr left, unique_ptr right, vector cond, JoinType join_type, const vector &left_projection_map, vector right_projection_map, vector column_ids, Index &index, bool lhs_first, idx_t estimated_cardinality); //! Columns from RHS used in the query vector column_ids; //! Columns to be fetched vector fetch_ids; //! Types of fetch columns vector fetch_types; //! Columns indexed by index unordered_set index_ids; //! Projected ids from LHS vector left_projection_map; //! Projected ids from RHS vector right_projection_map; //! The types of the keys vector condition_types; //! The types of all conditions vector build_types; //! Index used for join Index &index; vector conditions; JoinType join_type; //! In case we swap rhs with lhs we need to output columns related to rhs first. bool lhs_first = true; public: unique_ptr GetOperatorState(ExecutionContext &context) const override; OrderPreservationType OperatorOrder() const override { return OrderPreservationType::NO_ORDER; } bool ParallelOperator() const override { return true; } protected: OperatorResultType ExecuteInternal(ExecutionContext &context, DataChunk &input, DataChunk &chunk, GlobalOperatorState &gstate, OperatorState &state) const override; public: void BuildPipelines(Pipeline ¤t, MetaPipeline &meta_pipeline) override; vector> GetSources() const override; private: void GetRHSMatches(ExecutionContext &context, DataChunk &input, OperatorState &state_p) const; //! Fills result chunk void Output(ExecutionContext &context, DataChunk &input, DataChunk &chunk, OperatorState &state_p) const; }; } // namespace duckdb