Top Banner
Daniel.hu [email protected]
12
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 2: Something About Mysql Database Index

HASH vs B+ Tree Cluster Index vs No Cluster Index INNODB vs MYISAM

Page 3: Something About Mysql Database Index

Insert performance Batch INSERT and REPLACE Use LOAD DATA instead of INSERT Other tricks

Forbidden Foreign keyForbidden IndexRebuild Index

Page 4: Something About Mysql Database Index

Do you always need index on WHERE column

Does the order of columns in an index matter IN vs OR

Page 5: Something About Mysql Database Index

IN vs OR

large IN clauses are problematic

Page 6: Something About Mysql Database Index

Explain

Page 7: Something About Mysql Database Index

Make sure you strike a good balance for indexing Too many adversely affects data input Too few adversely affects reads

Order of columns in an index matters! Covering indexes are the fastest query possible

Page 8: Something About Mysql Database Index

Consider the impact of duplicate rows Avoid SELECT DISTINCT if it doesn’t cause a

problem Use UNION ALL instead of UNION if duplicate

rows are acceptable Use foreign key as index or create independent

index Despite what you see in examples, avoid

SELECT *

Page 9: Something About Mysql Database Index

Operators in the WHERE clause make a big difference Avoid <> and LIKE Use EXISTS, NOT EXISTS, and LEFT JOINS instead

of NOT IN If you must use LIKE, make the first character a

literal

Page 10: Something About Mysql Database Index

Don’t use ORDER BY unless you really need it Don’t use Count(…) where to protect data

integeration Don't use ORDER BY RAND() when data is

huge

Page 11: Something About Mysql Database Index

http://dev.mysql.com/doc/refman/5.1/zh/optimization.html#insert-speed http://www.xaprb.com/blog/2006/07/04/how-to-exploit-mysql-index-optimizations/ http://www.informit.com/articles/article.aspx?p=377652

Page 12: Something About Mysql Database Index

Thank you!