1 | //===----------------------------------------------------------------------===// |
2 | // DuckDB |
3 | // |
4 | // duckdb/execution/physical_operator_states.hpp |
5 | // |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #pragma once |
10 | |
11 | #include "duckdb/catalog/catalog.hpp" |
12 | #include "duckdb/common/common.hpp" |
13 | #include "duckdb/common/enums/operator_result_type.hpp" |
14 | #include "duckdb/common/enums/physical_operator_type.hpp" |
15 | #include "duckdb/common/types/data_chunk.hpp" |
16 | #include "duckdb/execution/execution_context.hpp" |
17 | #include "duckdb/optimizer/join_order/join_node.hpp" |
18 | |
19 | namespace duckdb { |
20 | class Event; |
21 | class Executor; |
22 | class PhysicalOperator; |
23 | class Pipeline; |
24 | class PipelineBuildState; |
25 | class MetaPipeline; |
26 | class InterruptState; |
27 | |
28 | struct SourcePartitionInfo { |
29 | //! The current batch index |
30 | //! This is only set in case RequiresBatchIndex() is true, and the source has support for it (SupportsBatchIndex()) |
31 | //! Otherwise this is left on INVALID_INDEX |
32 | //! The batch index is a globally unique, increasing index that should be used to maintain insertion order |
33 | //! //! in conjunction with parallelism |
34 | optional_idx batch_index; |
35 | //! The minimum batch index that any thread is currently actively reading |
36 | optional_idx min_batch_index; |
37 | }; |
38 | |
39 | // LCOV_EXCL_START |
40 | class OperatorState { |
41 | public: |
42 | virtual ~OperatorState() { |
43 | } |
44 | |
45 | virtual void Finalize(const PhysicalOperator &op, ExecutionContext &context) { |
46 | } |
47 | |
48 | template <class TARGET> |
49 | TARGET &Cast() { |
50 | D_ASSERT(dynamic_cast<TARGET *>(this)); |
51 | return reinterpret_cast<TARGET &>(*this); |
52 | } |
53 | template <class TARGET> |
54 | const TARGET &Cast() const { |
55 | D_ASSERT(dynamic_cast<const TARGET *>(this)); |
56 | return reinterpret_cast<const TARGET &>(*this); |
57 | } |
58 | }; |
59 | |
60 | class GlobalOperatorState { |
61 | public: |
62 | virtual ~GlobalOperatorState() { |
63 | } |
64 | |
65 | template <class TARGET> |
66 | TARGET &Cast() { |
67 | D_ASSERT(dynamic_cast<TARGET *>(this)); |
68 | return reinterpret_cast<TARGET &>(*this); |
69 | } |
70 | template <class TARGET> |
71 | const TARGET &Cast() const { |
72 | D_ASSERT(dynamic_cast<const TARGET *>(this)); |
73 | return reinterpret_cast<const TARGET &>(*this); |
74 | } |
75 | }; |
76 | |
77 | class GlobalSinkState { |
78 | public: |
79 | GlobalSinkState() : state(SinkFinalizeType::READY) { |
80 | } |
81 | virtual ~GlobalSinkState() { |
82 | } |
83 | |
84 | SinkFinalizeType state; |
85 | |
86 | template <class TARGET> |
87 | TARGET &Cast() { |
88 | D_ASSERT(dynamic_cast<TARGET *>(this)); |
89 | return reinterpret_cast<TARGET &>(*this); |
90 | } |
91 | template <class TARGET> |
92 | const TARGET &Cast() const { |
93 | D_ASSERT(dynamic_cast<const TARGET *>(this)); |
94 | return reinterpret_cast<const TARGET &>(*this); |
95 | } |
96 | }; |
97 | |
98 | class LocalSinkState { |
99 | public: |
100 | virtual ~LocalSinkState() { |
101 | } |
102 | |
103 | //! Source partition info |
104 | SourcePartitionInfo partition_info; |
105 | |
106 | template <class TARGET> |
107 | TARGET &Cast() { |
108 | D_ASSERT(dynamic_cast<TARGET *>(this)); |
109 | return reinterpret_cast<TARGET &>(*this); |
110 | } |
111 | template <class TARGET> |
112 | const TARGET &Cast() const { |
113 | D_ASSERT(dynamic_cast<const TARGET *>(this)); |
114 | return reinterpret_cast<const TARGET &>(*this); |
115 | } |
116 | }; |
117 | |
118 | class GlobalSourceState { |
119 | public: |
120 | virtual ~GlobalSourceState() { |
121 | } |
122 | |
123 | virtual idx_t MaxThreads() { |
124 | return 1; |
125 | } |
126 | |
127 | template <class TARGET> |
128 | TARGET &Cast() { |
129 | D_ASSERT(dynamic_cast<TARGET *>(this)); |
130 | return reinterpret_cast<TARGET &>(*this); |
131 | } |
132 | template <class TARGET> |
133 | const TARGET &Cast() const { |
134 | D_ASSERT(dynamic_cast<const TARGET *>(this)); |
135 | return reinterpret_cast<const TARGET &>(*this); |
136 | } |
137 | }; |
138 | |
139 | class LocalSourceState { |
140 | public: |
141 | virtual ~LocalSourceState() { |
142 | } |
143 | |
144 | template <class TARGET> |
145 | TARGET &Cast() { |
146 | D_ASSERT(dynamic_cast<TARGET *>(this)); |
147 | return reinterpret_cast<TARGET &>(*this); |
148 | } |
149 | template <class TARGET> |
150 | const TARGET &Cast() const { |
151 | D_ASSERT(dynamic_cast<const TARGET *>(this)); |
152 | return reinterpret_cast<const TARGET &>(*this); |
153 | } |
154 | }; |
155 | |
156 | struct OperatorSinkInput { |
157 | GlobalSinkState &global_state; |
158 | LocalSinkState &local_state; |
159 | InterruptState &interrupt_state; |
160 | }; |
161 | |
162 | struct OperatorSourceInput { |
163 | GlobalSourceState &global_state; |
164 | LocalSourceState &local_state; |
165 | InterruptState &interrupt_state; |
166 | }; |
167 | |
168 | // LCOV_EXCL_STOP |
169 | |
170 | } // namespace duckdb |
171 | |