Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[0.9.4.2] for WHERE time, Operator 'OR' behaves as 'AND' #4449

Closed
madshall opened this issue Oct 14, 2015 · 8 comments
Closed

[0.9.4.2] for WHERE time, Operator 'OR' behaves as 'AND' #4449

madshall opened this issue Oct 14, 2015 · 8 comments

Comments

@madshall
Copy link

The query:

select * from "application.heartbeat.count" WHERE time > '2015-10-10' LIMIT 10

returns:

time                            value
2015-10-13T13:33:46.257Z        1
2015-10-13T13:33:46.349Z        1
2015-10-13T13:33:46.611Z        1
2015-10-13T13:33:51.32Z         1
2015-10-13T13:33:51.415Z        1
2015-10-13T13:33:51.677Z        1
2015-10-13T13:33:56.382Z        1
2015-10-13T13:33:56.484Z        1
2015-10-13T13:33:56.742Z        1
2015-10-13T13:34:01.446Z        1

The query:

select * from "application.heartbeat.count" WHERE time < '2015-10-07' GROUP BY * LIMIT 10

returns:

time                            value
2015-10-06T17:44:38.689Z        1
2015-10-06T17:44:43.784Z        1
2015-10-06T17:44:48.877Z        1
2015-10-06T17:44:53.96Z         1
2015-10-06T17:44:59.036Z        1
2015-10-06T17:45:04.113Z        1
2015-10-06T17:45:09.188Z        1
2015-10-06T17:45:14.263Z        1
2015-10-06T17:45:19.334Z        1
2015-10-06T17:45:24.408Z        1

But the query:

select * from "application.heartbeat.count" WHERE time > '2015-10-07' OR time < '2015-10-10' GROUP BY * ORDER BY time DESC LIMIT 10

returns an intersection and not a conjunction:

time                            value
2015-10-09T20:55:21.206Z        1
2015-10-09T20:55:16.144Z        1
2015-10-09T20:55:11.08Z         1
2015-10-09T20:55:06.541Z        1
2015-10-09T20:55:01.477Z        1
2015-10-09T20:54:56.526Z        1
2015-10-09T20:54:51.463Z        1
2015-10-09T20:54:46.402Z        1
2015-10-09T20:54:41.343Z        1
2015-10-09T20:54:36.285Z        1
@beckettsean
Copy link
Contributor

@madshall what version of InfluxDB are you running?

@beckettsean beckettsean changed the title Operator 'OR' behaves as 'AND' for WHERE time, Operator 'OR' behaves as 'AND' Oct 14, 2015
@madshall
Copy link
Author

@beckettsean I'm running the latest 0.9.4.2 build.

@fg2it
Copy link
Contributor

fg2it commented Oct 14, 2015

@madshall your query is a bit strange. From https://influxdb.com/docs/v0.9/query_language/functions.html it is expected that you use group by with an aggregate function. In addition, you are also expected to have a lower bound on time, which is not the case with your OR condition.
By the way, what is supposed to return a group by * statement ?

@beckettsean beckettsean changed the title for WHERE time, Operator 'OR' behaves as 'AND' [0.9.4.2] for WHERE time, Operator 'OR' behaves as 'AND' Oct 14, 2015
@madshall
Copy link
Author

@fg2it that group by doesn't matter, I might leave it by mistake when compiled an example. Regarding your another question, GROUP BY * aggregates data by all tags.

@beckettsean
Copy link
Contributor

@fg2it GROUP BY * produces results grouped by every tag set. For example:

> select count(value) from disk_total where time > now() - 1m 
name: disk_total
----------------
time                count
2015-10-14T22:19:02.805709299Z  32

> select count(value) from disk_total where time > now() - 1m group by *
name: disk_total
tags: fstype=autofs, host=catalyst, path=/home
time                count
----                -----
2015-10-14T22:18:58.925464583Z  9


name: disk_total
tags: fstype=autofs, host=catalyst, path=/net
time                count
----                -----
2015-10-14T22:18:58.925464583Z  9


name: disk_total
tags: fstype=devfs, host=catalyst, path=/dev
time                count
----                -----
2015-10-14T22:18:58.925464583Z  9


name: disk_total
tags: fstype=hfs, host=catalyst, path=/
time                count
----                -----
2015-10-14T22:18:58.925464583Z  9

@beckettsean
Copy link
Contributor

Further characterization, when using relative offsets the "winner" of the OR is the one with the smaller result set (I think).

Testing with time > now() - xx

> select count(value) from disk_total where time > now() - 12m
name: disk_total
----------------
time                count
2015-10-14T22:11:47.377489Z 336

> select count(value) from disk_total where time > now() - 1m
name: disk_total
----------------
time                count
2015-10-14T22:22:49.986010247Z  36

> select count(value) from disk_total where time > now() - 12m or time > now() - 1m
name: disk_total
----------------
time                count
2015-10-14T22:22:53.794122118Z  32

> select count(value) from disk_total where time > now() - 1m or time > now() - 12m
name: disk_total
----------------
time                count
2015-10-14T22:22:58.537766Z 36

Testing with time < now() - xx

> select count(value) from disk_total where time < now() - 50d
name: disk_total
----------------
time            count
1970-01-01T00:00:00Z    290225

> select count(value) from disk_total where time < now() - 70d
name: disk_total
----------------
time            count
1970-01-01T00:00:00Z    152505

> select count(value) from disk_total where time < now() - 70d or time < now() - 50d
name: disk_total
----------------
time            count
1970-01-01T00:00:00Z    152505

> select count(value) from disk_total where time < now() - 50d or time < now() - 70d
name: disk_total
----------------
time            count
1970-01-01T00:00:00Z    152505

Another explanation is that the smaller result pool is returned

@beckettsean
Copy link
Contributor

Same appears to be true for absolute time ranges:

> select count(value) from disk_total where time > '2015-10-13 12:00:01'
name: disk_total
----------------
time                count
2015-10-13T12:00:01.000000001Z  21290

> select count(value) from disk_total where time > '2015-10-14 12:00:01'
name: disk_total
----------------
time                count
2015-10-14T12:00:01.000000001Z  5644

> select count(value) from disk_total where time > '2015-10-13 12:00:01' or time > '2015-10-14 12:00:01'
name: disk_total
----------------
time                count
2015-10-14T12:00:01.000000001Z  5636

> select count(value) from disk_total where time > '2015-10-14 12:00:01' or time > '2015-10-13 12:00:01'
name: disk_total
----------------
time                count
2015-10-14T12:00:01.000000001Z  5676

> select count(value) from disk_total where time < '2015-08-13 12:00:01'
name: disk_total
----------------
time            count
1970-01-01T00:00:00Z    181657

> select count(value) from disk_total where time < '2015-08-01 12:00:01'
name: disk_total
----------------
time            count
1970-01-01T00:00:00Z    122598

> select count(value) from disk_total where time < '2015-08-13 12:00:01' or time < '2015-08-01 12:00:01'
name: disk_total
----------------
time            count
1970-01-01T00:00:00Z    122598

> select count(value) from disk_total where time < '2015-08-01 12:00:01' or time < '2015-08-13 12:00:01'
name: disk_total
----------------
time            count
1970-01-01T00:00:00Z    122598

@jsternberg
Copy link
Contributor

This seems to be the same as #3290. The OR operator doesn't currently work as all time operations are assumed to be AND. I'm closing this in favor of #3290.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants