I have never used a plugin to automatically optimize the database and have only optimized DB’s semi-manually with the Adminer plugin: https://wordpress.org/plugins/adminer/ so I can’t offer any automated plugin suggestions. With the Adminer plugin I use the Optimize button which is a standard/general MySQL optimize command. For each site type I run specific SQL Queries in the Adminer SQL Query window to do cleanup on each of the site types. The Queries I run on this BuddyPress/bbPress site are different than the Queries I run on other sites. You have to know a bit about what you are doing and the Queries are not one size fits all so it would not do you any good if I posted the Queries I use here.