oracle database経験者が mysqlの設計思想を知っていろいろ考える

33
1 Oracle Database⤒㦂⪅䛜 MySQL䛾タィᛮ䜢▱䛳䛶䛔䜝䛔䜝⪃䛘䜛 (බ㛤∧) Oracle OpenWorld Unconference presented by JPOUG 2012/04/06 ᖹሯ ㈆ኵ

Upload: trandien

Post on 28-Jan-2017

263 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Oracle Database経験者が MySQLの設計思想を知っていろいろ考える

1

Oracle Database

MySQL

( )

Oracle OpenWorld Unconference presented by JPOUG

2012/04/06

Page 2: Oracle Database経験者が MySQLの設計思想を知っていろいろ考える

2

• DB Oracle MySQL

– RDBMS

– Oracle MySQL 8 2

• Twitter @sh2nd

• id:sh2

Page 3: Oracle Database経験者が MySQLの設計思想を知っていろいろ考える

3

• Oracle Database MySQL

• Oracle Database MySQL …

• MySQL Oracle Database …

Page 4: Oracle Database経験者が MySQLの設計思想を知っていろいろ考える

4

MySQL

Page 5: Oracle Database経験者が MySQLの設計思想を知っていろいろ考える

5

MySQL

• 2001/01 MySQL 3.23RHEL 2.1/3

• 2003/03 MySQL 4.0UNION

• 2004/10 MySQL 4.14.1.12 Windows Shift_JIS

(Microsoft Code Page 932) RHEL 4

• 2005/10 MySQL 5.0RHEL 5

• 2008/11 MySQL 5.1

RHEL 6

• 2010/12 MySQL 5.54 UTF-8

InnoDB

Page 6: Oracle Database経験者が MySQLの設計思想を知っていろいろ考える

6

Oracle Database

• Oracle 7 8

11.1

1980 1990 2000 2010

3.23

2

4.0 4.1 5.0 5.1 5.5

3 4 5 6 7 8.0 8.1 9.1 9.2 10.2 11.2

• Oracle Database

3

4

5

6

7 CBO

8.0

8.1 Statspack

9.1 AL32UTF8

9.2 SYSTEM

10.1 RBO AWR

10.2

11.1

11.2

10.1

• MySQL

4.0 UNION

4.1

5.0

5.1

5.5 4 UTF-8

Page 7: Oracle Database経験者が MySQLの設計思想を知っていろいろ考える

7

Page 8: Oracle Database経験者が MySQLの設計思想を知っていろいろ考える

8

• OLTP SQL

• SQL

SQL

• ORA-4031

• Java PreparedStatement

■preparedStatement = connection.prepareStatement("SELECT c FROM sbtest WHERE id = ?");preparedStatement.setInt(1, getRandomId()); // resultSet = preparedStatement.executeQuery();

■statement = connection.createStatement();resultSet = statement.executeQuery("SELECT c FROM sbtest WHERE id = " + getRandomId());

Page 9: Oracle Database経験者が MySQLの設計思想を知っていろいろ考える

9

SQL

• Oracle Database SQL

• Oracle Database SQL

Soft

Parse

Hard

Parse

Execute

Cursor

CacheParse

Cursor Cache Hit

Library Cache Hit

SGA

Miss Miss

SQL

Page 10: Oracle Database経験者が MySQLの設計思想を知っていろいろ考える

10

• SQL

SQL

Hard Parse

Soft

Parse

Hard

Parse

Execute

Cursor

CacheParse

Cursor Cache Hit

Library Cache Hit

SGA

Miss Miss

■Load Profile (Per Second)Parses: 2,131.6Hard parses: 2,089.32,089.32,089.32,089.3

■Instance Efficiency PercentagesLibrary Hit %: 43.30 Soft Parse %: 1.981.981.981.98Execute to Parse %: 0.15 Latch Hit %: 98.95Parse CPU to Parse Elapsd %: 48.35 % Non-Parse CPU: 35.32

Page 11: Oracle Database経験者が MySQLの設計思想を知っていろいろ考える

11

• SQL

SQL Soft Parse

Soft

Parse

Hard

Parse

Execute

Cursor

CacheParse

Cursor Cache Hit

Library Cache Hit

SGA

Miss Miss

■Load Profile (Per Second)Parses: 6,350.8Hard parses: 0.10.10.10.1

■Instance Efficiency PercentagesLibrary Hit %: 100.00 Soft Parse %: 100.00100.00100.00100.00Execute to Parse %: 0.01 Latch Hit %: 99.94Parse CPU to Parse Elapsd %: 82.69 % Non-Parse CPU: 93.37

Page 12: Oracle Database経験者が MySQLの設計思想を知っていろいろ考える

12

PreparedStatement

• PreparedStatement

SQL

Soft

Parse

Hard

Parse

Execute

Cursor

CacheParse

Cursor Cache Hit

Library Cache Hit

SGA

Miss Miss

■Load Profile (Per Second)Parses: 11.011.011.011.0Hard parses: 0.4

■Instance Efficiency PercentagesLibrary Hit %: 99.96 Soft Parse %: 96.49Execute to Parse %: 99.8599.8599.8599.85 Latch Hit %: 99.93Parse CPU to Parse Elapsd %: 35.40 % Non-Parse CPU: 99.96

Page 13: Oracle Database経験者が MySQLの設計思想を知っていろいろ考える

13

Page 14: Oracle Database経験者が MySQLの設計思想を知っていろいろ考える

14

• SysBench OLTP Java

– Oracle Database MySQL

– (Apache Commons DBCP)

– PreparedStatement

– Scientific Linux 6.2 64bit KVM CentOS 5.7 64bit

