MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / action

Method action

src/transform/src/fold_constants.rs:73–423  ·  view source on GitHub ↗

Replace operators on constants collections with constant collections. This transform will cease optimization if it encounters constant collections that are larger than `self.limit`, if that is set. It is not guaranteed that a constant input within the limit will be reduced to a `Constant` variant.

(
        &self,
        relation: &mut MirRelationExpr,
        relation_type: &mut ReprRelationType,
    )

Source from the content-addressed store, hash-verified

71 /// that are larger than `self.limit`, if that is set. It is not guaranteed that
72 /// a constant input within the limit will be reduced to a `Constant` variant.
73 pub fn action(
74 &self,
75 relation: &mut MirRelationExpr,
76 relation_type: &mut ReprRelationType,
77 ) -> Result<(), TransformError> {
78 match relation {
79 MirRelationExpr::Constant { .. } => { /* handled after match */ }
80 MirRelationExpr::Get { .. } => {}
81 MirRelationExpr::Let { .. } | MirRelationExpr::LetRec { .. } => {
82 // Constant propagation through bindings is currently handled by in NormalizeLets.
83 // Maybe we should move it / replicate it here (see database-issues#5346 for context)?
84 }
85 MirRelationExpr::Reduce {
86 input,
87 group_key,
88 aggregates,
89 monotonic: _,
90 expected_group_size: _,
91 } => {
92 // Guard against evaluating an expression that may contain
93 // unmaterializable functions.
94 if group_key.iter().any(|e| e.contains_unmaterializable())
95 || aggregates
96 .iter()
97 .any(|a| a.expr.contains_unmaterializable())
98 {
99 return Ok(());
100 }
101
102 if let Some((rows, ..)) = (**input).as_const() {
103 let new_rows = match rows {
104 Ok(rows) => {
105 if let Some(rows) =
106 Self::fold_reduce_constant(group_key, aggregates, rows, self.limit)
107 {
108 rows
109 } else {
110 return Ok(());
111 }
112 }
113 Err(e) => Err(e.clone()),
114 };
115 *relation = MirRelationExpr::Constant {
116 rows: new_rows,
117 typ: relation_type.clone(),
118 };
119 }
120 }
121 MirRelationExpr::TopK {
122 input,
123 group_key,
124 order_key,
125 limit,
126 offset,
127 ..
128 } => {
129 // Only fold constants when:
130 //

Callers 1

Calls 15

anyMethod · 0.80
as_literal_int64Method · 0.80
as_const_mutMethod · 0.80
take_dangerousMethod · 0.80
as_literal_strMethod · 0.80
take_safelyMethod · 0.80
sort_by_keyMethod · 0.80
packerMethod · 0.80
as_const_errMethod · 0.80
allMethod · 0.80
extend_by_rowMethod · 0.80
borrow_withMethod · 0.80

Tested by

no test coverage detected