influxdb icon indicating copy to clipboard operation
influxdb copied to clipboard

[0.9.4.1] "ORDER BY DESC" doesn't properly order output

Open abukaka opened this issue 11 years ago • 33 comments

I'm trying to get the newest n points from a series

>  select * from "76603ea0-f7ea-40ce-819a-df51f16cb379" where time > now() - 1m
name: 76603ea0-f7ea-40ce-819a-df51f16cb379
------------------------------------------
time                            value
2015-09-25T21:54:51.074Z        3.49632
2015-09-25T21:55:21.084Z        3.51199

> select value from "76603ea0-f7ea-40ce-819a-df51f16cb379" order by desc limit 10
name: 76603ea0-f7ea-40ce-819a-df51f16cb379
------------------------------------------
time                            value
2015-09-25T21:38:50.69Z         3.34024
2015-09-25T21:38:20.673Z        3.33428
2015-09-25T21:37:50.663Z        3.33001
2015-09-25T21:37:20.653Z        3.32566
2015-09-25T21:36:50.636Z        3.32132
2015-09-25T21:36:20.626Z        3.31698
2015-09-25T21:35:50.615Z        3.31252
2015-09-25T21:35:20.605Z        3.30831
2015-09-25T21:34:50.595Z        3.30364
2015-09-25T21:34:20.585Z        3.29886

The first query correctly shows the latest point:

2015-09-25T21:55:21.084Z        3.51199

But the second query is showing 10 points from an earlier time. The data is coming in every 30 seconds, but I keep getting the exact same resultset from the second query until I restart influxdb, and then it stays at a newer resultset.

abukaka avatar Sep 25 '15 22:09 abukaka

Might be a caching issue. @jwilder thoughts on this ORDER BY DESC bug?

beckettsean avatar Sep 25 '15 22:09 beckettsean

I can confirm the behavior. The following queries were run within 20 seconds of each other:

For each of the select * from cpu_busy order by desc limit 10 notice that the timestamps are identical but the series returned is non-deterministic. Not sure if that's a bug or not.

In any event, there is clearly more recent data than the 18:37:28 points, yet that's all the ORDER BY DESC queries return.

> select * from cpu_busy order by desc limit 10
name: cpu_busy
--------------
time                cpu host        value
2015-09-25T18:37:28.145778884Z  cpu5    catalyst    572.640625
2015-09-25T18:37:21.146185424Z  cpu5    catalyst    572.6328125
2015-09-25T18:37:14.14466783Z   cpu5    catalyst    572.625
2015-09-25T18:37:07.146164339Z  cpu5    catalyst    572.6171875
2015-09-25T18:37:00.138410476Z  cpu5    catalyst    572.609375
2015-09-25T18:36:53.145089554Z  cpu5    catalyst    572.6015625
2015-09-25T18:36:46.139973579Z  cpu5    catalyst    572.59375
2015-09-25T18:36:39.141992625Z  cpu5    catalyst    572.5859375
2015-09-25T18:36:32.147192457Z  cpu5    catalyst    572.578125
2015-09-25T18:36:25.143305949Z  cpu5    catalyst    572.578125

> select * from cpu_busy order by desc limit 10
name: cpu_busy
--------------
time                cpu host        value
2015-09-25T18:37:28.145778884Z  cpu1    catalyst    550.203125
2015-09-25T18:37:21.146185424Z  cpu1    catalyst    550.203125
2015-09-25T18:37:14.14466783Z   cpu1    catalyst    550.1875
2015-09-25T18:37:07.146164339Z  cpu1    catalyst    550.1875
2015-09-25T18:37:00.138410476Z  cpu1    catalyst    550.1796875
2015-09-25T18:36:53.145089554Z  cpu1    catalyst    550.171875
2015-09-25T18:36:46.139973579Z  cpu1    catalyst    550.1640625
2015-09-25T18:36:39.141992625Z  cpu1    catalyst    550.15625
2015-09-25T18:36:32.147192457Z  cpu1    catalyst    550.1484375
2015-09-25T18:36:25.143305949Z  cpu1    catalyst    550.1484375

