influxdata / influxdata/influxdb
Inconsistent query result depending on tag alphabetical order
- Dominant language
- Rust
- Stars
- 31.7k
- Forks
- 3.7k
- Avg merge
- 13h 37m
- Merged PRs (30d)
- 8
Description
__Steps to reproduce:__
insert the two following points in an empty database :
```
test,atag=b value=0 1605535726949295000
test,atag=a value=2 1605536777343664000
```
__Expected behavior:__
Query n°1: `SELECT "value" FROM "test" ORDER BY time DESC limit 1` returns the most recent point (`value=2`):
```
name: test
time value
---- -----
2020-11-16T14:26:17.343664Z 2
```
Query n°2: `SELECT MAX("value") FROM (SELECT "value" FROM "test" ORDER BY time DESC limit 1) ORDER BY time DESC` returns the MAX of the single value returned by query n°1, ie `2`:
```
name: test
time max
---- ---
2020-11-16T14:26:17.343664Z 2
```
__Actual behavior:__
Query n°1: `SELECT "value" FROM "test" ORDER BY time DESC limit 1` returns the most recent point (`value=2`) as expected.
But query n°2: `SELECT MAX("value") FROM (SELECT "value" FROM "test" ORDER BY time DESC limit 1) ORDER BY time DESC` returns the value of the oldest point (`value=0`) instead of the maximum of the single point returned by the precedent subquery (with `value=2`):
```
name: test
time max
---- ---
2020-11-16T14:08:46.949295Z 0
```
It seems to be related to the tag alphabetical order ("a" < "b"), because if I do the same test, but with these two points (the tags have been exchanged) :
```
test,atag=a value=0 1605535726949295000
test,atag=b value=2 1605536777343664000
```
Then both the query n°1 and the query n°2 return the most recent point (`value=2`) as expected.
__Environment info:__
* System info: Linux 5.8.18-100.fc31.x86_64 x86_64
* InfluxDB version: InfluxDB v1.8.3 (git: 1.8 563e6c3d1a7a2790763c6289501095dbec19244e)
* Other relevant environment details: Running in a docker container
Contributor guide
Research direction
Reproduce the issue in InfluxDB v1.8.3 using the supplied points and the two queries, then trace query execution for the subquery, MAX aggregation, ordering, and tag ordering. Done means the second query returns 2 regardless of tag alphabetical order, with regression coverage for both tag arrangements.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust, sql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100