Tip 1 comparison operators use "=" would not "<>"
"=" To increase the chance of using the index.
"LIMIT 1" to avoid full table scan to find the corresponding results of the scan will not continue.
Tips 3 column select the appropriate data type
TINYINT SMALLINT do not use, do not use SMALLINT INT, you know the truth, disk and memory consumption as small as possible thing.
Tips 4 large DELETE, UPDATE or INSERT query becomes more small queries
You can write a few lines, hundreds of lines of SQL statements are not forced to appear very high grid? However, in order to achieve better performance and better data control, you can turn them into multiple small queries.
5 instead of using techniques UNION ALL UNION, allowing repeat if the result set it
UNION ALL because not re efficient than UNION.
Tip 6 multiple times to get the same result set, please keep the SQL statement is consistent
The aim is to make full use of the query cache.
For example, according to the geographical and product id Product Pricing, for the first time we used:
Then the same query a second time, please keep the consistency of the above statements, such statements do not where inside the id and the region position reverse the order.
7 Tips to avoid using "the SELECT * "
If you do not query all the columns in the table, try to avoid using SELECT *, because it will be a full table scan, can not effectively use the index, increasing the burden on the database server, and network IO overhead between it and the application client.
Clause inside the column tips 8 WHERE try to be indexed
Just "try" Oh, not to say that all of the columns. Local conditions, adjusted according to actual situation, because sometimes too many indexes will decrease performance.
Tips 9 JOIN clause inside the column is indexed as much as possible
Also just "try" Oh, not to say that all of the columns.
Tips 10 ORDER BY column is indexed as much as possible
If the ORDER BY column is indexed, the performance will be better.
11 tips to use LIMIT implement paging logic
Not only improve performance, while reducing unnecessary network traffic between the database and application.
12 Tips Use the keyword EXPLAIN to view an execution plan
EXPLAIN can check the index usage and scanning lines.
other