I have a strong feeling that you are swimming upstream here and the DB you are using simply does not have enough resources to run Discourse.
- What are the exact specs of the metal (CPU / Hard drive make and model) ?
- What is the exact spec of the VM ?
These queries are indeed expensive, but we host plenty large forums (eg: About - Straight Dope Message Board 22 million posts) and we are able to run all these queries just fine on that instance.