That reduced the time to 178 milliseconds which is quite a nice improvement for so little effort. As I understand it, this is down to the traversal matcher handling smaller patterns more effectively than it handles longer patterns.

The next step was to move the WHERE clause up so that it filtered out rows right at the beginning of the query rather than letting them hang around for another 3 MATCH statements:

I expected it to be a bit slower since we were now keeping around more games than necessary again and as expected the time rose to 172 milliseconds – slightly quicker than our first attempt at tweaking.

I reverted that change and realised that there would be a lot of ‘stats’ nodes which didn’t have any goals associated with them and would therefore have a ‘goals’ property value of 0. I tried filtering those nodes out before the ‘SUM’ part of the query: