Augment non-nullability of columns, by observing either 1. Predicates that explicitly test for null values, and 2. Columns that if null would make a predicate be null.
(predicates: &[MirScalarExpr])
| 2173 | /// 1. Predicates that explicitly test for null values, and |
| 2174 | /// 2. Columns that if null would make a predicate be null. |
| 2175 | pub fn non_nullable_columns(predicates: &[MirScalarExpr]) -> BTreeSet<usize> { |
| 2176 | let mut nonnull_required_columns = BTreeSet::new(); |
| 2177 | for predicate in predicates { |
| 2178 | // Add any columns that being null would force the predicate to be null. |
| 2179 | // Should that happen, the row would be discarded. |
| 2180 | predicate.non_null_requirements(&mut nonnull_required_columns); |
| 2181 | |
| 2182 | /* |
| 2183 | Test for explicit checks that a column is non-null. |
| 2184 | |
| 2185 | This analysis is ad hoc, and will miss things: |
| 2186 | |
| 2187 | materialize=> create table a(x int, y int); |
| 2188 | CREATE TABLE |
| 2189 | materialize=> explain with(types) select x from a where (y=x and y is not null) or x is not null; |
| 2190 | Optimized Plan |
| 2191 | -------------------------------------------------------------------------------------------------------- |
| 2192 | Explained Query: + |
| 2193 | Project (#0) // { types: "(integer?)" } + |
| 2194 | Filter ((#0) IS NOT NULL OR ((#1) IS NOT NULL AND (#0 = #1))) // { types: "(integer?, integer?)" }+ |
| 2195 | Get materialize.public.a // { types: "(integer?, integer?)" } + |
| 2196 | + |
| 2197 | Source materialize.public.a + |
| 2198 | filter=(((#0) IS NOT NULL OR ((#1) IS NOT NULL AND (#0 = #1)))) + |
| 2199 | |
| 2200 | (1 row) |
| 2201 | */ |
| 2202 | |
| 2203 | if let MirScalarExpr::CallUnary { |
| 2204 | func: UnaryFunc::Not(scalar_func::Not), |
| 2205 | expr, |
| 2206 | } = predicate |
| 2207 | { |
| 2208 | if let MirScalarExpr::CallUnary { |
| 2209 | func: UnaryFunc::IsNull(scalar_func::IsNull), |
| 2210 | expr, |
| 2211 | } = &**expr |
| 2212 | { |
| 2213 | if let MirScalarExpr::Column(c, _name) = &**expr { |
| 2214 | nonnull_required_columns.insert(*c); |
| 2215 | } |
| 2216 | } |
| 2217 | } |
| 2218 | } |
| 2219 | |
| 2220 | nonnull_required_columns |
| 2221 | } |
| 2222 | |
| 2223 | impl CollectionPlan for MirRelationExpr { |
| 2224 | /// Collects the global collections that this MIR expression directly depends on, i.e., that it |
no test coverage detected