Flux: Poor performance of `union()` and `yield()`

Why is it that tables A and B can run in under 50ms, but union(tables: [A, B]) runs for 10+ seconds… around 200 times slower?

Here’s an example:

finalInterval = 1h
data = from(bucket: "foo")
	|> range(start: 2021-08-31T14:26:00Z, stop: 2021-09-02T06:33:00Z)
	|> filter(fn: (r) =>
		r._measurement == "data" and
		r._field == "value"
	)
sum = data
    |> aggregateWindow(every: finalInterval, createEmpty: false, fn: sum)
    |> keep(columns: ["deviceID", "type", "_time", "_value"])
    |> set(key: "_field", value: "sum")
max = data
    |> aggregateWindow(every: finalInterval, createEmpty: false, fn: max)
    |> keep(columns: ["deviceID", "type", "_time", "_value"])
    |> set(key: "_field", value: "max")
union(tables: [sum, max])

Tables sum and max individually run in under 50ms; whereas, the query above runs for over 13 seconds. Performance with similar Influx 1.x SQL query was under 100ms, as well.

Running latest InfluxDB 2.0.8 (git: e91d41810f) build_date: 2021-08-13T18:22:30Z on Linux x64.