> select * from cpu_busy order by desc limit 10
name: cpu_busy
--------------
time                cpu host        value
2015-09-25T18:37:28.145778884Z  cpu2    catalyst    5758.6796875
2015-09-25T18:37:21.146185424Z  cpu2    catalyst    5758.6484375
2015-09-25T18:37:14.14466783Z   cpu2    catalyst    5758.4453125
2015-09-25T18:37:07.146164339Z  cpu2    catalyst    5758.3671875
2015-09-25T18:37:00.138410476Z  cpu2    catalyst    5758.3203125
2015-09-25T18:36:53.145089554Z  cpu2    catalyst    5758.2109375
2015-09-25T18:36:46.139973579Z  cpu2    catalyst    5758.1484375
2015-09-25T18:36:39.141992625Z  cpu2    catalyst    5758.1015625
2015-09-25T18:36:32.147192457Z  cpu2    catalyst    5758.0390625
2015-09-25T18:36:25.143305949Z  cpu2    catalyst    5757.9921875

> select * from cpu_busy where time > now() - 1m
name: cpu_busy
--------------
time                cpu     host        value
2015-09-25T22:46:26.822606851Z  cpu3        catalyst    654.40625
2015-09-25T22:46:26.822606851Z  cpu1        catalyst    627.3125
2015-09-25T22:46:26.822606851Z  cpu7        catalyst    650.8203125
2015-09-25T22:46:26.822606851Z  cpu5        catalyst    649.5703125
2015-09-25T22:46:26.822606851Z  cpu4        catalyst    6984.0859375
2015-09-25T22:46:26.822606851Z  cpu6        catalyst    6977.765625
2015-09-25T22:46:26.822606851Z  cpu2        catalyst    6988.0703125
2015-09-25T22:46:26.822606851Z  cpu0        catalyst    10862.1640625
2015-09-25T22:46:26.822606851Z  cpu-total   catalyst    34394.1953125
2015-09-25T22:46:33.823754066Z  cpu0        catalyst    10862.828125
2015-09-25T22:46:33.823754066Z  cpu-total   catalyst    34395.5
2015-09-25T22:46:33.823754066Z  cpu7        catalyst    650.828125
2015-09-25T22:46:33.823754066Z  cpu3        catalyst    654.4140625
2015-09-25T22:46:33.823754066Z  cpu1        catalyst    627.3203125
2015-09-25T22:46:33.823754066Z  cpu2        catalyst    6988.25
2015-09-25T22:46:33.823754066Z  cpu5        catalyst    649.5703125
2015-09-25T22:46:33.823754066Z  cpu6        catalyst    6977.875
2015-09-25T22:46:33.823754066Z  cpu4        catalyst    6984.4140625
2015-09-25T22:46:49.032374681Z  cpu6        catalyst    6978.34375
2015-09-25T22:46:49.032374681Z  cpu4        catalyst    6984.9765625
2015-09-25T22:46:49.032374681Z  cpu7        catalyst    650.84375
2015-09-25T22:46:49.032374681Z  cpu0        catalyst    10864.359375
2015-09-25T22:46:49.032374681Z  cpu-total   catalyst    34398.5703125
2015-09-25T22:46:49.032374681Z  cpu5        catalyst    649.578125
2015-09-25T22:46:49.032374681Z  cpu3        catalyst    654.421875
2015-09-25T22:46:49.032374681Z  cpu2        catalyst    6988.7109375
2015-09-25T22:46:49.032374681Z  cpu1        catalyst    627.3359375
2015-09-25T22:46:56.035665737Z  cpu2        catalyst    6988.96875
2015-09-25T22:46:56.035665737Z  cpu1        catalyst    627.3359375
2015-09-25T22:46:56.035665737Z  cpu7        catalyst    650.84375
2015-09-25T22:46:56.035665737Z  cpu6        catalyst    6978.640625
2015-09-25T22:46:56.035665737Z  cpu4        catalyst    6985.234375
2015-09-25T22:46:56.035665737Z  cpu3        catalyst    654.4375
2015-09-25T22:46:56.035665737Z  cpu0        catalyst    10865.1015625
2015-09-25T22:46:56.035665737Z  cpu5        catalyst    649.59375
2015-09-25T22:46:56.035665737Z  cpu-total   catalyst    34400.1640625
2015-09-25T22:47:03.035745541Z  cpu5        catalyst    649.6015625
2015-09-25T22:47:03.035745541Z  cpu-total   catalyst    34402.1328125
2015-09-25T22:47:03.035745541Z  cpu7        catalyst    650.8515625
2015-09-25T22:47:03.035745541Z  cpu2        catalyst    6989.484375
2015-09-25T22:47:03.035745541Z  cpu1        catalyst    627.34375
2015-09-25T22:47:03.035745541Z  cpu0        catalyst    10865.9375
2015-09-25T22:47:03.035745541Z  cpu6        catalyst    6978.9375
2015-09-25T22:47:03.035745541Z  cpu3        catalyst    654.4375
2015-09-25T22:47:03.035745541Z  cpu4        catalyst    6985.5390625
2015-09-25T22:47:10.036339336Z  cpu4        catalyst    6985.734375
2015-09-25T22:47:10.036339336Z  cpu7        catalyst    650.8515625
2015-09-25T22:47:10.036339336Z  cpu5        catalyst    649.6015625
2015-09-25T22:47:10.036339336Z  cpu-total   catalyst    34403.53125
2015-09-25T22:47:10.036339336Z  cpu3        catalyst    654.4453125
2015-09-25T22:47:10.036339336Z  cpu6        catalyst    6979.171875
2015-09-25T22:47:10.036339336Z  cpu2        catalyst    6989.7109375
2015-09-25T22:47:10.036339336Z  cpu0        catalyst    10866.6640625
2015-09-25T22:47:10.036339336Z  cpu1        catalyst    627.3515625
2015-09-25T22:47:17.039300539Z  cpu4        catalyst    6986.1640625
2015-09-25T22:47:17.039300539Z  cpu0        catalyst    10867.4921875
2015-09-25T22:47:17.039300539Z  cpu1        catalyst    627.421875
2015-09-25T22:47:17.039300539Z  cpu7        catalyst    650.9296875
2015-09-25T22:47:17.039300539Z  cpu3        catalyst    654.5234375
2015-09-25T22:47:17.039300539Z  cpu2        catalyst    6990
2015-09-25T22:47:17.039300539Z  cpu5        catalyst    649.6875
2015-09-25T22:47:17.039300539Z  cpu6        catalyst    6979.5625
2015-09-25T22:47:17.039300539Z  cpu-total   catalyst    34405.78125
2015-09-25T22:47:24.039074098Z  cpu6        catalyst    6979.765625
2015-09-25T22:47:24.039074098Z  cpu-total   catalyst    34407.1640625
2015-09-25T22:47:24.039074098Z  cpu4        catalyst    6986.390625
2015-09-25T22:47:24.039074098Z  cpu0        catalyst    10868.2109375
2015-09-25T22:47:24.039074098Z  cpu1        catalyst    627.4375
2015-09-25T22:47:24.039074098Z  cpu3        catalyst    654.53125
2015-09-25T22:47:24.039074098Z  cpu2        catalyst    6990.1875
2015-09-25T22:47:24.039074098Z  cpu7        catalyst    650.9453125
2015-09-25T22:47:24.039074098Z  cpu5        catalyst    649.6953125

