mysql performance

45
MySQL performance Xhark 김김김

Upload: aran

Post on 29-Jan-2016

87 views

Category:

Documents


8 download

DESCRIPTION

MySQL performance. Xhark 김재홍. MySQL 이란 ?. MySQL is a database management system. 어떻게 ? => 저장한다. 왜 MySQL performance 를 ?. 컴퓨터가 동작하는 데에 시간이 많이 드는 부분 ? 1. 데이터처리 ( 프로그램 동작 ) 2. 입력과 출력 3. 네트워크 4. etc…. Database!. MySQL 이란 ?. 어떻게 ? MyISAM InnoDB Arara 에서는 InnoDB 를 사용 …. - PowerPoint PPT Presentation

TRANSCRIPT

MySQL

MySQL performanceXhark

MySQL?MySQL is a database management system.

?

=> .MySQL ?

MySQL database management system, database . .

database management system , MySQL Open source database management system .2 MySQL performance? ?

1. ( )2. 3.

4. etc

Database!3MySQL??

MyISAMInnoDB

Arara InnoDB MySQL .

?

, MySQL .MyISAM / InnoDB4MySQL Database TableMySQL Database Table .5MySQL Table Column, Row, IndexetcIndex!

Index = PRIMARY KEY, UNIQUE, INDEX, and FULLTEXT

Why use index?MySQL Table .

Table Column Row Index .

Index.

6MySQL Index Index !

Index , .

Index ?=>

7Index For example:CREATE TABLE test ( id INT NOT NULL, last_name CHAR(30) NOT NULL, first_name CHAR(30) NOT NULL, PRIMARY KEY (id), INDEX name (last_name,first_name)); Column Index , MySQL Column Index .

Multiple-Column-Index !

For ExampleTable UsersColumns : id/username/password/nickname/emailIndex:

id(PrimaryKey. auto_increment), username(UniqueKey), email(UniqueKey)

1. SELECT * from Users where username=NAME2. SELECT * from Users where nickname=NICKUsername index B-tree Row ! Good! Nickname index ? , nickname Key .

For Example2Table Article_vote_statusColumns : id/user_id/board_id/article_idIndex:

id(PrimaryKey. auto_increment), user_id(Key), board_id(Key), article_id(Key)

SELECT * from article_vote_status where user_id=UID and board_id=BID and article_id=AIDuser_id UID row, board_id BID row, article_id AID row !

, !?Multiple-Column-Index !

(user_id, board_id, article_id) Key , !

?Example1 Example2 . Time-critic .

?Database , Tree .

DS B-tree !

?Index Tree , (log time) Index !

Tree ?

storage engine1. MyISAM

2. InnoDB

.

MyISAMSun MicrosystemsGNU General Public License

MyISAM Sun Mircosystems , GPL.17MyISAMInnoDB . , InnoDB .

.

BUT, .MyISAMMyISAM transaction .

=>

Transaction , .19MyISAM ???

R-trees4.1 (for the MyISAM storage engine)(R:rectangle)20

Simple example of an R-tree for 2D rectangles21

Visualization of an R*-tree for 3D cubes using ELKI22Similar to B-trees (by wiki)MyISAM Data .Data file(.MYD) Index file(.MYI) .

, Index Tree .

Index ?=> Tree .

MyISAM Performance(INSERT)

Connecting: (3)Sending query to server: (2)Parsing query: (2)Inserting row: (1 size of row)Inserting indexes: (1 number of indexes) * log NClosing: (1)

MyISAM Performance(DELETE)

The time required to delete individual rows is exactly proportional to the number of indexesMyISAM Performance(UPDATE)

SELECT query with the additional overhead of a write.

-> SELECT , Index Tree .MyISAM Performance(SELECT)

row ? log(row_count) / log(index_block_length / 3 * 2 / (index_length + data_pointer_length)) + 1.

Block ... Row ?

MyISAM Performance(SELECT)

To eliminate rows from consideration. If there is a choice between multiple indexes, MySQL normally uses the index that finds the smallest number of rows

InnoDBOracle CorporationGNU General Public License or proprietaryInnoDB Oracle Coporation , GPL proprietary .

30InnoDB .

.

Transaction .

InnoDBInnoDB , Transaction .

, .

Database query , . InnoDB MyISAM .InnoDBMyISAM .

? -> 1. B-tree .2. Transaction .3. 2 .4. . (MyISAM OS )

6. InnoDB . 5. Locking .

InnoDB : Row-level Locking

MyISAM : Table-level Locking

-> MyISAM , Table Thread ? InnoDB !InnoDBINFORMATION_SCHEMA

. Reference

InnoDB ???

TableSpace !

PDF Cache ?

.

!Select * from t1SELECT * from t1

. SELECT ! , .

?

SELECT Removal of unnecessary parentheses:((a AND b) AND c OR (((a AND b) AND (c AND d)))) -> (a AND b AND c) OR (a AND b AND c AND d)Constant folding:(a b>5 AND b=c AND a=5Constant condition removal (needed because of constant folding):(B>=5 AND B=5) OR (B=6 AND 5=5) OR (B=7 AND 5=6) -> B=5 OR B=6SELECT SELECT COUNT(*) FROM tbl_name;SELECT MIN(key_part1),MAX(key_part1) FROM tbl_name;SELECT MAX(key_part2) FROM tbl_name WHERE key_part1=constant;SELECT ... FROM tbl_name ORDER BY key_part1,key_part2,... LIMIT 10;SELECT ... FROM tbl_name ORDER BY key_part1 DESC, key_part2 DESC, ... LIMIT 10; 39SELECT SELECT key_part1,key_part2 FROM tbl_name WHERE key_part1=val;SELECT COUNT(*) FROM tbl_name WHERE key_part1=val1 AND key_part2=val2;SELECT key_part2 FROM tbl_name GROUP BY key_part1;SELECT ... FROM tbl_name ORDER BY key_part1,key_part2,... ;SELECT ... FROM tbl_name ORDER BY key_part1 DESC, key_part2 DESC, ... ; 40SQLAlchemySQLAlchemy ? Query .Example)Qeury.session().filter_by(A).all();SQLAlchemy Arara ?# XXX: . .article_list = session.query(model.Article).filter_by(root_id=None).order_by(model.Article.id.desc())[offset:last].Referencehttp://dev.mysql.com/doc/refman/5.0/en/http://en.wikipedia.org/wiki/R-treehttp://www.innodb.com/doc/