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

ORDER BY time DESC probably returns the wrong results sometimes #7905

Closed
jsternberg opened this issue Jan 30, 2017 · 1 comment
Closed

ORDER BY time DESC probably returns the wrong results sometimes #7905

jsternberg opened this issue Jan 30, 2017 · 1 comment

Comments

@jsternberg
Copy link
Contributor

jsternberg commented Jan 30, 2017

Bug report

System info: InfluxDB 1.2.0

Steps to reproduce:

> CREATE DATABASE db0
> USE db0
> INSERT cpu,host=server01 value=2 1000000000
> INSERT cpu,host=server01 value=3 2000000000
> INSERT cpu,host=server02 value=4 1000000000
> INSERT cpu,host=server02 value=5 2000000000
> SELECT value, host FROM cpu ORDER BY time DESC
name: cpu
time                value host
----                ----- ----
2000000000          3     server01
2000000000          5     server02
1000000000          2     server01
1000000000          4     server02

The order should be server02 before server01. There is also an error in the Emitter which causes this one:

> CREATE DATABASE db0
> USE db0
> INSERT mem,host=server01 free=1 1000000000
> INSERT mem,host=server01 free=2 2000000000
> INSERT mem,host=server02 used=3 1000000000
> INSERT mem,host=server02 used=4 2000000000
> SELECT first("used") AS "used", first("free") AS "free" FROM "mem" WHERE time >= '1970-01-01T00:00:01Z' AND time <= '1970-01-01T00:00:02Z' GROUP BY host, time(1s) FILL(none) ORDER BY time DESC
name: mem
tags: host=server01
time       used free
----       ---- ----
2000000000      2
1000000000      1

name: mem
tags: host=server02
time       used free
----       ---- ----
2000000000 4
1000000000 3

server02 is supposed to be before server01.

Additional info:

This section of code seems wrong and an earlier version of the code seems to do something different:

        // Update range values if lower and emitter is in time ascending order.
        if e.ascending {
            if (itrName < name) || (itrName == name && itrTags.ID() < tags.ID()) || (itrName == name && itrTags.ID() == tags.ID() && itrTime < t) {
                t, name, tags = itrTime, itrName, itrTags
            }
            continue
        }

        // Update range values if higher and emitter is in time descending order.
        if (itrName < name) || (itrName == name && itrTags.ID() < tags.ID()) || (itrName == name && itrTags.ID() == tags.ID() && itrTime < t) {
            t, name, tags = itrTime, itrName, itrTags
        }

It seems like the second statement there have the conditions in the wrong direction.

@jsternberg jsternberg changed the title GROUP BY time DESC probably returns the wrong results sometimes ORDER BY time DESC probably returns the wrong results sometimes Jan 30, 2017
@jwilder jwilder added this to the 1.2.1 milestone Feb 6, 2017
@jsternberg
Copy link
Contributor Author

Fixed via #7907.

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

2 participants