> select * from cpu_busy order by desc limit 10
name: cpu_busy
--------------
time                cpu     host        value
2015-09-25T18:37:28.145778884Z  cpu-total   catalyst    29100.0859375
2015-09-25T18:37:21.146185424Z  cpu-total   catalyst    29099.8359375
2015-09-25T18:37:14.14466783Z   cpu-total   catalyst    29098.6875
2015-09-25T18:37:07.146164339Z  cpu-total   catalyst    29098.3125
2015-09-25T18:37:00.138410476Z  cpu-total   catalyst    29097.9765625
2015-09-25T18:36:53.145089554Z  cpu-total   catalyst    29097.5546875
2015-09-25T18:36:46.139973579Z  cpu-total   catalyst    29097.3125
2015-09-25T18:36:39.141992625Z  cpu-total   catalyst    29097.0546875
2015-09-25T18:36:32.147192457Z  cpu-total   catalyst    29096.6640625
2015-09-25T18:36:25.143305949Z  cpu-total   catalyst    29096.4296875

> 

beckettsean avatar Sep 25 '15 22:09 beckettsean

It's not caching, or at least changing the measurement to one I haven't queried ever before still returns the older points:

> select * from cpu_guest where time > now() - 20s
name: cpu_guest
---------------
time                cpu     host        value
2015-09-25T22:50:33.041239173Z  cpu7        catalyst    0
2015-09-25T22:50:33.041239173Z  cpu2        catalyst    0
2015-09-25T22:50:33.041239173Z  cpu3        catalyst    0
2015-09-25T22:50:33.041239173Z  cpu1        catalyst    0
2015-09-25T22:50:33.041239173Z  cpu-total   catalyst    0
2015-09-25T22:50:33.041239173Z  cpu0        catalyst    0
2015-09-25T22:50:33.041239173Z  cpu5        catalyst    0
2015-09-25T22:50:33.041239173Z  cpu4        catalyst    0
2015-09-25T22:50:33.041239173Z  cpu6        catalyst    0
2015-09-25T22:50:40.039990577Z  cpu7        catalyst    0
2015-09-25T22:50:40.039990577Z  cpu4        catalyst    0
2015-09-25T22:50:40.039990577Z  cpu6        catalyst    0
2015-09-25T22:50:40.039990577Z  cpu2        catalyst    0
2015-09-25T22:50:40.039990577Z  cpu-total   catalyst    0
2015-09-25T22:50:40.039990577Z  cpu5        catalyst    0
2015-09-25T22:50:40.039990577Z  cpu3        catalyst    0
2015-09-25T22:50:40.039990577Z  cpu0        catalyst    0
2015-09-25T22:50:40.039990577Z  cpu1        catalyst    0
2015-09-25T22:50:47.039657797Z  cpu0        catalyst    0
2015-09-25T22:50:47.039657797Z  cpu1        catalyst    0
2015-09-25T22:50:47.039657797Z  cpu7        catalyst    0
2015-09-25T22:50:47.039657797Z  cpu4        catalyst    0
2015-09-25T22:50:47.039657797Z  cpu6        catalyst    0
2015-09-25T22:50:47.039657797Z  cpu-total   catalyst    0
2015-09-25T22:50:47.039657797Z  cpu5        catalyst    0
2015-09-25T22:50:47.039657797Z  cpu2        catalyst    0
2015-09-25T22:50:47.039657797Z  cpu3        catalyst    0

