Well optimization is a skill of a DBA A tool can not optimize any database like a DBA. It involves database normalization, rearranging schemas, proper use of WHERE and JOIN clauses etc. normalization to 3rd form is the best practice. SPs are normally faster than queries hence its better to arrange queries in SPs.
Use a persistent layer in your programming architecture. You can find tons of Free and Open Source Software in the Internet...