Skip to main content

radixdb_executor/
compiled_plan.rs

1//! Cached execution descriptors shared by statement dispatch and fast paths.
2
3use std::sync::Arc;
4
5use radixdb_core::{CompactArc, DataType, Schema, SmartString, Value};
6
7/// How a compiled statement obtains its primary-key value.
8#[derive(Debug, Clone)]
9pub enum PkValueSource {
10    Parameter(usize),
11    Literal(i64),
12    NamedParameter(SmartString),
13}
14
15/// Pre-bound state for `SELECT * ... WHERE pk = value`.
16#[derive(Debug, Clone)]
17pub struct CompiledPkLookup {
18    pub table_name: SmartString,
19    pub schema: CompactArc<Schema>,
20    pub column_names: CompactArc<Vec<String>>,
21    pub pk_value_source: PkValueSource,
22    pub cached_epoch: u64,
23}
24
25/// One pre-bound UPDATE assignment.
26#[derive(Debug, Clone)]
27pub struct CompiledUpdateColumn {
28    pub column_idx: usize,
29    pub column_type: DataType,
30    pub value_source: UpdateValueSource,
31}
32
33/// How a compiled UPDATE obtains an assignment value.
34#[derive(Debug, Clone)]
35pub enum UpdateValueSource {
36    Literal(Value),
37    Parameter(usize),
38    NamedParameter(SmartString),
39}
40
41/// Pre-bound state for a primary-key UPDATE.
42#[derive(Debug, Clone)]
43pub struct CompiledPkUpdate {
44    pub table_name: SmartString,
45    pub schema: CompactArc<Schema>,
46    pub pk_column_name: SmartString,
47    pub pk_value_source: PkValueSource,
48    pub updates: Vec<CompiledUpdateColumn>,
49    pub cached_epoch: u64,
50}
51
52/// Pre-bound state for a primary-key DELETE.
53#[derive(Debug, Clone)]
54pub struct CompiledPkDelete {
55    pub table_name: SmartString,
56    pub schema: CompactArc<Schema>,
57    pub pk_column_name: SmartString,
58    pub pk_value_source: PkValueSource,
59    pub cached_epoch: u64,
60}
61
62/// Schema-derived INSERT state reused by cached statements.
63#[derive(Debug, Clone)]
64pub struct CompiledInsert {
65    pub table_name: SmartString,
66    pub column_indices: Arc<Vec<usize>>,
67    pub column_types: Arc<Vec<DataType>>,
68    pub column_vector_dims: Arc<Vec<u16>>,
69    pub column_names: Arc<Vec<SmartString>>,
70    pub all_column_types: Arc<Vec<DataType>>,
71    pub default_row_template: Arc<Vec<Value>>,
72    pub cached_epoch: u64,
73}
74
75/// Pre-bound state for `COUNT(DISTINCT column)`.
76#[derive(Debug, Clone)]
77pub struct CompiledCountDistinct {
78    pub table_name: SmartString,
79    pub column_name: SmartString,
80    pub result_column_name: String,
81    pub cached_epoch: u64,
82}
83
84/// Pre-bound state for `COUNT(*)`.
85#[derive(Debug, Clone)]
86pub struct CompiledCountStar {
87    pub table_name: SmartString,
88    pub result_column_name: String,
89    pub cached_epoch: u64,
90}
91
92/// Cached execution state selected by statement dispatch.
93#[derive(Debug, Clone, Default)]
94pub enum CompiledExecution {
95    #[default]
96    Unknown,
97    NotOptimizable(u64),
98    PkLookup(CompiledPkLookup),
99    PkUpdate(CompiledPkUpdate),
100    PkDelete(CompiledPkDelete),
101    Insert(CompiledInsert),
102    CountDistinct(CompiledCountDistinct),
103    CountStar(CompiledCountStar),
104}