New changes on – fixed calculations of exclusive times

When you see plan on, one of the columns visible is exclusive.

In principle it's simple – take time of current node, subtract times of all sub nodes, and you get how much time was spent in this node alone.

Reality is not that simple. Two things especially make the calculations complicated. CTEs, and InitPlans.

Now, with the just pushed change to Pg::Explain (plan parsing library), and site itself, some of the bad calculations are gone.

Let's see some examples:

Let's start with CTE.

One specific plan was displayed by previous code like this:

Now, it looks like this:

Note that exclusive in line 7 dropped by a lot. What's more – sum of exclusive times is no longer greater than total runtime.

With InitPlans it looked like this:

Now, it looks like this:

There are more things to notice in here:

  • top level node, line 1 – exclusive time is now actually there. Previously displayed 0 was simply error in calculations.
  • line 7 – correctly reduced exclusive time, because this node used InitPlan from line 3, so it's time should be subtracted.
  • In line 2 please note that you can now see more information, including what this InitPlan returned.