Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-plan/src/frame/opt_state.rs
8479 views
1
use bitflags::bitflags;
2
3
bitflags! {
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
28
// const STREAMING = 1 << 10; // Legacy flag for removed old streaming engine.
29
30
const NEW_STREAMING = 1 << 11;
31
/// Run every node eagerly. This turns off multi-node optimizations.
32
const EAGER = 1 << 12;
33
/// Try to estimate the number of rows so that joins can determine which side to keep in memory.
34
const ROW_ESTIMATE = 1 << 13;
35
/// Replace simple projections with a faster inlined projection that skips the expression engine.
36
const FAST_PROJECTION = 1 << 14;
37
/// Check if operations are order dependent and unset maintaining_order if
38
/// the order would not be observed.
39
const CHECK_ORDER_OBSERVE = 1 << 15;
40
}
41
}
42
43
impl OptFlags {
44
pub fn schema_only() -> Self {
45
Self::TYPE_COERCION | Self::TYPE_CHECK
46
}
47
48
pub fn eager(&self) -> bool {
49
self.contains(OptFlags::EAGER)
50
}
51
52
pub fn cluster_with_columns(&self) -> bool {
53
self.contains(OptFlags::CLUSTER_WITH_COLUMNS)
54
}
55
56
pub fn predicate_pushdown(&self) -> bool {
57
self.contains(OptFlags::PREDICATE_PUSHDOWN)
58
}
59
60
pub fn projection_pushdown(&self) -> bool {
61
self.contains(OptFlags::PROJECTION_PUSHDOWN)
62
}
63
pub fn simplify_expr(&self) -> bool {
64
self.contains(OptFlags::SIMPLIFY_EXPR)
65
}
66
pub fn slice_pushdown(&self) -> bool {
67
self.contains(OptFlags::SLICE_PUSHDOWN)
68
}
69
pub fn new_streaming(&self) -> bool {
70
self.contains(OptFlags::NEW_STREAMING)
71
}
72
pub fn fast_projection(&self) -> bool {
73
self.contains(OptFlags::FAST_PROJECTION)
74
}
75
}
76
77
impl Default for OptFlags {
78
fn default() -> Self {
79
Self::from_bits_truncate(u32::MAX) & !Self::NEW_STREAMING & !Self::EAGER
80
}
81
}
82
83
/// AllowedOptimizations
84
pub type AllowedOptimizations = OptFlags;
85
86