> select * from cpu_guest order by desc limit 10
name: cpu_guest
---------------
time                cpu     host        value
2015-09-25T18:37:28.145778884Z  cpu-total   catalyst    0
2015-09-25T18:37:21.146185424Z  cpu-total   catalyst    0
2015-09-25T18:37:14.14466783Z   cpu-total   catalyst    0
2015-09-25T18:37:07.146164339Z  cpu-total   catalyst    0
2015-09-25T18:37:00.138410476Z  cpu-total   catalyst    0
2015-09-25T18:36:53.145089554Z  cpu-total   catalyst    0
2015-09-25T18:36:46.139973579Z  cpu-total   catalyst    0
2015-09-25T18:36:39.141992625Z  cpu-total   catalyst    0
2015-09-25T18:36:32.147192457Z  cpu-total   catalyst    0
2015-09-25T18:36:25.143305949Z  cpu-total   catalyst    0

beckettsean avatar Sep 25 '15 22:09 beckettsean

It's interesting that the timestamp doesn't move forward. Some similar symptoms to #4209 although no ORDER BY in that issue and in this issue, the normal WHERE time queries return the expected results.

beckettsean avatar Sep 25 '15 22:09 beckettsean

I see the same behaviour.

markusr avatar Sep 29 '15 16:09 markusr

possibly related to https://github.com/influxdb/influxdb/issues/4232

beckettsean avatar Sep 29 '15 18:09 beckettsean

I have the same problem. It looks like when using DESC, it cannot have the latest data in X minutes but ASC works fine.

