something about mysql database index

12
Daniel.hu [email protected]

Upload: dearhwj

Post on 17-Jul-2015

1.459 views

Category:

Technology


3 download

TRANSCRIPT

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

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

Forbidden Foreign keyForbidden IndexRebuild Index

Do you always need index on WHERE column

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

IN vs OR

large IN clauses are problematic

Explain

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

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 *

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

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

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

Thank you!