influxdata / influxdata/influxdb
Need to GROUP BY time(...) when filtering SHOW TAG VALUES CARDINALITY by time
- Dominant language
- Rust
- Stars
- 31.7k
- Forks
- 3.7k
- Avg merge
- 13h 37m
- Merged PRs (30d)
- 8
Description
### Bug report
__System info:__
InfluxDB 1.5.2 on CentOS 7
__Steps to reproduce:__
Try to run `SHOW TAG VALUES CARDINALITY FROM "database" WITH KEY = "database" WHERE time > NOW() - 1d`
__Expected behavior:__
The query should return the number of distinct values for tag `database` that have data for the last day.
__Actual behavior:__
The result is empty, meaning no rows are returned at all.
__Additional info:__
Interestingly, this works when `GROUP BY time(1d)`:
```
SHOW TAG VALUES CARDINALITY FROM "database" WITH KEY = "database" WHERE time > NOW() - 1d GROUP BY time(1d)
name: database
count
-----
2
0
```
This is consistent with the behaviour of the rewritten query:
```
> SELECT count(distinct("_tagValue")) FROM "database" WHERE "_tagKey" = 'database' AND time > NOW() - 1d
> SELECT count(distinct("_tagValue")) FROM "database" WHERE "_tagKey" = 'database' AND time > NOW() - 1d GROUP BY time(1d)
name: database
time count
---- -----
1970-01-01T00:00:00Z 2
2018-04-19T00:00:00Z 0
```
Note that `GROUP BY time(1d)` isn't required for `SHOW TAG VALUES FROM "database" WITH KEY = "database" WHERE time > NOW() - 1d` to work.
Contributor guide
Research direction
Start by reproducing the SHOW TAG VALUES CARDINALITY query in the issue, then compare its behavior with the GROUP BY time(1d) form and the rewritten SELECT queries shown. Done means the filtered cardinality query returns the distinct tag count for the requested time range without requiring GROUP BY time(...).
Written by the indexing model from the issue text.
Assessment
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100