Here is my test: select * from "2.bs.status" where time > now() - 5m order by time desc => no record select * from "2.bs.status" where time > now() - 5m order by time asc => 51 records

melson-jao avatar Oct 01 '15 04:10 melson-jao

same issue for me

> select host_platform_hostname, ip from device where uuid='xxx' order by time desc limit 20;
name: device
------------
time                host_platform_hostname  ip
2015-10-07T20:07:15.413421077Z  xxx
2015-10-07T16:06:58.455773567Z  xxx
2015-10-07T12:06:41.936796682Zxxx
2015-10-07T08:06:28.2645801Z    xxx
2015-10-07T04:06:26.473557076Z  xxx
2015-10-07T00:06:23.686127241Z  xxx
2015-10-06T20:06:12.676490453Z  xxx
2015-10-06T16:06:08.18404945Z   xxx
2015-10-06T12:06:00.728460079Z  xxx
2015-10-06T08:05:51.025483794Zxxx
2015-10-06T04:05:37.363029562Z  xxx
2015-10-06T00:05:28.033830294Z  xxx
2015-10-05T20:05:17.565873246Zxxx
2015-10-05T16:05:02.900082772Z  xxx
2015-10-05T12:04:50.210404264Zxxx
2015-10-05T08:04:34.163433683Z  xxx
2015-10-05T04:04:21.854884971Zxxx
2015-10-07T21:50:28.74730167Z   xxx     a.b.c.d
2015-10-05T00:04:13.617422854Zxxx
2015-10-04T20:04:06.976163638Zxxx

I assume a.b.c.d ip should be on the top

theromis avatar Oct 07 '15 22:10 theromis

Pretty sure this is an issue w/ the bz1 engine and WAL cursors. Have you tried the tsm1 engine?

jwilder avatar Oct 07 '15 22:10 jwilder

How can I try it? Sorry I'm not familiar with influxdb internals. But I really like this db and believe in it. BTW: if this is an issue, how I can convert my current storage to tsm1?

theromis avatar Oct 07 '15 22:10 theromis

@theromis More info here: https://influxdb.com/blog/2015/10/07/the_new_influxdb_storage_engine_a_time_structured_merge_tree.html

jwilder avatar Oct 07 '15 22:10 jwilder

@jwilder Thank you, I saw this info today, but how I can convert my current data into this new format?

theromis avatar Oct 07 '15 23:10 theromis

@theromis This is no convertor right now. If you enable the new engine, new data will be written using the the new engine. Existing data will still use the older engines.

jwilder avatar Oct 07 '15 23:10 jwilder

@jwilder Can I switch storage type to tsm1 in 0.9.4.1 just changing type in conf file? Cannot find any entries in the influxdb.conf

edit: can see in 0.9.4.2, will try it now

theromis avatar Oct 07 '15 23:10 theromis

@theromis No. tsm1 is not available in 0.9.4 releases. You need to install the latest nightly build or wait until 0.9.5 and change your config file according the the instructions linked from the blog post. The latest nightly can be downloaded here: https://influxdb.com/download/index.html

jwilder avatar Oct 07 '15 23:10 jwilder

@jwilder updated to 0.9.5 nightly build, but it still showing same result. Should I create new empty database?

theromis avatar Oct 07 '15 23:10 theromis

@theromis You're old data will still still show the wrong sorts since it's still stored in the older engine format. New data written to new shards created by the tsm1 engine should (hopefully) sort correctly. Creating a new database will make that happen faster though.

jwilder avatar Oct 07 '15 23:10 jwilder

@jwilder Thank you, will try it now.

theromis avatar Oct 07 '15 23:10 theromis

I observed the same behaviour, it seems as if limit is applied before ordering, so in my case:

select sum(value) FROM net_bytes_recv where time > now() - 1h group by time(30s) order by time desc limit 5;

returns five oldest points ordered by time in descending order.

legendary-jarppi avatar Oct 15 '15 05:10 legendary-jarppi

I can reproduce same behavior on 0.9.4.2

Using the nightly build of 0.9.5, with the tsm1 engine and a fresh db, ORDER BY DESC seems to work correctly.

markcwill avatar Oct 16 '15 00:10 markcwill