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
6939 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
/// Collapse slower joins with filters into faster joins.
38
const COLLAPSE_JOINS = 1 << 15;
39
/// Check if operations are order dependent and unset maintaining_order if
40
/// the order would not be observed.
41
const CHECK_ORDER_OBSERVE = 1 << 16;
42
}
43
}
44
45
impl OptFlags {
46
pub fn schema_only() -> Self {
47
Self::TYPE_COERCION | Self::TYPE_CHECK
48
}
49
50
pub fn eager(&self) -> bool {
51
self.contains(OptFlags::EAGER)
52
}
53
54
pub fn cluster_with_columns(&self) -> bool {
55
self.contains(OptFlags::CLUSTER_WITH_COLUMNS)
56
}
57
58
pub fn collapse_joins(&self) -> bool {
59
self.contains(OptFlags::COLLAPSE_JOINS)
60
}
61
62
pub fn predicate_pushdown(&self) -> bool {
63
self.contains(OptFlags::PREDICATE_PUSHDOWN)
64
}
65
66
pub fn projection_pushdown(&self) -> bool {
67
self.contains(OptFlags::PROJECTION_PUSHDOWN)
68
}
69
pub fn simplify_expr(&self) -> bool {
70
self.contains(OptFlags::SIMPLIFY_EXPR)
71
}
72
pub fn slice_pushdown(&self) -> bool {
73
self.contains(OptFlags::SLICE_PUSHDOWN)
74
}
75
pub fn new_streaming(&self) -> bool {
76
self.contains(OptFlags::NEW_STREAMING)
77
}
78
pub fn fast_projection(&self) -> bool {
79
self.contains(OptFlags::FAST_PROJECTION)
80
}
81
}
82
83
impl Default for OptFlags {
84
fn default() -> Self {
85
Self::from_bits_truncate(u32::MAX) & !Self::NEW_STREAMING & !Self::EAGER
86
}
87
}
88
89
/// AllowedOptimizations
90
pub type AllowedOptimizations = OptFlags;
91
92