polars_plan/frame/
opt_state.rs

1use bitflags::bitflags;
2
3bitflags! {
4#[derive(Copy, Clone, Debug)]
5    /// Allowed optimizations.
6    pub struct OptFlags: u32 {
7        /// Only read columns that are used later in the query.
8        const PROJECTION_PUSHDOWN = 1;
9        /// Apply predicates/filters as early as possible.
10        const PREDICATE_PUSHDOWN = 1 << 2;
11        /// Cluster sequential `with_columns` calls to independent calls.
12        const CLUSTER_WITH_COLUMNS = 1 << 3;
13        /// Run many type coercion optimization rules until fixed point.
14        const TYPE_COERCION = 1 << 4;
15        /// Run many expression optimization rules until fixed point.
16        const SIMPLIFY_EXPR = 1 << 5;
17        /// Do type checking of the IR.
18        const TYPE_CHECK = 1 << 6;
19        /// Pushdown slices/limits.
20        const SLICE_PUSHDOWN = 1 << 7;
21        /// Run common-subplan-elimination. This elides duplicate plans and caches their
22        /// outputs.
23        const COMM_SUBPLAN_ELIM = 1 << 8;
24        /// Run common-subexpression-elimination. This elides duplicate expressions and caches their
25        /// outputs.
26        const COMM_SUBEXPR_ELIM = 1 << 9;
27        /// Run nodes that are capably of doing so on the streaming engine.
28        const STREAMING = 1 << 10;
29        const NEW_STREAMING = 1 << 11;
30        /// Run every node eagerly. This turns off multi-node optimizations.
31        const EAGER = 1 << 12;
32        /// Try to estimate the number of rows so that joins can determine which side to keep in memory.
33        const ROW_ESTIMATE = 1 << 13;
34        /// Replace simple projections with a faster inlined projection that skips the expression engine.
35        const FAST_PROJECTION = 1 << 14;
36        /// Collapse slower joins with filters into faster joins.
37        const COLLAPSE_JOINS = 1 << 15;
38        /// Check if operations are order dependent and unset maintaining_order if
39        /// the order would not be observed.
40        const CHECK_ORDER_OBSERVE = 1 << 16;
41    }
42}
43
44impl OptFlags {
45    pub fn schema_only() -> Self {
46        Self::TYPE_COERCION | Self::TYPE_CHECK
47    }
48
49    pub fn eager(&self) -> bool {
50        self.contains(OptFlags::EAGER)
51    }
52
53    pub fn cluster_with_columns(&self) -> bool {
54        self.contains(OptFlags::CLUSTER_WITH_COLUMNS)
55    }
56
57    pub fn collapse_joins(&self) -> bool {
58        self.contains(OptFlags::COLLAPSE_JOINS)
59    }
60
61    pub fn predicate_pushdown(&self) -> bool {
62        self.contains(OptFlags::PREDICATE_PUSHDOWN)
63    }
64
65    pub fn projection_pushdown(&self) -> bool {
66        self.contains(OptFlags::PROJECTION_PUSHDOWN)
67    }
68    pub fn simplify_expr(&self) -> bool {
69        self.contains(OptFlags::SIMPLIFY_EXPR)
70    }
71    pub fn slice_pushdown(&self) -> bool {
72        self.contains(OptFlags::SLICE_PUSHDOWN)
73    }
74    pub fn streaming(&self) -> bool {
75        self.contains(OptFlags::STREAMING)
76    }
77    pub fn new_streaming(&self) -> bool {
78        self.contains(OptFlags::NEW_STREAMING)
79    }
80    pub fn fast_projection(&self) -> bool {
81        self.contains(OptFlags::FAST_PROJECTION)
82    }
83}
84
85impl Default for OptFlags {
86    fn default() -> Self {
87        Self::from_bits_truncate(u32::MAX) & !Self::NEW_STREAMING & !Self::STREAMING & !Self::EAGER
88    }
89}
90
91/// AllowedOptimizations
92pub type AllowedOptimizations = OptFlags;