I have a query that is on the opening page of our application that takes about 8-10 seconds to load. I've tried all I can to optimize it and I simply cannot make it go any faster (indexed appropriately, rewriting redundant code, ridding it of view-ception hell it lived in). It's a query on our largest table with a bunch of joins to other tables that have a many to one relationship to the main (many in the smaller relate to one id in the largest) and requires an unavoidable group by largeTable.id that makes it so slow.
Now I do have to make this work faster one way or another. I think this may be an appropriate situation to have a data warehouse (I hope that's the right term) type table. I would insert into this warehouse table the results of the slow query and then query from the warehouse table directly. Then, anytime something in my application that affects a table that affects the data from the slow query/data warehouse table, I would drop the rows in the table and recreate it which would then take slightly longer than the initial query, but only happen a few times a day, whereas the rest of the day I am querying directly from my data warehouse table much faster.
Is this a reasonable solution? Are there any common pitfalls or things I need to watch out for with this methodology, or a better way to do it? After a few days of trying to just optimize the query, I need some work around. I am still relatively new to this and am open to suggestions.