influxdata / influxdata/influxdb
Support disparate time intervals and more advanced time in WHERE clauses
- Dominant language
- Rust
- Stars
- 31.7k
- Forks
- 3.7k
- Avg merge
- 13h 37m
- Merged PRs (30d)
- 8
Description
### Feature Request
I'm calling this a feature request, but it's both a feature request and a bug in the existing query engine. Explained more below.
**Proposal:** Support disparate time intervals and more advanced time in WHERE clauses.
**Current behavior:** You can only select one continuous block of time. There is no way to select multiple blocks of time even though the query language _implies_ it should be possible. In fact, we completely _ignore_ any of the query language that would suggest that it's possible in favor of doing something unexpected. Given the following examples:
```
SELECT * FROM cpu WHERE time >= now() - 10m OR (time >= now() - 20m AND region = 'uswest')
```
The above query says you want any points within the last 10 minutes or within the last 20 minutes if the region is uswest. What actually happens is we take all points from the last 10 minutes because we naively look through every binary expression that has `time` as one of the arguments and assume that they were put together with `AND`.
**Desired behavior:** Parse the `WHERE` clause to retrieve the disparate time periods that it specifies correctly. The above example would create two different time intervals. One where the time was anything within the last 10 minutes and one that was within the last 20 minutes if the region was `uswest`.
**Use case:** It prevents confusion from people who are attempting to use the `WHERE` clause in this way and then they find out we do not parse the time clauses in the way that we imply we do. It also opens possibilities in the future of implementing new syntax for selecting only time points in the morning or the afternoon.
I'm not sure how useful this is so it will likely remain low priority. If this is important for your use case, please add a 👍 reaction to this issue and explain your use case so we can learn more about this issue and those it affects.
Thanks!
Contributor guide
Research direction
The issue identifies the query engine's WHERE-clause time parsing as the entry point; begin by tracing how binary expressions containing time are currently combined. Compare the behavior with the supplied OR/AND example, and consider the work complete when disparate intervals and their predicates are retrieved as described, with coverage for that example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- sql
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100