– Core i5-2400S (Quad-Core 2.50GHz) 2

– Oracle Database 11g R2 SGA_TARGET = 4G

– MySQL 5.5.22 innodb_buffer_pool_size = 1024M

– C

– B

– P PreparedStatement

Page 15: Oracle Database経験者が MySQLの設計思想を知っていろいろ考える

15

Oracle Database

( )

Page 16: Oracle Database経験者が MySQLの設計思想を知っていろいろ考える

16

Oracle Database

( )

Page 17: Oracle Database経験者が MySQLの設計思想を知っていろいろ考える

17

Oracle Database

• ※1 SESSION_CACHED_CURSORS = 50

PGA CB-

CBP

SESSION_CACHED_CURSORS 11g R1 50

0

• ※2 CURSOR_SHARING = FORCE

SQL Hard Parse

CB-

FORCE

• ※3

Oracle Database

• ※3 11g R1

(Java )

Page 18: Oracle Database経験者が MySQLの設計思想を知っていろいろ考える

18

MySQL

SysBench OLTP tps (read-only, 1M recs, uniform)

0.0 100.0 200.0 300.0 400.0 500.0 600.0 700.0 800.0

CBP

CB-

C--

-B-

--- MySQL

Page 19: Oracle Database経験者が MySQLの設計思想を知っていろいろ考える

19

MySQL

• PreparedStatement

Page 20: Oracle Database経験者が MySQLの設計思想を知っていろいろ考える

20

Page 21: Oracle Database経験者が MySQLの設計思想を知っていろいろ考える

21

Client-Side PreparedStatement

• MySQL JDBC

Client-Side PreparedStatement

• MySQL JDBC

SQL

Client

Program

JDBC

Driver

Database

Server

Client

Program

JDBC

Driver

MySQL

Server

prepare prepareSELECT * FROM t WHERE id = ?

execute executeparam1 = 100

prepare

execute executeSELECT * FROM t WHERE id = 100

RDBMS

MySQL

Page 22: Oracle Database経験者が MySQLの設計思想を知っていろいろ考える

22

SQL

• MySQL SQL

SQL

• NESTED LOOPS JOIN

MERGE JOIN HASH JOIN

MySQL 5.6 Batched Key Access MERGE JOIN

MariaDB

5.3 HASH JOIN

•Oracle Database MySQL

MySQL 5.6 Table Pullout

Oracle Database

SELECT * FROM sales WHERE cust_id IN (SELECT cust_id FROM customers);

⇒ MySQL sales 1 customer

⇒ Oracle DatabaseSELECT sales.* FROM sales s INNER JOIN customers c ON s.cust_id = c.cust_id;

Page 23: Oracle Database経験者が MySQLの設計思想を知っていろいろ考える

23

Server-Side PreparedStatement

• MySQL MySQL

4.1 JDBC

useServerPrepStmts true

• MySQL SQL SQL

SQL

MySQL 2

• SQL

MySQL Oracle Database

MySQL

RDBMS

MySQL

Parse

Parse

Execute&Fetch

Execute&Fetch

SQL

SQL

Page 24: Oracle Database経験者が MySQLの設計思想を知っていろいろ考える

24

MySQL Server-Side PreparedStatement

• PreparedStatement

SysBench OLTP tps (read-only, 1M recs, uniform)

0.0 100.0 200.0 300.0 400.0 500.0 600.0 700.0 800.0

CBP

CB-

C--

-B-

---MySQL

MySQL Server-Side

Page 25: Oracle Database経験者が MySQLの設計思想を知っていろいろ考える

25

• MySQL(InnoDB)

– Oracle Database

– IBM DB2

– Microsoft SQL Server

– PostgreSQL

– MySQL(InnoDB)

• INDEX UNIQUE SCAN INDEX RANGE

SCAN

• SysBench OLTP

SELECT c FROM sbtest WHERE id = ?SELECT c FROM sbtest WHERE id BETWEEN ? AND ?SELECT SUM(k) FROM sbtest WHERE id BETWEEN ? AND ?SELECT c FROM sbtest WHERE id BETWEEN ? AND ? ORDER BY cSELECT DISTINCT c FROM sbtest WHERE id BETWEEN ? AND ? ORDER BY c

Page 26: Oracle Database経験者が MySQLの設計思想を知っていろいろ考える

26

Oracle

( )

Page 27: Oracle Database経験者が MySQLの設計思想を知っていろいろ考える

27

• MySQL

MySQL Oracle Database

• Oracle Database

–Apache prefork

–7 SQL

11g R1

• MySQL

Page 28: Oracle Database経験者が MySQLの設計思想を知っていろいろ考える

28

Oracle

( )

Page 29: Oracle Database経験者が MySQLの設計思想を知っていろいろ考える

29

Page 30: Oracle Database経験者が MySQLの設計思想を知っていろいろ考える

30

• Oracle Database

• MySQL

– DB

Page 31: Oracle Database経験者が MySQLの設計思想を知っていろいろ考える

31

• MySQL Oracle Database 15

Oracle 8i

• OLTP MySQL Oracle

Database

Exadata Business

Intelligence Data Warehouse

• DB …

Page 32: Oracle Database経験者が MySQLの設計思想を知っていろいろ考える

32

• SysBench: a system performance benchmark

http://sysbench.sourceforge.net/

• IT Web (11)

JDBC PreparedStatement

http://www.atmarkit.co.jp/fjava/rensai2/webopt11/webopt11.html

Page 33: Oracle Database経験者が MySQLの設計思想を知っていろいろ考える

33

1.

2. PostgreSQL

3. Oracle Database

4. MySQL