Skip to content

Commit

Permalink
fix: field metaqueries take fast path if predicate is only on `_measu…
Browse files Browse the repository at this point in the history
…rement` (influxdata#21962)

* fix: field metaqueries take fast path if predicate is only on `_measurement`

* chore: update CHANGELOG

* test: add test for fields with measurement predicate
  • Loading branch information
williamhbaker authored Jul 29, 2021
1 parent 52ccb23 commit 8e80798
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ This release adds an embedded SQLite database for storing metadata required by t
1. [21925](https://github.com/influxdata/influxdb/pull/21925): Upgrade to golang-jwt 3.2.1.
1. [21946](https://github.com/influxdata/influxdb/pull/21946): Prevent silently dropped writes when there are overlapping shards.
1. [21950](https://github.com/influxdata/influxdb/pull/21950): Invalid requests to /api/v2 subroutes now return 404 instead of a list of links.
1. [21962](https://github.com/influxdata/influxdb/pull/21962): Flux metaqueries for `_field` take fast path if `_measurement` is the only predicate.

## v2.0.7 [2021-06-04]

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package influxdb_test


import "testing"

option now = () => 2030-01-01T00:00:00Z

inData = "
#datatype,string,long,dateTime:RFC3339,string,string,string,double
#group,false,false,false,true,true,true,false
#default,_result,,,,,,
,result,table,_time,_measurement,host,_field,_value
,,0,2018-05-22T19:53:26Z,system,host.local,load1,1.83
,,0,2018-05-22T19:53:36Z,system,host.local,load1,1.72
,,0,2018-05-22T19:53:46Z,system,host.local,load1,1.74
,,0,2018-05-22T19:53:56Z,system,host.local,load1,1.63
,,0,2018-05-22T19:54:06Z,system,host.local,load1,1.91
,,0,2018-05-22T19:54:16Z,system,host.local,load1,1.84

,,1,2018-05-22T19:53:26Z,sys,host.local,load3,1.98
,,1,2018-05-22T19:53:36Z,sys,host.local,load3,1.97
,,1,2018-05-22T19:53:46Z,sys,host.local,load3,1.97
,,1,2018-05-22T19:53:56Z,sys,host.local,load3,1.96
,,1,2018-05-22T19:54:06Z,sys,host.local,load3,1.98
,,1,2018-05-22T19:54:16Z,sys,host.local,load3,1.97

,,2,2018-05-22T19:53:26Z,system,host.local,load5,1.95
,,2,2018-05-22T19:53:36Z,system,host.local,load5,1.92
,,2,2018-05-22T19:53:46Z,system,host.local,load5,1.92
,,2,2018-05-22T19:53:56Z,system,host.local,load5,1.89
,,2,2018-05-22T19:54:06Z,system,host.local,load5,1.94
,,2,2018-05-22T19:54:16Z,system,host.local,load5,1.93

,,3,2018-05-22T19:53:26Z,swap,host.global,used_percent,82.98
,,3,2018-05-22T19:53:36Z,swap,host.global,used_percent,82.59
,,3,2018-05-22T19:53:46Z,swap,host.global,used_percent,82.59
,,3,2018-05-22T19:53:56Z,swap,host.global,used_percent,82.59
,,3,2018-05-22T19:54:06Z,swap,host.global,used_percent,82.59
,,3,2018-05-22T19:54:16Z,swap,host.global,used_percent,82.64

#datatype,string,long,dateTime:RFC3339,string,string,string,long
#group,false,false,false,true,true,true,false
#default,_result,,,,,,
,result,table,_time,_measurement,host,_field,_value
,,4,2018-05-22T19:53:26Z,sys,host.global,load7,183
,,4,2018-05-22T19:53:36Z,sys,host.global,load7,172
,,4,2018-05-22T19:53:46Z,sys,host.global,load7,174
,,4,2018-05-22T19:53:56Z,sys,host.global,load7,163
,,4,2018-05-22T19:54:06Z,sys,host.global,load7,191
,,4,2018-05-22T19:54:16Z,sys,host.global,load7,184

,,5,2018-05-22T19:53:26Z,sys,host.local,load8,198
,,5,2018-05-22T19:53:36Z,sys,host.local,load8,197
,,5,2018-05-22T19:53:46Z,sys,host.local,load8,197
,,5,2018-05-22T19:53:56Z,sys,host.local,load8,196
,,5,2018-05-22T19:54:06Z,sys,host.local,load8,198
,,5,2018-05-22T19:54:16Z,sys,host.local,load8,197

,,6,2018-05-22T19:53:26Z,sys,host.global,load9,195
,,6,2018-05-22T19:53:36Z,sys,host.global,load9,192
,,6,2018-05-22T19:53:46Z,sys,host.global,load9,192
,,6,2018-05-22T19:53:56Z,sys,host.global,load9,189
,,6,2018-05-22T19:54:06Z,sys,host.global,load9,194
,,6,2018-05-22T19:54:16Z,sys,host.global,load9,193

,,7,2018-05-22T19:53:26Z,swp,host.global,used_percent,8298
,,7,2018-05-22T19:53:36Z,swp,host.global,used_percent,8259
,,7,2018-05-22T19:53:46Z,swp,host.global,used_percent,8259
,,7,2018-05-22T19:53:56Z,swp,host.global,used_percent,8259
,,7,2018-05-22T19:54:06Z,swp,host.global,used_percent,8259
,,7,2018-05-22T19:54:16Z,swp,host.global,used_percent,8264
"

testcase show_fields_with_meas_pred {
result = testing.loadStorage(csv: inData)
|> range(start: 2018-01-01T00:00:00Z, stop: 2019-01-01T00:00:00Z)
|> filter(fn: (r) => r._measurement == "sys")
|> keep(columns: ["_field"])
|> group()
|> distinct(column: "_field")
|> sort()

out_fields = "
#datatype,string,long,string
#group,false,false,false
#default,0,,
,result,table,_value
,,0,load3
,,0,load7
,,0,load8
,,0,load9
"

testing.diff(got: result, want: testing.loadMem(csv: out_fields)) |> yield()
}
5 changes: 4 additions & 1 deletion v1/services/storage/predicate_influxql.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@ func (v *hasAnyTagKeys) Visit(node influxql.Node) influxql.Visitor {
}

if n, ok := node.(*influxql.VarRef); ok {
if n.Val != fieldKey && n.Val != measurementKey && n.Val != "$" {
// The influxql expression will have had references to "_measurement"
// remapped to "_name" at this point by reads.NodeToExpr, so be sure to
// check for the appropriate value here using the measurementRemap map.
if n.Val != fieldKey && n.Val != measurementRemap[measurementKey] && n.Val != "$" {
v.found = true
return nil
}
Expand Down

0 comments on commit 8e80798

Please sign in to comment.