From 1dbe0662d8b3a12312242b3dfa888d724a8d88ba Mon Sep 17 00:00:00 2001 From: Ben Johnson Date: Thu, 24 Aug 2017 08:45:46 -0600 Subject: [PATCH] Use system cursors for measurement, series, and tag key meta queries. --- CHANGELOG.md | 1 + coordinator/statement_executor.go | 1 + influxql/ast.go | 6 ++ influxql/statement_rewriter.go | 78 +++++++++++--------- influxql/statement_rewriter_test.go | 44 ++++++------ query/emitter.go | 7 ++ query/internal/internal.pb.go | 107 +++++++++++++++------------- query/internal/internal.proto | 1 + query/iterator.go | 6 ++ query/iterator_test.go | 1 + tests/server_test.go | 38 +--------- tsdb/engine/tsm1/engine.go | 7 +- 12 files changed, 155 insertions(+), 142 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c9f0702745..44239051f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ - [#8662](https://github.com/influxdata/influxdb/pull/8662): Improve test coverage across both indexes. - [#8611](https://github.com/influxdata/influxdb/issues/8611): Respect X-Request-Id/Request-Id headers. - [#8572](https://github.com/influxdata/influxdb/issues/8668): InfluxDB now uses MIT licensed version of BurntSushi/toml. +- [#8752](https://github.com/influxdata/influxdb/pull/8752): Use system cursors for measurement, series, and tag key meta queries. ### Bugfixes diff --git a/coordinator/statement_executor.go b/coordinator/statement_executor.go index f369fb5762..0afe9fc843 100644 --- a/coordinator/statement_executor.go +++ b/coordinator/statement_executor.go @@ -449,6 +449,7 @@ func (e *StatementExecutor) executeSelectStatement(stmt *influxql.SelectStatemen em.Location = stmt.Location } em.OmitTime = stmt.OmitTime + em.EmitName = stmt.EmitName defer em.Close() // Emit rows to the results channel. diff --git a/influxql/ast.go b/influxql/ast.go index 9eb9a5871f..b528ef3d59 100644 --- a/influxql/ast.go +++ b/influxql/ast.go @@ -1004,6 +1004,12 @@ type SelectStatement struct { // Removes the "time" column from the output. OmitTime bool + // Removes measurement name from resulting query. Useful for meta queries. + StripName bool + + // Overrides the output measurement name. + EmitName string + // Removes duplicate rows from raw queries. Dedupe bool } diff --git a/influxql/statement_rewriter.go b/influxql/statement_rewriter.go index 55e343458b..564a60e2a6 100644 --- a/influxql/statement_rewriter.go +++ b/influxql/statement_rewriter.go @@ -88,21 +88,25 @@ func rewriteShowFieldKeyCardinalityStatement(stmt *ShowFieldKeyCardinalityStatem } func rewriteShowMeasurementsStatement(stmt *ShowMeasurementsStatement) (Statement, error) { - // Check for time in WHERE clause (not supported). - if HasTimeExpr(stmt.Condition) { - return nil, errors.New("SHOW MEASUREMENTS doesn't support time in WHERE clause") + var sources Sources + if stmt.Source != nil { + sources = Sources{stmt.Source} } - condition := stmt.Condition - if stmt.Source != nil { - condition = rewriteSourcesCondition(Sources([]Source{stmt.Source}), stmt.Condition) - } - return &ShowMeasurementsStatement{ - Database: stmt.Database, - Condition: condition, - Limit: stmt.Limit, + return &SelectStatement{ + Fields: []*Field{ + {Expr: &VarRef{Val: "_name"}, Alias: "name"}, + }, + Sources: rewriteSources2(sources, stmt.Database), + Condition: stmt.Condition, Offset: stmt.Offset, + Limit: stmt.Limit, SortFields: stmt.SortFields, + OmitTime: true, + StripName: true, + EmitName: "measurements", + Dedupe: true, + IsRawQuery: true, }, nil } @@ -140,25 +144,22 @@ func rewriteShowMeasurementCardinalityStatement(stmt *ShowMeasurementCardinality Offset: stmt.Offset, Limit: stmt.Limit, OmitTime: true, + StripName: true, }, nil } func rewriteShowSeriesStatement(stmt *ShowSeriesStatement) (Statement, error) { - // Check for time in WHERE clause (not supported). - if HasTimeExpr(stmt.Condition) { - return nil, errors.New("SHOW SERIES doesn't support time in WHERE clause") - } - return &SelectStatement{ Fields: []*Field{ - {Expr: &VarRef{Val: "key"}}, + {Expr: &VarRef{Val: "_seriesKey"}, Alias: "key"}, }, - Sources: rewriteSources(stmt.Sources, "_series", stmt.Database), - Condition: rewriteSourcesCondition(stmt.Sources, stmt.Condition), + Sources: rewriteSources2(stmt.Sources, stmt.Database), + Condition: stmt.Condition, Offset: stmt.Offset, Limit: stmt.Limit, SortFields: stmt.SortFields, OmitTime: true, + StripName: true, Dedupe: true, IsRawQuery: true, }, nil @@ -248,11 +249,6 @@ func rewriteShowTagValuesStatement(stmt *ShowTagValuesStatement) (Statement, err } func rewriteShowTagValuesCardinalityStatement(stmt *ShowTagValuesCardinalityStatement) (Statement, error) { - // Check for time in WHERE clause (not supported). - if HasTimeExpr(stmt.Condition) { - return nil, errors.New("SHOW TAG VALUES CARDINALITY doesn't support time in WHERE clause") - } - // Use all measurements, if zero. if len(stmt.Sources) == 0 { stmt.Sources = Sources{ @@ -324,17 +320,18 @@ func rewriteShowTagValuesCardinalityStatement(stmt *ShowTagValuesCardinalityStat } func rewriteShowTagKeysStatement(stmt *ShowTagKeysStatement) (Statement, error) { - // Check for time in WHERE clause (not supported). - if HasTimeExpr(stmt.Condition) { - return nil, errors.New("SHOW TAG KEYS doesn't support time in WHERE clause") - } - return &SelectStatement{ Fields: []*Field{ - {Expr: &VarRef{Val: "tagKey"}}, + { + Expr: &Call{ + Name: "distinct", + Args: []Expr{&VarRef{Val: "_tagKey"}}, + }, + Alias: "tagKey", + }, }, - Sources: rewriteSources(stmt.Sources, "_tagKeys", stmt.Database), - Condition: rewriteSourcesCondition(stmt.Sources, stmt.Condition), + Sources: rewriteSources2(stmt.Sources, stmt.Database), + Condition: stmt.Condition, Offset: stmt.Offset, Limit: stmt.Limit, SortFields: stmt.SortFields, @@ -457,3 +454,20 @@ func rewriteSourcesCondition(sources Sources, cond Expr) Expr { } return scond } + +func rewriteSources2(sources Sources, database string) Sources { + if len(sources) == 0 { + sources = Sources{&Measurement{Regex: &RegexLiteral{Val: matchAllRegex.Copy()}}} + } + for _, source := range sources { + switch source := source.(type) { + case *Measurement: + if source.Database == "" { + source.Database = database + } + } + } + return sources +} + +var matchAllRegex = regexp.MustCompile(`.+`) diff --git a/influxql/statement_rewriter_test.go b/influxql/statement_rewriter_test.go index c0554b3172..c4eb4b949b 100644 --- a/influxql/statement_rewriter_test.go +++ b/influxql/statement_rewriter_test.go @@ -53,91 +53,91 @@ func TestRewriteStatement(t *testing.T) { }, { stmt: `SHOW SERIES`, - s: `SELECT "key" FROM _series`, + s: `SELECT _seriesKey AS "key" FROM /.+/`, }, { stmt: `SHOW SERIES ON db0`, - s: `SELECT "key" FROM db0.._series`, + s: `SELECT _seriesKey AS "key" FROM db0../.+/`, }, { stmt: `SHOW SERIES FROM cpu`, - s: `SELECT "key" FROM _series WHERE _name = 'cpu'`, + s: `SELECT _seriesKey AS "key" FROM cpu`, }, { stmt: `SHOW SERIES ON db0 FROM cpu`, - s: `SELECT "key" FROM db0.._series WHERE _name = 'cpu'`, + s: `SELECT _seriesKey AS "key" FROM db0..cpu`, }, { stmt: `SHOW SERIES FROM mydb.myrp1.cpu`, - s: `SELECT "key" FROM mydb.myrp1._series WHERE _name = 'cpu'`, + s: `SELECT _seriesKey AS "key" FROM mydb.myrp1.cpu`, }, { stmt: `SHOW SERIES ON db0 FROM mydb.myrp1.cpu`, - s: `SELECT "key" FROM mydb.myrp1._series WHERE _name = 'cpu'`, + s: `SELECT _seriesKey AS "key" FROM mydb.myrp1.cpu`, }, { stmt: `SHOW SERIES FROM mydb.myrp1./c.*/`, - s: `SELECT "key" FROM mydb.myrp1._series WHERE _name =~ /c.*/`, + s: `SELECT _seriesKey AS "key" FROM mydb.myrp1./c.*/`, }, { stmt: `SHOW SERIES ON db0 FROM mydb.myrp1./c.*/`, - s: `SELECT "key" FROM mydb.myrp1._series WHERE _name =~ /c.*/`, + s: `SELECT _seriesKey AS "key" FROM mydb.myrp1./c.*/`, }, { stmt: `SHOW TAG KEYS`, - s: `SELECT tagKey FROM _tagKeys`, + s: `SELECT distinct(_tagKey) AS tagKey FROM /.+/`, }, { stmt: `SHOW TAG KEYS ON db0`, - s: `SELECT tagKey FROM db0.._tagKeys`, + s: `SELECT distinct(_tagKey) AS tagKey FROM db0../.+/`, }, { stmt: `SHOW TAG KEYS FROM cpu`, - s: `SELECT tagKey FROM _tagKeys WHERE _name = 'cpu'`, + s: `SELECT distinct(_tagKey) AS tagKey FROM cpu`, }, { stmt: `SHOW TAG KEYS ON db0 FROM cpu`, - s: `SELECT tagKey FROM db0.._tagKeys WHERE _name = 'cpu'`, + s: `SELECT distinct(_tagKey) AS tagKey FROM db0..cpu`, }, { stmt: `SHOW TAG KEYS FROM /c.*/`, - s: `SELECT tagKey FROM _tagKeys WHERE _name =~ /c.*/`, + s: `SELECT distinct(_tagKey) AS tagKey FROM /c.*/`, }, { stmt: `SHOW TAG KEYS ON db0 FROM /c.*/`, - s: `SELECT tagKey FROM db0.._tagKeys WHERE _name =~ /c.*/`, + s: `SELECT distinct(_tagKey) AS tagKey FROM db0../c.*/`, }, { stmt: `SHOW TAG KEYS FROM cpu WHERE region = 'uswest'`, - s: `SELECT tagKey FROM _tagKeys WHERE (_name = 'cpu') AND (region = 'uswest')`, + s: `SELECT distinct(_tagKey) AS tagKey FROM cpu WHERE region = 'uswest'`, }, { stmt: `SHOW TAG KEYS ON db0 FROM cpu WHERE region = 'uswest'`, - s: `SELECT tagKey FROM db0.._tagKeys WHERE (_name = 'cpu') AND (region = 'uswest')`, + s: `SELECT distinct(_tagKey) AS tagKey FROM db0..cpu WHERE region = 'uswest'`, }, { stmt: `SHOW TAG KEYS FROM mydb.myrp1.cpu`, - s: `SELECT tagKey FROM mydb.myrp1._tagKeys WHERE _name = 'cpu'`, + s: `SELECT distinct(_tagKey) AS tagKey FROM mydb.myrp1.cpu`, }, { stmt: `SHOW TAG KEYS ON db0 FROM mydb.myrp1.cpu`, - s: `SELECT tagKey FROM mydb.myrp1._tagKeys WHERE _name = 'cpu'`, + s: `SELECT distinct(_tagKey) AS tagKey FROM mydb.myrp1.cpu`, }, { stmt: `SHOW TAG KEYS FROM mydb.myrp1./c.*/`, - s: `SELECT tagKey FROM mydb.myrp1._tagKeys WHERE _name =~ /c.*/`, + s: `SELECT distinct(_tagKey) AS tagKey FROM mydb.myrp1./c.*/`, }, { stmt: `SHOW TAG KEYS ON db0 FROM mydb.myrp1./c.*/`, - s: `SELECT tagKey FROM mydb.myrp1._tagKeys WHERE _name =~ /c.*/`, + s: `SELECT distinct(_tagKey) AS tagKey FROM mydb.myrp1./c.*/`, }, { stmt: `SHOW TAG KEYS FROM mydb.myrp1.cpu WHERE region = 'uswest'`, - s: `SELECT tagKey FROM mydb.myrp1._tagKeys WHERE (_name = 'cpu') AND (region = 'uswest')`, + s: `SELECT distinct(_tagKey) AS tagKey FROM mydb.myrp1.cpu WHERE region = 'uswest'`, }, { stmt: `SHOW TAG KEYS ON db0 FROM mydb.myrp1.cpu WHERE region = 'uswest'`, - s: `SELECT tagKey FROM mydb.myrp1._tagKeys WHERE (_name = 'cpu') AND (region = 'uswest')`, + s: `SELECT distinct(_tagKey) AS tagKey FROM mydb.myrp1.cpu WHERE region = 'uswest'`, }, { stmt: `SELECT value FROM cpu`, diff --git a/query/emitter.go b/query/emitter.go index 09b6cab908..6909172bca 100644 --- a/query/emitter.go +++ b/query/emitter.go @@ -20,6 +20,9 @@ type Emitter struct { // The columns to attach to each row. Columns []string + // Overridden measurement name to emit. + EmitName string + // The time zone location. Location *time.Location @@ -139,6 +142,10 @@ func (e *Emitter) loadBuf() (t int64, name string, tags Tags, err error) { // createRow creates a new row attached to the emitter. func (e *Emitter) createRow(name string, tags Tags, values []interface{}) { + if e.EmitName != "" { + name = e.EmitName + } + e.tags = tags e.row = &models.Row{ Name: name, diff --git a/query/internal/internal.pb.go b/query/internal/internal.pb.go index b8e88130e0..22b31c85fb 100644 --- a/query/internal/internal.pb.go +++ b/query/internal/internal.pb.go @@ -216,6 +216,7 @@ type IteratorOptions struct { Offset *int64 `protobuf:"varint,13,opt,name=Offset" json:"Offset,omitempty"` SLimit *int64 `protobuf:"varint,14,opt,name=SLimit" json:"SLimit,omitempty"` SOffset *int64 `protobuf:"varint,15,opt,name=SOffset" json:"SOffset,omitempty"` + StripName *bool `protobuf:"varint,22,opt,name=StripName" json:"StripName,omitempty"` Dedupe *bool `protobuf:"varint,16,opt,name=Dedupe" json:"Dedupe,omitempty"` MaxSeriesN *int64 `protobuf:"varint,18,opt,name=MaxSeriesN" json:"MaxSeriesN,omitempty"` Ordered *bool `protobuf:"varint,20,opt,name=Ordered" json:"Ordered,omitempty"` @@ -353,6 +354,13 @@ func (m *IteratorOptions) GetSOffset() int64 { return 0 } +func (m *IteratorOptions) GetStripName() bool { + if m != nil && m.StripName != nil { + return *m.StripName + } + return false +} + func (m *IteratorOptions) GetDedupe() bool { if m != nil && m.Dedupe != nil { return *m.Dedupe @@ -529,53 +537,54 @@ func init() { func init() { proto.RegisterFile("internal/internal.proto", fileDescriptorInternal) } var fileDescriptorInternal = []byte{ - // 757 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x55, 0x51, 0x6f, 0xfb, 0x34, - 0x10, 0x57, 0x92, 0xa6, 0x6b, 0xdc, 0x95, 0xfe, 0x31, 0x65, 0x58, 0x68, 0x42, 0x51, 0x04, 0x52, - 0x04, 0xa8, 0x48, 0x7b, 0xe2, 0x09, 0xa9, 0x63, 0x1b, 0xaa, 0xb4, 0x75, 0x93, 0x33, 0xf6, 0x6e, - 0x9a, 0x5b, 0x64, 0x29, 0x75, 0x8a, 0xe3, 0xa0, 0xf6, 0xa3, 0xf0, 0xb1, 0xf8, 0x14, 0x3c, 0xf2, - 0x15, 0x90, 0xcf, 0x49, 0x9b, 0x4e, 0xa0, 0xfd, 0x9f, 0x7a, 0xbf, 0xdf, 0x5d, 0x6c, 0xdf, 0xdd, - 0xef, 0xae, 0xe4, 0x0b, 0xa9, 0x0c, 0x68, 0x25, 0xca, 0x1f, 0x3a, 0x63, 0xbe, 0xd5, 0x95, 0xa9, - 0x68, 0xf8, 0x7b, 0x03, 0x7a, 0x9f, 0xfc, 0xe3, 0x93, 0xf0, 0xa9, 0x92, 0xca, 0x50, 0x4a, 0x06, - 0x2b, 0xb1, 0x01, 0xe6, 0xc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x43, 0x01, 0xbb, 0x76, 0xe6, 0x1c, 0xb0, 0xf7, 0x2d, 0xeb, 0x67, 0xa1, - 0x0b, 0x30, 0xed, 0xa4, 0x1d, 0x70, 0xf2, 0xd3, 0x51, 0xb0, 0xf8, 0xae, 0x46, 0xbb, 0x6e, 0x7a, - 0x58, 0x99, 0x03, 0xee, 0x75, 0xc6, 0xef, 0x77, 0x26, 0x59, 0x90, 0xc9, 0xc9, 0xae, 0xc1, 0x96, - 0xb4, 0xd5, 0xf5, 0xda, 0x96, 0xb4, 0xa5, 0xbd, 0x20, 0x43, 0xdc, 0xf7, 0xab, 0xee, 0x08, 0x87, - 0x92, 0x39, 0x19, 0xba, 0x99, 0xb3, 0x43, 0xfa, 0x22, 0xca, 0xf6, 0x7f, 0xc0, 0x9a, 0xb8, 0xf2, - 0xed, 0x9a, 0xf2, 0x9d, 0xd0, 0xad, 0xfd, 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x3b, 0x75, 0x73, - 0x01, 0x59, 0x06, 0x00, 0x00, + // 769 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x8c, 0x55, 0xe1, 0x8e, 0xe3, 0x34, + 0x10, 0x56, 0x92, 0x4d, 0xb7, 0x71, 0xb7, 0xf4, 0x30, 0x65, 0xb1, 0xd0, 0x09, 0x45, 0x11, 0x48, + 0x11, 0xa0, 0x22, 0xed, 0x2f, 0x7e, 0x21, 0xf5, 0xd8, 0x5b, 0x54, 0xe9, 0xae, 0x7b, 0x72, 0x97, + 0xfd, 0x6f, 0x9a, 0xd9, 0xc8, 0x52, 0xea, 0x14, 0xc7, 0x41, 0xed, 0x03, 0xf0, 0x10, 0x3c, 0x16, + 0x4f, 0xc2, 0x2b, 0x20, 0x8f, 0x9d, 0x34, 0x5d, 0x81, 0xf6, 0x7e, 0x75, 0xbe, 0x6f, 0xa6, 0x63, + 0xcf, 0xcc, 0x37, 0x0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x64, 0x7f, 0x05, 0x64, 0x32, 0xa0, 0xbb, 0xed, 0xfc, 0x4d, + 0x34, 0xe0, 0x15, 0xdc, 0x63, 0x9a, 0x93, 0x19, 0x07, 0x03, 0xca, 0x36, 0xf8, 0x43, 0x5d, 0xc9, + 0xed, 0x11, 0x57, 0x34, 0xe1, 0xcf, 0xe9, 0xfe, 0x4d, 0x8d, 0xdc, 0x0e, 0x60, 0xd5, 0x73, 0x12, + 0x73, 0x28, 0xe1, 0xe0, 0x37, 0xd2, 0x01, 0x7b, 0xde, 0xaa, 0x79, 0x10, 0xba, 0x04, 0xe3, 0xf7, + 0xb0, 0xc7, 0xd9, 0x4f, 0x27, 0x39, 0xe3, 0xbd, 0x5a, 0xed, 0x66, 0x1d, 0x60, 0x67, 0x7a, 0x3c, + 0x98, 0x5b, 0x38, 0x9c, 0x5b, 0xb6, 0x24, 0xd3, 0xb3, 0x97, 0x08, 0x07, 0xe6, 0xbb, 0x1b, 0xf8, + 0x81, 0xf9, 0xd6, 0x5e, 0x93, 0x11, 0x7e, 0x0d, 0xd6, 0x5d, 0x0a, 0x87, 0xb2, 0x05, 0x19, 0xb9, + 0x8d, 0xb4, 0x2b, 0xfc, 0x28, 0x2a, 0xff, 0x95, 0xb0, 0x26, 0x7e, 0x10, 0xec, 0x23, 0x16, 0xba, + 0x35, 0xb0, 0xf6, 0xbf, 0x01, 0x00, 0x00, 0xff, 0xff, 0x55, 0x55, 0xec, 0xe3, 0x77, 0x06, 0x00, + 0x00, } diff --git a/query/internal/internal.proto b/query/internal/internal.proto index ef52293082..2bb2889e53 100644 --- a/query/internal/internal.proto +++ b/query/internal/internal.proto @@ -46,6 +46,7 @@ message IteratorOptions { optional int64 Offset = 13; optional int64 SLimit = 14; optional int64 SOffset = 15; + optional bool StripName = 22; optional bool Dedupe = 16; optional int64 MaxSeriesN = 18; optional bool Ordered = 20; diff --git a/query/iterator.go b/query/iterator.go index bf97692b2d..4b692dc83a 100644 --- a/query/iterator.go +++ b/query/iterator.go @@ -666,6 +666,9 @@ type IteratorOptions struct { // Limits the number of series. SLimit, SOffset int + // Removes the measurement name. Useful for meta queries. + StripName bool + // Removes duplicate rows from raw queries. Dedupe bool @@ -736,6 +739,7 @@ func newIteratorOptionsStmt(stmt *influxql.SelectStatement, sopt SelectOptions) opt.Condition = condition opt.Ascending = stmt.TimeAscending() opt.Dedupe = stmt.Dedupe + opt.StripName = stmt.StripName opt.Fill, opt.FillValue = stmt.Fill, stmt.FillValue if opt.Fill == influxql.NullFill && stmt.Target != nil { @@ -986,6 +990,7 @@ func encodeIteratorOptions(opt *IteratorOptions) *internal.IteratorOptions { Offset: proto.Int64(int64(opt.Offset)), SLimit: proto.Int64(int64(opt.SLimit)), SOffset: proto.Int64(int64(opt.SOffset)), + StripName: proto.Bool(opt.StripName), Dedupe: proto.Bool(opt.Dedupe), MaxSeriesN: proto.Int64(int64(opt.MaxSeriesN)), Ordered: proto.Bool(opt.Ordered), @@ -1054,6 +1059,7 @@ func decodeIteratorOptions(pb *internal.IteratorOptions) (*IteratorOptions, erro Offset: int(pb.GetOffset()), SLimit: int(pb.GetSLimit()), SOffset: int(pb.GetSOffset()), + StripName: pb.GetStripName(), Dedupe: pb.GetDedupe(), MaxSeriesN: int(pb.GetMaxSeriesN()), Ordered: pb.GetOrdered(), diff --git a/query/iterator_test.go b/query/iterator_test.go index bf2098d870..54eb109b71 100644 --- a/query/iterator_test.go +++ b/query/iterator_test.go @@ -1315,6 +1315,7 @@ func TestIteratorOptions_MarshalBinary(t *testing.T) { Offset: 200, SLimit: 300, SOffset: 400, + StripName: true, Dedupe: true, } diff --git a/tests/server_test.go b/tests/server_test.go index 39c472c647..67c954cd0e 100644 --- a/tests/server_test.go +++ b/tests/server_test.go @@ -6240,12 +6240,6 @@ func TestServer_Query_Where_With_Tags(t *testing.T) { command: `select foo from where_events where tenant != 'paul' OR foo = 'bar'`, exp: `{"results":[{"statement_id":0,"series":[{"name":"where_events","columns":["time","foo"],"values":[["2009-11-10T23:00:02Z","bar"],["2009-11-10T23:00:03Z","baz"],["2009-11-10T23:00:04Z","bat"],["2009-11-10T23:00:05Z","bar"],["2009-11-10T23:00:06Z","bap"]]}]}]}`, }, - &Query{ - name: "where on tag that should be double quoted but isn't", - params: url.Values{"db": []string{"db0"}}, - command: `show series where data-center = 'foo'`, - exp: `{"results":[{"statement_id":0,"error":"invalid tag comparison operator"}]}`, - }, &Query{ name: "where comparing tag and field", params: url.Values{"db": []string{"db0"}}, @@ -7040,18 +7034,6 @@ func TestServer_Query_ShowSeries(t *testing.T) { exp: `{"results":[{"statement_id":0,"series":[{"columns":["key"],"values":[["cpu,host=server01,region=useast"],["cpu,host=server02,region=useast"]]}]}]}`, params: url.Values{"db": []string{"db0"}}, }, - &Query{ - name: `show series with WHERE time should fail`, - command: "SHOW SERIES WHERE time > now() - 1h", - exp: `{"results":[{"statement_id":0,"error":"SHOW SERIES doesn't support time in WHERE clause"}]}`, - params: url.Values{"db": []string{"db0"}}, - }, - &Query{ - name: `show series with WHERE field should fail`, - command: "SHOW SERIES WHERE value > 10.0", - exp: `{"results":[{"statement_id":0,"error":"invalid tag comparison operator"}]}`, - params: url.Values{"db": []string{"db0"}}, - }, }...) for i, query := range test.queries { @@ -7267,13 +7249,7 @@ func TestServer_Query_ShowMeasurements(t *testing.T) { &Query{ name: `show measurements where tag does not match a regular expression`, command: "SHOW MEASUREMENTS WHERE region !~ /ca.*/", - exp: `{"results":[{"statement_id":0,"series":[{"name":"measurements","columns":["name"],"values":[["cpu"]]}]}]}`, - params: url.Values{"db": []string{"db0"}}, - }, - &Query{ - name: `show measurements with time in WHERE clauses errors`, - command: `SHOW MEASUREMENTS WHERE time > now() - 1h`, - exp: `{"results":[{"statement_id":0,"error":"SHOW MEASUREMENTS doesn't support time in WHERE clause"}]}`, + exp: `{"results":[{"statement_id":0,"series":[{"name":"measurements","columns":["name"],"values":[["cpu"],["gpu"]]}]}]}`, params: url.Values{"db": []string{"db0"}}, }, }...) @@ -7433,12 +7409,6 @@ func TestServer_Query_ShowTagKeys(t *testing.T) { exp: `{"results":[{"statement_id":0}]}`, params: url.Values{"db": []string{"db0"}}, }, - &Query{ - name: "show tag keys with time in WHERE clause errors", - command: "SHOW TAG KEYS FROM cpu WHERE time > now() - 1h", - exp: `{"results":[{"statement_id":0,"error":"SHOW TAG KEYS doesn't support time in WHERE clause"}]}`, - params: url.Values{"db": []string{"db0"}}, - }, &Query{ name: "show tag values with key", command: "SHOW TAG VALUES WITH KEY = host", @@ -7629,12 +7599,6 @@ func TestServer_Query_ShowTagKeyCardinality(t *testing.T) { exp: `{"results":[{"statement_id":0,"series":[{"name":"cpu","columns":["count"],"values":[[2]]},{"name":"gpu","columns":["count"],"values":[[2]]}]}]}`, params: url.Values{"db": []string{"db0"}}, }, - &Query{ - name: `show tag values cardinality with key and time in WHERE clause should error`, - command: `SHOW TAG VALUES CARDINALITY WITH KEY = host WHERE time > now() - 1h`, - exp: `{"results":[{"statement_id":0,"error":"SHOW TAG VALUES CARDINALITY doesn't support time in WHERE clause"}]}`, - params: url.Values{"db": []string{"db0"}}, - }, }...) for i, query := range test.queries { diff --git a/tsdb/engine/tsm1/engine.go b/tsdb/engine/tsm1/engine.go index a58fa37789..92db0227bc 100644 --- a/tsdb/engine/tsm1/engine.go +++ b/tsdb/engine/tsm1/engine.go @@ -1961,6 +1961,9 @@ func (e *Engine) createVarRefSeriesIterator(ref *influxql.VarRef, name string, s // If it's only auxiliary fields then it doesn't matter what type of iterator we use. if ref == nil { + if opt.StripName { + name = "" + } return newFloatIterator(name, tags, itrOpt, nil, aux, conds, condNames), nil } @@ -1974,8 +1977,8 @@ func (e *Engine) createVarRefSeriesIterator(ref *influxql.VarRef, name string, s return nil, nil } - // Remove measurement name if we are selecting the name. - if ref.Val == "_name" { + // Remove name if requested. + if opt.StripName { name = "" }