Last active
December 17, 2015 18:19
-
-
Save kwon37xi/5652026 to your computer and use it in GitHub Desktop.
Real MySQL http://www.aladin.co.kr/shop/wproduct.aspx?ISBN=8992939000 책의 455 쪽 Delayed Join 이 정말로 성능이 좋아지는지 테스트하는 코드.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@GrabConfig(systemClassLoader=true) | |
@Grab(group='mysql', module='mysql-connector-java', version='5.1.25') | |
import groovy.sql.Sql | |
Sql.withInstance('jdbc:mysql://localhost/employees?useUnicode=true&characterEncoding=utf8', | |
'root', 'root', 'com.mysql.jdbc.Driver') { sql -> | |
def times = 1000 | |
def start = 0 | |
print "##### 일반 조인 " | |
start = System.currentTimeMillis() | |
for (i in 1..times) { | |
sql.execute(""" | |
SELECT /*! SQL_NO_CACHE */ e.* | |
FROM salaries s, employees e | |
WHERE e.emp_no=s.emp_no | |
AND s.emp_no BETWEEN 10001 AND 13000 | |
GROUP BY s.emp_no | |
ORDER BY SUM(s.salary) DESC | |
LIMIT 10 | |
"""); | |
} | |
println " - ${System.currentTimeMillis() - start} ms" | |
print "##### 지연된 조인 " | |
start = System.currentTimeMillis() | |
for (i in 1..times) { | |
sql.execute(""" | |
SELECT /*! SQL_NO_CACHE */ e.* | |
FROM | |
(SELECT s.emp_no | |
FROM salaries s | |
WHERE s.emp_no BETWEEN 10001 AND 13000 | |
GROUP BY s.emp_no | |
ORDER BY SUM(s.salary) DESC | |
LIMIT 10) x, | |
employees e | |
WHERE e.emp_no = x.emp_no; | |
"""); | |
} | |
println " - ${System.currentTimeMillis() - start} ms" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment