IsNoop detects trivial noop queries like {false} which never return results and can be used to exit early.
()
| 117 | // IsNoop detects trivial noop queries like {false} which never return |
| 118 | // results and can be used to exit early. |
| 119 | func (r *RootExpr) IsNoop() bool { |
| 120 | isNoopFilter := func(x any) bool { |
| 121 | f, ok := x.(*SpansetFilter) |
| 122 | if !ok { |
| 123 | return false |
| 124 | } |
| 125 | |
| 126 | if f.Expression.referencesSpan() { |
| 127 | return false |
| 128 | } |
| 129 | |
| 130 | // Else check for static evaluation to false |
| 131 | v, _ := f.Expression.execute(nil) |
| 132 | return v.Equals(&StaticFalse) |
| 133 | } |
| 134 | |
| 135 | // Any spanset filter that references the span or something other |
| 136 | // than static false means the expression isn't noop. |
| 137 | // This checks one layer deep which covers most expressions. |
| 138 | for _, e := range r.Pipeline.Elements { |
| 139 | switch x := e.(type) { |
| 140 | case SpansetOperation: |
| 141 | if !isNoopFilter(x.LHS) { |
| 142 | return false |
| 143 | } |
| 144 | if !isNoopFilter(x.RHS) { |
| 145 | return false |
| 146 | } |
| 147 | case *SpansetFilter: |
| 148 | if !isNoopFilter(x) { |
| 149 | return false |
| 150 | } |
| 151 | default: |
| 152 | // Lots of other expressions here which aren't checked |
| 153 | // for noops yet. |
| 154 | return false |
| 155 | } |
| 156 | } |
| 157 | return true |
| 158 | } |
| 159 | |
| 160 | // ********************** |
| 161 | // Pipeline |