# Aggregation with window so slowly

**URL:** https://community.influxdata.com/t/aggregation-with-window-so-slowly/25464
**Category:** InfluxDB 2
**Tags:** flux
**Created:** [June 18, 2022, 12:56am UTC](https://community.influxdata.com/t/aggregation-with-window-so-slowly/25464 "2022-06-18T00:56:40Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Yuchun\_Wang](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/yuchun_wang/32/10379_2.png) [@Yuchun\_Wang](https://community.influxdata.com/u/Yuchun_Wang)
#### Post date: [June 18, 2022, 12:56am UTC](https://community.influxdata.com/t/aggregation-with-window-so-slowly/25464/1 "2022-06-18T00:56:40Z")

</div>

Q = from(bucket:“timeseries”)  
|\> range(start: 2021-01-01T00:00:01.000Z, stop: 2021-07-18T21:11:52.999Z)  
QVmax = Q  
|\> aggregateWindow(every: 20s480ms, fn:max )  
QVmin = Q  
|\> aggregateWindow(every: 20s480ms, fn:min )  
QTmin = Q  
|\> aggregateWindow(every: 20s480ms, fn:first )  
QTmax = Q  
|\> aggregateWindow(every: 20s480ms, fn:last )  
union(tables: [QVmax,QVmin,QTmin,QTmax])

my server with 256G memeory and 64 core cpu. this bucket has 2m points.I want to know if there is any good way to optimize it.

from(bucket:“timeseries”)  
|\> range(start: 2021-01-01T00:00:01.000Z, stop: 2021-07-18T21:11:52.999Z)

The second question is that it takes 4 seconds to run the above query, is this normal?

---

<div class="post-metadata">

### Author: ![Anaisdg](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/anaisdg/32/6401_2.png) [@Anaisdg](https://community.influxdata.com/u/Anaisdg)
#### Post date: [June 21, 2022, 4:26pm UTC](https://community.influxdata.com/t/aggregation-with-window-so-slowly/25464/2 "2022-06-21T16:26:22Z")

</div>

Hello @Yuchun_Wang,  
Why do you need to union the tables?  
Perhaps you can skip this?

```auto
Q = from(bucket:“timeseries”)
|> range(start: 2021-01-01T00:00:01.000Z, stop: 2021-07-18T21:11:52.999Z)
QVmax = Q
|> aggregateWindow(every: 20s480ms, fn:max )
|> yield(name: "1")
QVmin = Q
|> aggregateWindow(every: 20s480ms, fn:min )
|> yield(name: "2")
QTmin = Q
|> aggregateWindow(every: 20s480ms, fn:first )
|> yield(name: "3")
QTmax = Q
|> aggregateWindow(every: 20s480ms, fn:last )
|> yield(name: "4")

```

Also the from |\> range |\> filter |\> aggwindow is a pusdown pattern its _possible_ that this is more efficient but i haven’t tested it:

```auto
 from(bucket:“timeseries”)
|> range(start: 2021-01-01T00:00:01.000Z, stop: 2021-07-18T21:11:52.999Z)
|> aggregateWindow(every: 20s480ms, fn:max )
|> yield(name: "1")

 from(bucket:“timeseries”)
|> range(start: 2021-01-01T00:00:01.000Z, stop: 2021-07-18T21:11:52.999Z)
|> aggregateWindow(every: 20s480ms, fn:min )
|> yield(name: "2")

 from(bucket:“timeseries”)
|> range(start: 2021-01-01T00:00:01.000Z, stop: 2021-07-18T21:11:52.999Z)
|> aggregateWindow(every: 20s480ms, fn:first )
|> yield(name: "3")

 from(bucket:“timeseries”)
|> range(start: 2021-01-01T00:00:01.000Z, stop: 2021-07-18T21:11:52.999Z)
|> aggregateWindow(every: 20s480ms, fn:last )
|> yield(name: "4")

```
