|
|
|
12-01-21
|
조회 3,403
|
|
|
|
12-01-21
|
조회 4,191
|
|
|
선택이란
|
12-01-21
|
조회 3,595
|
|
|
선택이란
|
12-01-21
|
조회 3,266
|
|
|
|
12-01-20
|
조회 3,144
|
|
|
|
12-01-20
|
조회 2,784
|
|
|
관리자
|
12-01-20
|
조회 3,551
|
|
|
관리자
|
12-01-20
|
조회 3,396
|
|
|
|
12-01-20
|
조회 2,791
|
|
|
|
12-01-20
|
조회 3,217
|
|
|
헌이
|
12-01-20
|
조회 6,308
|
|
|
|
12-01-19
|
조회 3,341
|
|
|
|
12-01-19
|
조회 4,990
|
|
|
관리자
|
12-01-19
|
조회 3,278
|
|
|
|
12-01-19
|
조회 3,273
|
|
|
|
12-01-19
|
조회 3,231
|
|
|
|
12-01-19
|
조회 2,850
|
|
|
|
12-01-18
|
조회 3,788
|
|
|
|
12-01-18
|
조회 3,002
|
|
|
|
12-01-18
|
조회 2,754
|
|
|
|
12-01-18
|
조회 3,325
|
|
|
|
12-01-18
|
조회 2,986
|
|
|
|
12-01-18
|
조회 3,162
|
|
|
|
12-01-17
|
조회 2,958
|
|
|
|
12-01-17
|
조회 4,048
|
|
|
|
12-01-17
|
조회 4,473
|
|
|
|
12-01-17
|
조회 3,343
|
|
|
|
12-01-17
|
조회 3,462
|
|
|
|
12-01-17
|
조회 3,199
|
|
|
|
12-01-17
|
조회 5,271
|
|
|
|
12-01-17
|
조회 3,064
|
|
|
|
12-01-16
|
조회 2,801
|
|
|
선택이란
|
12-01-16
|
조회 3,656
|
|
|
|
12-01-16
|
조회 4,143
|
|
|
|
12-01-15
|
조회 2,953
|
|
|
|
12-01-15
|
조회 3,770
|
|
|
|
12-01-15
|
조회 3,721
|
|
|
|
12-01-14
|
조회 3,621
|
|
|
|
12-01-14
|
조회 3,760
|
|
|
|
12-01-14
|
조회 3,493
|
|
|
예감
|
12-01-14
|
조회 1.1만
|
|
|
예감
|
12-01-14
|
조회 3,703
|
|
|
예감
|
12-01-14
|
조회 4,016
|
|
|
선택이란
|
12-01-14
|
조회 2,977
|
|
|
|
12-01-14
|
조회 2,828
|
|
|
|
12-01-13
|
조회 2,968
|
|
|
|
12-01-13
|
조회 3,548
|
|
|
|
12-01-13
|
조회 4,627
|
|
|
|
12-01-13
|
조회 2,966
|
|
|
|
12-01-12
|
조회 4,270
|
|
|
|
12-01-12
|
조회 4,408
|
|
|
|
12-01-12
|
조회 3,414
|
|
|
|
12-01-12
|
조회 3,254
|
|
|
|
12-01-11
|
조회 2,843
|
|
|
|
12-01-11
|
조회 3,271
|
|
|
예감
|
12-01-11
|
조회 3,489
|
|
|
예감
|
12-01-11
|
조회 3,211
|
|
|
예감
|
12-01-11
|
조회 3,216
|
|
|
예감
|
12-01-11
|
조회 3,322
|
|
|
예감
|
12-01-11
|
조회 3,545
|
|
|
|
12-01-11
|
조회 4,325
|
|
|
|
12-01-11
|
조회 3,400
|
|
|
|
12-01-11
|
조회 2,863
|
|
|
선택이란
|
12-01-11
|
조회 1.2만
|
|
|
|
12-01-11
|
조회 3,191
|
|
|
|
12-01-10
|
조회 2,999
|
|
|
|
12-01-10
|
조회 3,719
|
|
|
|
12-01-10
|
조회 4,785
|
|
|
|
12-01-10
|
조회 3,466
|
|
|
|
12-01-10
|
조회 3,197
|
|
|
|
12-01-10
|
조회 2,935
|
|
|
|
12-01-10
|
조회 3,843
|
|
|
|
12-01-10
|
조회 3,115
|
|
|
|
12-01-10
|
조회 4,626
|
|
|
|
12-01-10
|
조회 2,987
|
|
|
|
12-01-10
|
조회 3,023
|
|
|
|
12-01-10
|
조회 3,229
|
|
|
|
12-01-10
|
조회 3,865
|
|
|
|
12-01-10
|
조회 2,929
|
|
|
|
12-01-10
|
조회 4,554
|
|
|
|
12-01-10
|
조회 2,945
|
|
|
|
12-01-10
|
조회 5,421
|
|
|
|
12-01-10
|
조회 5,592
|
|
|
|
12-01-10
|
조회 5,471
|
|
|
|
12-01-10
|
조회 5,367
|
|
|
|
12-01-09
|
조회 2,888
|
|
|
|
12-01-09
|
조회 2,819
|
|
|
|
12-01-09
|
조회 3,360
|
|
|
|
12-01-09
|
조회 3,876
|
|
|
|
12-01-09
|
조회 2,820
|
|
|
|
12-01-09
|
조회 2,987
|
|
|
|
12-01-09
|
조회 2,791
|
|
|
|
12-01-08
|
조회 7,130
|
|
|
|
12-01-08
|
조회 2,815
|
|
|
|
12-01-08
|
조회 7,221
|
|
|
jakekwak
|
12-01-08
|
조회 3,749
|
|
|
|
12-01-08
|
조회 3,335
|
|
|
|
12-01-08
|
조회 2,736
|
|
|
|
12-01-08
|
조회 2,897
|
|
|
선택이란
|
12-01-08
|
조회 3,531
|
댓글 13개
흥미로운 쿼리문이라 살펴 보았습니다.^^
제가 보기에는...
from (select in_pumno, in_code from in_table group by in_code having in_code = "123") a
이 구문은.. 저 select의 결과물이 in_code=123 이것중에 하나만 뽑아지겠네요..
[ WHERE a.in_code='123' order by a.in_code LIMIT 1 ]과 동일한 결과가 나올것 같습니다.
group by보다는 where가 속도가 좀더 빠르지 않을까 생각이 듭니다.
다음줄의
left join (select pr_pumno, pr_code, sum(pr_amount) as pr_amt from pr_table group by pr_code having pr_code = "123") b on a.in_code = b.pr_code
이것또한 비슷하긴 하지만.. 카운트 하는것이 있어서 그룹으로 묶어야 겠네요..
이 안의 서브쿼리는 밖으로 빼는게 속도가 더 느리게 나오나요?
한번도 해보지 않아서 잘 모르겠네요..
인덱스는 당연히 적절히 잘 설정하셨을거라 생각합니다.
데이터셋이 있으면 한번 테스트 해볼텐데..
하쉽네요..^^
한번 테스트해보고 후기 올리겠습니다. 행복한 밤 되세요.^^
대용량 데이터베이스를 만져볼 기회가 잘 없으니..
이런 경험도 귀중한 경험이 될것 같습니다.
1. in_code, pr_code 인덱스 체크
2. 서브쿼리 b의 group by 쿼리를 distinct 쿼리로 수정
3. 서브쿼리 a의 group by 쿼리는 단순 where 조건절로 수정 또는 밖으로 빼서 바로 조인
감사합니다.
from
in_table a
where a.in_code='123'
order by a.in_pumno
저도 초보입장으로 보면.. 두번의 서브쿼리를 풀스캔을 하고 있어서 데이타 양에 따라 상당히 부하가 가지 않을까 싶네요.
순도뤼님 말씀처럼 적절한 인덱스 걸기가 중요할거 같네요.
1. 비교부분에 인덱스 부분, in_pumno,in_code,pr_code
검증이 안된거라..^^; 틀리면 죄송합니다.
그런데 속도는 첫번째 쿼리가 두번째 쿼리보다 엄청빠릅니다.
having 절을 아무데나 쓰는게 아니군요...ㅋ
을 왜 사용하는지 모르겠군요.
HAVING SUM(필드) > 1000 이렇게 함수결과값을 얻어 비교할때만 빠르군요.
일반 조건절은 무조건 where문을 사용하십시오.
SELECT a.in_pumno, a.in_code, a.in_dcno, ifnull( a.in_amt, 0 ) , ifnull( b.pr_amt, 0 ) , ifnull( a.in_amt, 0 ) - ifnull( b.pr_amt, 0 ) , a.in_vendor
FROM (
SELECT in_pumno, in_code, in_dcno, sum( in_amount ) AS in_amt, in_vendor, in_comp
FROM in_table where in_code = '3SILKR001FJNBQ' group by in_code
) as a
LEFT JOIN (
SELECT pr_code, pr_pumno, pr_vendor, sum( pr_amount ) AS pr_amt
FROM pr_table
where pr_code = '3SILKR001FJNBQ' group by pr_code
) as b ON a.in_code = b.pr_code
ORDER BY a.in_pumno
LIMIT 0 , 30
===============================================================================
SELECT a.in_pumno, a.in_code, a.in_dcno, ifnull( a.in_amt, 0 ) , ifnull( b.pr_amt, 0 ) , ifnull( a.in_amt, 0 ) - ifnull( b.pr_amt, 0 ) , a.in_vendor
FROM (
SELECT in_pumno, in_code, in_dcno, sum( in_amount ) AS in_amt, in_vendor, in_comp
FROM in_table
GROUP BY in_code
HAVING in_code = '3SILKR001FY5HM'
)a
LEFT JOIN (
SELECT pr_code, pr_pumno, pr_vendor, sum( pr_amount ) AS pr_amt
FROM pr_table
GROUP BY pr_code
HAVING pr_code = '3SILKR001FY5HM'
)b ON a.in_code = b.pr_code
ORDER BY a.in_pumno
LIMIT 0 , 30
역시 WHERE가 빠르군요..^^
EXPLAIN SELECT a.in_pumno, a.in_code, a.in_dcno, ifnull( a.in_amt, 0 ) , ifnull( b.pr_amt, 0 ) , ifnull( a.in_amt, 0 ) - ifnull( b.pr_amt, 0 ) , a.in_vendor
FROM (
SELECT in_pumno, in_code, in_dcno, sum( in_amount ) AS in_amt, in_vendor, in_comp
FROM in_table
WHERE in_code = '3SILKR001FJNBQ'
GROUP BY in_code) AS a
LEFT JOIN (
SELECT pr_code, pr_pumno, pr_vendor, sum( pr_amount ) AS pr_amt
FROM pr_table
WHERE pr_code = '3SILKR001FJNBQ'
GROUP BY pr_code) AS b ON a.in_code = b.pr_code
ORDER BY a.in_pumno
LIMIT 0 , 30
=====================================================
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived2> system NULL NULL NULL NULL 1
1 PRIMARY <derived3> system NULL NULL NULL NULL 1
3 DERIVED pr_table ref pr_code pr_code 50 1 Using where
2 DERIVED in_table ref in_code in_code 50 1 Using where
아직 explain을 분석할줄 몰라 잠시 찾아 보았습니다.
첫번째 두번째 로 분석된 테이블은 인덱스를 활용하지 못했군요..
레코드수가 많은 놈은 속도가 40초가 넘네요.
쩝쩝...쿼리문을 손봐야하겠는데...
어떻게 손을 봐야 빨라질지..난감합니다.ㅠㅠ