Skip to main content

linkrs_query/optimizer/partitioning/
config.rs

1use crate::planning::plan::PartitionSpec;
2
3/// Static configuration for partition selection. The default is disabled so
4/// introducing the optimizer cannot change query results without an explicit
5/// self-proven layout source.
6#[derive(Debug, Clone, PartialEq, Eq)]
7pub struct PartitioningConfig {
8    pub enabled: bool,
9    pub min_rows_per_partition: u64,
10    pub max_partitions: usize,
11    /// Fallback vertex ID range used when the storage cannot self-prove a
12    /// domain. Ranges use `i64` to match the real vertex ID type and avoid
13    /// silent truncation of values >= 2^32.
14    pub vertex_id_range: Option<std::ops::Range<i64>>,
15    /// Maximum worker threads for intra-query parallelism.
16    /// 1 means fully serial.
17    pub max_workers: usize,
18    /// Maximum queued chunks per partition worker for backpressure.
19    pub max_buffered_chunks: usize,
20    /// Parallel fixed startup overhead in row-equivalents (fragment startup,
21    /// exchange coordination). All-zero cost params disable the economic
22    /// gate and leave the row-count threshold as the only gate.
23    pub fixed_overhead_rows: u64,
24    /// Per-partition fixed overhead in row-equivalents.
25    pub per_partition_rows: u64,
26    /// Exchange cost per output row in row-equivalents, per mille
27    /// (50 = 0.05 row-equivalents per row crossing the gather).
28    pub exchange_row_per_mille: u32,
29}
30
31impl Default for PartitioningConfig {
32    fn default() -> Self {
33        Self {
34            enabled: false,
35            min_rows_per_partition: 100_000,
36            max_partitions: 1,
37            vertex_id_range: None,
38            max_workers: 1,
39            max_buffered_chunks: 10,
40            fixed_overhead_rows: 0,
41            per_partition_rows: 0,
42            exchange_row_per_mille: 0,
43        }
44    }
45}
46
47#[derive(Debug, Clone, PartialEq, Eq)]
48pub struct PartitioningDecision {
49    pub partition_spec: Option<PartitionSpec>,
50    pub reason: String,
51}
52
53/// Storage-provided layout information read at optimize time.
54///
55/// The planner no longer trusts a caller-supplied vertex-id range blindly:
56/// `vertex_id_range` is the storage's **self-proven** domain (see
57/// `StorageReader::vertex_id_domain`), and `layout_version` is the storage's
58/// monotonic physical layout version (see `StorageReader::layout_version`).
59/// When the storage cannot prove a domain, the configured range is used as a
60/// fallback; when neither exists, partitioning falls back (safe default).
61#[derive(Debug, Clone, Default, PartialEq, Eq)]
62pub struct PartitioningLayoutInfo {
63    /// Monotonic storage layout version (0 = not provided).
64    pub layout_version: u64,
65    /// Storage self-proven vertex-id domain covering the space.
66    pub vertex_id_range: Option<std::ops::Range<i64>>,
67}