InfluxQL query cannot detect all the fields from subquery result

Steps to reproduce:

  1. Bring up the sandbox to get the latest influxdb instance and get the auto-generated _internal.monitor data for example.
  2. Run query on chronograf:

SELECT mean("usage_nice"), mean("usage_iowait") FROM "telegraf"."autogen"."cpu" GROUP BY time(2m) , which will return results of cpu.mean and cpu.mean_1 . This is expected since we selected 2 fields in the query.

  1. However, if we put the query in step 2 to be the subquery like:

SELECT last(*) FROM (SELECT mean("usage_nice"), mean("usage_iowait") FROM "telegraf"."autogen"."cpu" GROUP BY time(2m)) , it will only return one field’s result: cpu.last_mean whereas 2 field results are expected here since the subquery returns 2 field results and we apply last() function on those results.

Expected behavior:
SELECT last(*) FROM (SELECT mean("usage_nice"), mean("usage_iowait") FROM "telegraf"."autogen"."cpu" GROUP BY time(2m))
It should return 2 column of field results cpu.last_mean and cpu.last_mean_1 .

Actual behavior:
SELECT last(*) FROM (SELECT mean("usage_nice"), mean("usage_iowait") FROM "telegraf"."autogen"."cpu" GROUP BY time(2m))
It only returns one field result cpu.last_mean .

Environment info:

  • InfluxDB version: v1.8.5

Temporary Workaround:
I think some default alias mechanism for subquery goes wrong.

Currently if we force to make alias for the subquery fields manually, then this issue is gone:

Try:

SELECT last(*) FROM (SELECT mean("usage_nice") AS "mean", mean("usage_iowait") AS "mean_1" FROM "telegraf"."autogen"."cpu" GROUP BY time(2m))

and you will see the last() function could detect all the fields from subquery. It will return cpu.last_mean and cpu.last_mean_1 .

Hello @triplefirecoder,
Can you please submit an issue?

Thank you.