For building faster SQL queries, follow these hints.
- 1. Use Smaller batches
Always try to delete data or update data in smaller batches. If you try to delete thousands of records in one go, it will impact performance. If you try to update large batches of data in one go, it will also negatively impact performance and speed. Break these up in smaller chunks.
- Stop being trigger-happy!
By using triggers, you may end up locking more than one table at the same time, until the trigger has completed its work. Sometimes a trigger is unavoidable, but only sometimes. Rather, try to split the logic so that only limited resources are locked at a given time.
- Avoid nesting views
As the name implies, nested views are views inside existing views. The more nested a view becomes, the more data has to be returned for a single query and this can really cause your whole database to lag quite quickly. Do not nest views.