Query Optimization
The biggest speed-ups can be seen by reprogramming your SQL statements so they are more efficient. If you follow these tips, your server will thank you:
• Select as little data as possible. Rather than SELECT *, select only the fields you need.
• If you need only a few rows, use LIMIT to select the number you need.
• Declare fields as NOT NULL when creating tables to save space and increase speed.
• Provide default values for fields and use them where you can.
• Be very careful with table joins because they are the easiest way to write inefficient queries.
• If you must use joins, be sure you join on fields that are indexed. They should also preferably be integer fields because these are faster than strings for comparisons. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access