SpanExpression is an implementation of Expression. TODO(sumeer): after integration and experimentation with optimizer costing, decide if we can eliminate the generality of the Expression interface. If we don't need that generality, we can merge SpanExpression and SpanExpressionProto.
| 302 | // interface. If we don't need that generality, we can merge SpanExpression |
| 303 | // and SpanExpressionProto. |
| 304 | type SpanExpression struct { |
| 305 | // Tight mirrors the definition of IsTight(). |
| 306 | Tight bool |
| 307 | |
| 308 | // Unique is true if the spans in FactoredUnionSpans are guaranteed not to |
| 309 | // produce duplicate primary keys. Otherwise, Unique is false. Unique may |
| 310 | // be true for certain JSON or Array SpanExpressions, and it holds when |
| 311 | // unique SpanExpressions are combined with And. It does not hold when |
| 312 | // these non-empty SpanExpressions are combined with Or. |
| 313 | // |
| 314 | // Once a SpanExpression is built, this field is relevant if the root |
| 315 | // SpanExpression has no children (i.e., Operator is None). In this case, |
| 316 | // Unique is used to determine whether an invertedFilter is needed on top |
| 317 | // of the inverted index scan to deduplicate keys (an invertedFilter is |
| 318 | // always necessary if Operator is not None). |
| 319 | Unique bool |
| 320 | |
| 321 | // SpansToRead are the spans to read from the inverted index |
| 322 | // to evaluate this SpanExpression. These are non-overlapping |
| 323 | // and sorted. If left or right contains a non-SpanExpression, |
| 324 | // it is not included in the spanning union. |
| 325 | // To illustrate, consider a made up example: |
| 326 | // [2, 10) \intersection [6, 14) |
| 327 | // is factored into: |
| 328 | // [6, 10) \union ([2, 6) \intersection [10, 14)) |
| 329 | // The root expression has a spanning union of [2, 14). |
| 330 | SpansToRead Spans |
| 331 | |
| 332 | // FactoredUnionSpans are the spans to be unioned. These are |
| 333 | // non-overlapping and sorted. As mentioned earlier, factoring |
| 334 | // can result in faster evaluation and can be useful for |
| 335 | // optimizer cost estimation. |
| 336 | // |
| 337 | // Using the same example, the FactoredUnionSpans will be |
| 338 | // [6, 10). Now let's extend the above example and say that |
| 339 | // it was just a sub-expression in a bigger expression, and |
| 340 | // the full expression involved an intersection of that |
| 341 | // sub-expression and [5, 8). After factoring, we would get |
| 342 | // [6, 8) \union ([5, 6) \intersection ([8, 10) \union ([2, 6) \intersection [10, 14)))) |
| 343 | // The top-level expression has FactoredUnionSpans [6, 8), and the left and |
| 344 | // right children have factoredUnionSpans [5, 6) and [8, 10) respectively. |
| 345 | // The SpansToRead of this top-level expression is still [2, 14) since the |
| 346 | // intersection with [5, 8) did not add anything to the spans to read. Also |
| 347 | // note that, despite factoring, there are overlapping spans in this |
| 348 | // expression, specifically [2, 6) and [5, 6). |
| 349 | FactoredUnionSpans Spans |
| 350 | |
| 351 | // Operator is the set operation to apply to Left and Right. |
| 352 | // When this is union or intersection, both Left and Right are non-nil, |
| 353 | // else both are nil. |
| 354 | Operator SetOperator |
| 355 | Left Expression |
| 356 | Right Expression |
| 357 | } |
| 358 | |
| 359 | var _ Expression = (*SpanExpression)(nil) |
| 360 |
nothing calls this directly
no outgoing calls
no test coverage detected