It's a complex PR/topic and don't understand all the code / hard to review so focused on looking at tests. Ran the system tests for most premium features and they seem to pass. Also checked custom reports generates similar queries that still work (some SQLs changed but are still valid). As nothing seems to break I reckon it's good to merge (in 3.8).
I'll also go through the code and try to make it more expressive.