Skip to content

Instantly share code, notes, and snippets.

@kwon37xi
Last active December 17, 2015 18:19
Show Gist options
  • Save kwon37xi/5652026 to your computer and use it in GitHub Desktop.
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 이 정말로 성능이 좋아지는지 테스트하는 코드.
@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