Path: blob/main/crates/polars-plan/src/frame/opt_state.rs
8479 views
use bitflags::bitflags;12bitflags! {3#[derive(Copy, Clone, Debug)]4/// Allowed optimizations.5pub struct OptFlags: u32 {6/// Only read columns that are used later in the query.7const PROJECTION_PUSHDOWN = 1;8/// Apply predicates/filters as early as possible.9const PREDICATE_PUSHDOWN = 1 << 2;10/// Cluster sequential `with_columns` calls to independent calls.11const CLUSTER_WITH_COLUMNS = 1 << 3;12/// Run many type coercion optimization rules until fixed point.13const TYPE_COERCION = 1 << 4;14/// Run many expression optimization rules until fixed point.15const SIMPLIFY_EXPR = 1 << 5;16/// Do type checking of the IR.17const TYPE_CHECK = 1 << 6;18/// Pushdown slices/limits.19const SLICE_PUSHDOWN = 1 << 7;20/// Run common-subplan-elimination. This elides duplicate plans and caches their21/// outputs.22const COMM_SUBPLAN_ELIM = 1 << 8;23/// Run common-subexpression-elimination. This elides duplicate expressions and caches their24/// outputs.25const COMM_SUBEXPR_ELIM = 1 << 9;2627// const STREAMING = 1 << 10; // Legacy flag for removed old streaming engine.2829const NEW_STREAMING = 1 << 11;30/// Run every node eagerly. This turns off multi-node optimizations.31const EAGER = 1 << 12;32/// Try to estimate the number of rows so that joins can determine which side to keep in memory.33const ROW_ESTIMATE = 1 << 13;34/// Replace simple projections with a faster inlined projection that skips the expression engine.35const FAST_PROJECTION = 1 << 14;36/// Check if operations are order dependent and unset maintaining_order if37/// the order would not be observed.38const CHECK_ORDER_OBSERVE = 1 << 15;39}40}4142impl OptFlags {43pub fn schema_only() -> Self {44Self::TYPE_COERCION | Self::TYPE_CHECK45}4647pub fn eager(&self) -> bool {48self.contains(OptFlags::EAGER)49}5051pub fn cluster_with_columns(&self) -> bool {52self.contains(OptFlags::CLUSTER_WITH_COLUMNS)53}5455pub fn predicate_pushdown(&self) -> bool {56self.contains(OptFlags::PREDICATE_PUSHDOWN)57}5859pub fn projection_pushdown(&self) -> bool {60self.contains(OptFlags::PROJECTION_PUSHDOWN)61}62pub fn simplify_expr(&self) -> bool {63self.contains(OptFlags::SIMPLIFY_EXPR)64}65pub fn slice_pushdown(&self) -> bool {66self.contains(OptFlags::SLICE_PUSHDOWN)67}68pub fn new_streaming(&self) -> bool {69self.contains(OptFlags::NEW_STREAMING)70}71pub fn fast_projection(&self) -> bool {72self.contains(OptFlags::FAST_PROJECTION)73}74}7576impl Default for OptFlags {77fn default() -> Self {78Self::from_bits_truncate(u32::MAX) & !Self::NEW_STREAMING & !Self::EAGER79}80}8182/// AllowedOptimizations83pub type AllowedOptimizations = OptFlags;848586