SQL Guide : Tuning performance with SQL : Tuning SQL statements and applications
  
Tuning SQL statements and applications
Tuning the SQL statements, especially in applications where complex queries are involved, is generally the most efficient means of improving the database performance.
Be sure to tune your application before tuning the RDBMS because:
during application design you have control over the SQL statements and data to be processed
you can improve performance even if you are unfamiliar with the internal working of the RDBMS you are going to use
if your application is not tuned well, it will not run well even on a well-tuned RDBMS
You should know what data your application processes, what are the SQL statements used, and what operations the application performs on the data. For example, you can improve query performance when you keep SELECT statements simple, avoiding unnecessary clauses and predicates.
See also
Evaluating application performance
Using stored procedure language
Executing prepared statements (prepare once, execute many)
Tuning performance with SQL