Path: blob/main/crates/polars-plan/src/frame/opt_state.rs
6939 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/// Collapse slower joins with filters into faster joins.37const COLLAPSE_JOINS = 1 << 15;38/// Check if operations are order dependent and unset maintaining_order if39/// the order would not be observed.40const CHECK_ORDER_OBSERVE = 1 << 16;41}42}4344impl OptFlags {45pub fn schema_only() -> Self {46Self::TYPE_COERCION | Self::TYPE_CHECK47}4849pub fn eager(&self) -> bool {50self.contains(OptFlags::EAGER)51}5253pub fn cluster_with_columns(&self) -> bool {54self.contains(OptFlags::CLUSTER_WITH_COLUMNS)55}5657pub fn collapse_joins(&self) -> bool {58self.contains(OptFlags::COLLAPSE_JOINS)59}6061pub fn predicate_pushdown(&self) -> bool {62self.contains(OptFlags::PREDICATE_PUSHDOWN)63}6465pub fn projection_pushdown(&self) -> bool {66self.contains(OptFlags::PROJECTION_PUSHDOWN)67}68pub fn simplify_expr(&self) -> bool {69self.contains(OptFlags::SIMPLIFY_EXPR)70}71pub fn slice_pushdown(&self) -> bool {72self.contains(OptFlags::SLICE_PUSHDOWN)73}74pub fn new_streaming(&self) -> bool {75self.contains(OptFlags::NEW_STREAMING)76}77pub fn fast_projection(&self) -> bool {78self.contains(OptFlags::FAST_PROJECTION)79}80}8182impl Default for OptFlags {83fn default() -> Self {84Self::from_bits_truncate(u32::MAX) & !Self::NEW_STREAMING & !Self::EAGER85}86}8788/// AllowedOptimizations89pub type AllowedOptimizations = OptFlags;909192