Subquery over an aggregation query: do not understand the result

influxql
influxdb
#1

Hello there!

coming back to experimenting with influxdb (version 1.5.2) I have found a behavior that I cannot fully understand: when I do a subquery over an aggregation query, the returned timeserie has different rows for the same tag.

What I mean is (using the _internal database):

Aggregation query:

select max(currentSegmentDiskBytes) as curr1,sum(currentSegmentDiskBytes) as curr2 ,count(currentSegmentDiskBytes) as curr3 from tsm1_wal where time <= now()-1h AND time >= now()-24h group by "walPath"

Response:

name: tsm1_wal
tags: walPath=/var/lib/influxdb/wal/_internal/monitor/1
time                curr1 curr2 curr3
----                ----- ----- -----
1527154104090214481 0     0     5357

name: tsm1_wal
tags: walPath=/var/lib/influxdb/wal/_internal/monitor/284
time                curr1    curr2       curr3
----                -----    -----       -----
1527154104090214481 10490027 25444967007 8280

name: tsm1_wal
tags: walPath=/var/lib/influxdb/wal/_internal/monitor/30
time                curr1 curr2 curr3
----                ----- ----- -----
1527154104090214481 0     0     8280

name: tsm1_wal
tags: walPath=/var/lib/influxdb/wal/_internal/monitor/31
time                curr1 curr2 curr3
----                ----- ----- -----
1527154104090214481 0     0     8280

name: tsm1_wal
tags: walPath=/var/lib/influxdb/wal/_internal/monitor/32
time                curr1 curr2 curr3
----                ----- ----- -----
1527154104090214481 0     0     8280

name: tsm1_wal
tags: walPath=/var/lib/influxdb/wal/_internal/monitor/375
time                curr1    curr2       curr3
----                -----    -----       -----
1527154104090214481 10492703 15483021061 3050

name: tsm1_wal
tags: walPath=/var/lib/influxdb/wal/_internal/monitor/90
time                curr1 curr2 curr3
----                ----- ----- -----
1527154104090214481 0     0     8280

name: tsm1_wal
tags: walPath=/var/lib/influxdb/wal/testIntegration/autogen/374
time                curr1 curr2 curr3
----                ----- ----- -----
1527154104090214481 606   36360 7250

Subquery over the aggregation query:

select curr1,curr2,curr3,"walPath" from (select max(currentSegmentDiskBytes) as curr1,sum(currentSegmentDiskBytes) as curr2 ,count(currentSegmentDiskBytes) as curr3 from tsm1_wal where time <= now()-1h AND time >= now()-24h group by "walPath")

Response:

name: tsm1_wal
time                curr1    curr2       curr3 walPath
----                -----    -----       ----- -------
1527154135724359121 0        0           5354  /var/lib/influxdb/wal/_internal/monitor/1
1527154135724359121          25415575430 8280  /var/lib/influxdb/wal/_internal/monitor/284
1527154135724359121 0        0           8280  /var/lib/influxdb/wal/_internal/monitor/30
1527154135724359121 0        0           8280  /var/lib/influxdb/wal/_internal/monitor/31
1527154135724359121 0        0           8280  /var/lib/influxdb/wal/_internal/monitor/32
1527154135724359121          15510757296 3053  /var/lib/influxdb/wal/_internal/monitor/375
1527154135724359121 0        0           8280  /var/lib/influxdb/wal/_internal/monitor/90
1527154135724359121 606      36360       7253  /var/lib/influxdb/wal/testIntegration/autogen/374
1527154135724359121 10490027                   /var/lib/influxdb/wal/_internal/monitor/284
1527154135724359121 10492703                   /var/lib/influxdb/wal/_internal/monitor/375

As you can see in the subquery, there are 2 different rows for the tag /var/lib/influxdb/wal/_internal/monitor/375 and 2 different rows for the tag /var/lib/influxdb/wal/_internal/monitor/284. However in the aggregation query for each tag there is just one timeserie.

The problem here is that I want to sort the results of the subquery over one of the fields (using top(), because I don’t know if there is a better way), some thing like this:

Subquery over the aggregation query sorted by curr1:

select top(curr1,"walPath",20) as curr1,curr2,curr3 from (select max(currentSegmentDiskBytes) as curr1,sum(currentSegmentDiskBytes) as curr2 ,count(currentSegmentDiskBytes) as curr3 from tsm1_wal where time <= now()-1h AND time >= now()-24h group by "walPath")

Response:

time                curr1    walPath                                                    curr2 curr3
----                -----    -------                                                    ----- -----
1527155363571782386 10492703 /var/lib/influxdb/wal/_internal/monitor/375                      
1527155363571782386 10490027 /var/lib/influxdb/wal/_internal/monitor/284                      
1527155363571782386 606      /var/lib/influxdb/wal/testIntegration/autogen/374          36360 7376
1527155363571782386 0        /var/lib/influxdb/wal/_internal/monitor/1                  0     5231
1527155363571782386 0        /var/lib/influxdb/wal/_internal/monitor/30                 0     8280
1527155363571782386 0        /var/lib/influxdb/wal/_internal/monitor/32                 0     8280
1527155363571782386 0        /var/lib/influxdb/wal/_internal/monitor/90                 0     8280
1527155363571782386 0        /var/lib/influxdb/wal/_internal/monitor/31                 0     8280

As you can see, I have lost the values of the fields curr2 and curr3 for the tags /var/lib/influxdb/wal/_internal/monitor/375 and /var/lib/influxdb/wal/_internal/monitor/284

Any ideas?

Thanks in advance!