oracle database経験者が mysqlの設計思想を知っていろいろ考える
Post on 28-Jan-2017
292 Views
Preview:
TRANSCRIPT
1
Oracle Database
MySQL
( )
Oracle OpenWorld Unconference presented by JPOUG
2012/04/06
2
• DB Oracle MySQL
– RDBMS
– Oracle MySQL 8 2
• Twitter @sh2nd
• id:sh2
•
3
• Oracle Database MySQL
• Oracle Database MySQL …
• MySQL Oracle Database …
4
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
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
7
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());
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
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
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
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
13
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
15
Oracle Database
•
( )
16
Oracle Database
•
( )
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 )
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
19
MySQL
• PreparedStatement
•
•
20
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
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;
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
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
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
26
Oracle
•
( )
27
• MySQL
MySQL Oracle Database
…
• Oracle Database
–Apache prefork
–7 SQL
11g R1
• MySQL
–
–
–
28
Oracle
•
( )
29
30
• Oracle Database
–
–
–
• MySQL
– DB
–
–
31
• MySQL Oracle Database 15
Oracle 8i
• OLTP MySQL Oracle
Database
Exadata Business
Intelligence Data Warehouse
• DB …
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
33
1.
2. PostgreSQL
3. Oracle Database
4. MySQL
top related