nodedb_physical/physical_task.rs
1// SPDX-License-Identifier: Apache-2.0
2
3use nodedb_types::id::{TxnId, VShardId};
4use nodedb_types::{DatabaseId, TenantId};
5
6use crate::physical_plan::PhysicalPlan;
7
8/// Post-execution set operation for merging multi-task results.
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10pub enum PostSetOp {
11 /// No post-merge (single task or independent tasks).
12 None,
13 /// UNION DISTINCT: deduplicate rows across sub-queries.
14 UnionDistinct,
15 /// INTERSECT: keep rows that appear in all sub-query results.
16 Intersect,
17 /// INTERSECT ALL: keep rows appearing in both (with multiplicity).
18 IntersectAll,
19 /// EXCEPT: keep rows from first that don't appear in second.
20 Except,
21 /// EXCEPT ALL: keep rows from first not in second (with multiplicity).
22 ExceptAll,
23}
24
25/// A physical execution task ready for dispatch to the Data Plane.
26///
27/// The planner produces these after converting a DataFusion logical plan
28/// into a concrete physical operation targeting a specific vShard.
29#[derive(Debug, Clone)]
30pub struct PhysicalTask {
31 /// Target tenant.
32 pub tenant_id: TenantId,
33
34 /// Target vShard (determines which Data Plane core handles this).
35 pub vshard_id: VShardId,
36
37 /// Database scope. All data access is restricted to this database namespace.
38 /// `DatabaseId::DEFAULT` (0) is the built-in `default` database.
39 pub database_id: DatabaseId,
40
41 /// The physical operation to execute.
42 pub plan: PhysicalPlan,
43
44 /// Post-execution merge operation for set operations (UNION, INTERSECT, EXCEPT).
45 pub post_set_op: PostSetOp,
46
47 /// Set when this task originates inside a session transaction block;
48 /// keys the per-transaction staging overlay. `None` for autocommit /
49 /// non-transactional / system tasks.
50 pub txn_id: Option<TxnId>,
51}