Closed marco44 closed 1 year ago
Nice idea. While looking at it, I was thinking that for the part were we use the metadata rather than unnesting a whole record, we could use exclusive bounds (:from, :to, '()'
) rather than inclusive bounds, as we will already fully unnest those? Shouldn't make much a difference but still a slight win.
Yeah exclusive bounds should work too
I forgot to update this issue. This has been committed as of https://github.com/powa-team/powa-web/commit/be95314e1a008007679e866238217dfd71ef1eea and released in the latest version 4.1.4, so marking this issue as closed.
FTR I kept the bounds inclusive for now to keep things simple as it can only lead to sorting 4 extra rows, which isn't much. We could later change that, after triple checking that this is indeed correct, if needed.
This family of queries run when we're on a "per database" overview. They're trying to figure out min/max of counters for each query, for wait events… and they can be slow. It's the case for me, as the VM that runs powa is quite small, and has very little IO. So any sort on disk is very slow.
So let's take this query as an example (extracted from my server log):
Values have no importance, just note that it's one day of data, and it already takes a long time. The problem is that we have to sort all those records (and everything attached to them) to perform the group by in the end. Which results in a big sort, with lots of data written on disk.
This query is made of 2 parts: one that unnests all records on the interval from powa_wait_sampling_history, and one that gets the records from powa_wait_sampling_history_current. All of this is then unioned and then we take max/min for the whole dataset.
This can, I think, be optimized this way:
So here's a rewrite proposal: