Flux query extremely slow compard to influxql

Hi all,
i have the same query doing a simple aggregation of values per month.
I did the same query in flux and in influxdb (influxql has the issue that i monthly aggregations are not always on the 1st but the date shifts - this is another topic anot for here - thats why i did it on flux).
The 2 queries run on the same grafana instance against the same influxdb, so the infrastructure shold not play any role.
The problem:

  • runtime of influx db: fast and ok
  • flux: 30s

The influxql:
SELECT difference(max(“kwH”)) FROM “autogen”.“Stromzaehler_Total” WHERE (“location”::tag = ‘wp_total_in’) AND $timeFilter GROUP BY time($__interval) fill(none)

$__interval is set in query_options to 730h (as month diesnt exist as unit???)

The flux: from(bucket: “isg/autogen”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r._measurement == “Stromzaehler_Total” and r.location == “wp_total_in”)
|> aggregateWindow (every: 1mo, fn: max)
|> difference()

Any advise would be nice.
Jürgen

from(bucket: "isg/autogen")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r._measurement == "Stromzaehler_Total" and r.location == "wp_total_in")
|> aggregateWindow (every: 1mo, fn: max)
|> difference()

What are the field names you have in your data? I do not see any filters for any fields, so that is probably making it slow. You have the measurement (not the same as a field) and a tag called “location” but no fields. Perhaps you have a field called kwH? If yes, then add that field filter and see what happens.

Also, I like to build my Flux queries in Influx Data Explorer, then one I have it working as it should, copy & paste into Grafana.