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,
)
| 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 | // |
no test coverage detected