Optimize APEL summaries performance (Fixes BUGZ-3893)
This code change significantly improves the APEL summary query performance without altering the schema. On my mide-side database it manage to reduce the query time from 10 minutes to 2 seconds!
Problem in short:
the APEL summary query requires grouping by benchmark. The benchmark is in the extra attributes table according to our schema, so JOIN is needed. JOIN as it is harms performance more and more when the database grows in size and especially affects sites that have large amount of jobs.
Changes in this MR:
as APEL summary query aggregates the last 2 month only, we can select a subset of data from extra table as well. In the proposed approach the JOIN will be done with a subquery result instead of full extra attributes table. The subquery selects the data from records id range (defined by one more very fast query). This results in a significantly smaller JOIN that runs much faster.