refactor: allow newIndexSeriesCursor() to accept an influxql.Expr (#19833)

* refactor: allow newIndexSeriesCursor() to accept an influxql.Expr

In order to let TagKeys and TagValues get the right answer,
sometimes they will need to examine their predicate and
see if using the index is possible, or if a block scan is needed.
For those cases we want to examine the predicate before creating
the index series cursor. This change allows us to create an
index series cursor with an already-deserialized influxql.Expr.
pull/19834/head
Christopher M. Wolff 2020-10-27 09:31:46 -07:00 committed by GitHub
parent 5c63c2163d
commit 790165b05a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 4 deletions

View File

@ -38,6 +38,18 @@ type indexSeriesCursor struct {
}
func newIndexSeriesCursor(ctx context.Context, predicate *datatypes.Predicate, shards []*tsdb.Shard) (*indexSeriesCursor, error) {
var expr influxql.Expr
if root := predicate.GetRoot(); root != nil {
var err error
if expr, err = reads.NodeToExpr(root, measurementRemap); err != nil {
return nil, err
}
}
return newIndexSeriesCursorInfluxQLPred(ctx, expr, shards)
}
func newIndexSeriesCursorInfluxQLPred(ctx context.Context, predicate influxql.Expr, shards []*tsdb.Shard) (*indexSeriesCursor, error) {
queries, err := tsdb.CreateCursorIterators(ctx, shards)
if err != nil {
return nil, err
@ -61,10 +73,8 @@ func newIndexSeriesCursor(ctx context.Context, predicate *datatypes.Predicate, s
}
p := &indexSeriesCursor{row: reads.SeriesRow{Query: queries}}
if root := predicate.GetRoot(); root != nil {
if p.cond, err = reads.NodeToExpr(root, measurementRemap); err != nil {
return nil, err
}
if predicate != nil {
p.cond = predicate
p.hasFieldExpr, p.hasValueExpr = HasFieldKeyOrValue(p.cond)
if !(p.hasFieldExpr || p.hasValueExpr) {