I agree with everything that is said here, and I would like to add: make sure your SQL is well encapsulated, so when you find that you need to optimize, there is only one place you need to change, and the change will be transparent to any code that calls it.
Personally, I like to encapsulate all my SQL in PL / SQL procedures, but there are some that disagree with this. No matter what you do, I recommend that you do not try to put your SQL "inline" in different source code. It seems that this always leads to cutting and pasting and quickly becomes difficult to maintain. Put your SQL in another place and try to use it as much as possible.
Also, read indexes, how they really work, and when you should and shouldn't use them. For many people, the first instinct when they receive a slow query is to index the table to death. This may solve the problem in the short term, but a long-term table with a large index will be slow to insert and update. A few well-chosen indexes are much better than indexing each field. Try reading Refactoring SQL Applications by Stefan Farout.
Finally, as stated above, a properly normalized database design will help to avoid 99% of your slow queries. Sometimes denormalization occurs, but it is important that you know the rules before breaking them.
Good luck
source share