This restores the old time range behavior

All time ranges are combined with AND regardless of context and
regardless of whether it makes any logical sense.

That was the previous behavior and, unfortunately, a lot of people rely
on it.
pull/8771/head
Jonathan A. Sternberg 2017-08-30 20:16:58 -05:00
parent dad6d95bf8
commit c8440b4778
4 changed files with 17 additions and 8 deletions

View File

@ -37,7 +37,7 @@
- [#8694](https://github.com/influxdata/influxdb/issues/8694): Reduce CPU usage when checking series cardinality
- [#8677](https://github.com/influxdata/influxdb/issues/8677): Fix backups when snapshot is empty.
- [#8706](https://github.com/influxdata/influxdb/pull/8706): Cursor leak, resulting in an accumulation of `.tsm.tmp` files after compactions.
- [#8712](https://github.com/influxdata/influxdb/pull/8712): Force time expressions to use AND and improve condition parsing.
- [#8712](https://github.com/influxdata/influxdb/pull/8712): Improve condition parsing.
- [#8716](https://github.com/influxdata/influxdb/pull/8716): Ensure inputs are closed on error. Add runtime GC finalizer as additional guard to close iterators
- [#8695](https://github.com/influxdata/influxdb/issues/8695): Fix merging bug on system iterators.

View File

@ -4828,11 +4828,8 @@ func ConditionExpr(cond Expr, valuer Valuer) (Expr, TimeRange, error) {
return nil, TimeRange{}, err
}
// If either of the two expressions has a time range and we are combining
// them with OR, return an error since this isn't allowed.
if cond.Op == OR && !(lhsTime.IsZero() && rhsTime.IsZero()) {
return nil, TimeRange{}, errors.New("cannot use OR with time conditions")
}
// Always intersect the time range even if it makes no sense.
// There is no such thing as using OR with a time range.
timeRange := lhsTime.Intersect(rhsTime)
// Combine the left and right expression.

View File

@ -765,7 +765,18 @@ func TestConditionExpr(t *testing.T) {
{s: `4`, err: `invalid condition expression: 4`},
{s: `time >= 'today'`, err: `invalid operation: time and *influxql.StringLiteral are not compatible`},
{s: `time != '2000-01-01T00:00:00Z'`, err: `invalid time comparison operator: !=`},
{s: `host = 'server01' OR (time >= now() - 10m AND host = 'server02')`, err: `cannot use OR with time conditions`},
// This query makes no logical sense, but it's common enough that we pretend
// it does. Technically, this should be illegal because the AND has higher precedence
// than the OR so the AND only applies to the server02 tag, but a person's intention
// is to have it apply to both and previous versions worked that way.
{s: `host = 'server01' OR host = 'server02' AND time >= now() - 10m`,
cond: `host = 'server01' OR host = 'server02'`,
min: mustParseTime("1999-12-31T23:50:00Z")},
// TODO(jsternberg): This should be an error, but we can't because the above query
// needs to work. Until we can work a way for the above to work or at least get
// a warning message for people to transition to a correct syntax, the bad behavior
// stays.
//{s: `host = 'server01' OR (time >= now() - 10m AND host = 'server02')`, err: `cannot use OR with time conditions`},
{s: `value AND host = 'server01'`, err: `invalid condition expression: value`},
{s: `host = 'server01' OR (value)`, err: `invalid condition expression: value`},
{s: `time > '2262-04-11 23:47:17'`, err: `time 2262-04-11T23:47:17Z overflows time literal`},

View File

@ -145,7 +145,8 @@ func TestCompile_Failures(t *testing.T) {
{s: `SELECT bottom(value, 2.5) FROM cpu`, err: `expected integer as last argument in bottom(), found 2.500`},
{s: `SELECT bottom(value, -1) FROM cpu`, err: `limit (-1) in bottom function must be at least 1`},
{s: `SELECT bottom(value, 3) FROM cpu LIMIT 2`, err: `limit (3) in bottom function can not be larger than the LIMIT (2) in the select statement`},
{s: `SELECT value FROM cpu WHERE time >= now() - 10m OR time < now() - 5m`, err: `cannot use OR with time conditions`},
// TODO(jsternberg): This query is wrong, but we cannot enforce this because of previous behavior: https://github.com/influxdata/influxdb/pull/8771
//{s: `SELECT value FROM cpu WHERE time >= now() - 10m OR time < now() - 5m`, err: `cannot use OR with time conditions`},
{s: `SELECT value FROM cpu WHERE value`, err: `invalid condition expression: value`},
{s: `SELECT count(value), * FROM cpu`, err: `mixing aggregate and non-aggregate queries is not supported`},
{s: `SELECT max(*), host FROM cpu`, err: `mixing aggregate and non-aggregate queries is not supported`},