• Daum
  • |
  • 카페
  • |
  • 테이블
  • |
  • 메일
  • |
  • 카페앱 설치
 
카페정보
델파이 내공 쌓기(with jjs)
 
 
 
카페 게시글
델파이 강좌 SQL 쿼리문의 최적화에 대해서
주정섭 추천 0 조회 1,177 04.09.22 10:26 댓글 26
게시글 본문내용
 
다음검색
댓글
  • 05.04.27 13:31

    첫댓글 CPU 이용률 이런것도 참고해야 하는데...

  • 05.11.12 11:32

    Inline view라고 속칭하는 From절의 Select절은 지양하는 것이 원칙입니다. 일반 Ansi 표준 SQL에서 허용할 수 있는 문장을 굳이 inline view 사용해서 표현할 이유도 없고요 상기 퀴리는 Inline view의 결과을 해싱하고 다시 그것을 그룹핑한다음 또 그것을 소트까지 했습니다. 상기 쿼리에서 수정할 것은

  • 05.11.12 11:36

    Order by 절입니다. 이미 Group by절에서 정렬이 이루어 졌기에 의미 없으며 오히려 엔진에 쓸데없는 Overload를 가중합니다. (실제 차이는 별로 없겠지만 데이터 건수가 많을 경우 정렬 한 문장이 어디입니까 ^^) 마지막으로 inline view를 쓰지 않는 것이 좋겠죠.. 물론 대안 없이 말씀 드리는 것도 아니고요 ^^

  • 05.11.12 11:38

    Select case when cust_name < '가' then '기타' when cust_name < '나' then 'ㄱ' when cust_name < '다' then 'ㄴ' when cust_name < '라' then 'ㄷ' when cust_name < '마' then 'ㄹ'

  • 05.11.12 11:39

    when cust_name < '바' then 'ㅁ' when cust_name < '사' then 'ㅂ' when cust_name < '아' then 'ㅅ' when cust_name < '자' then 'ㅇ' when cust_name < '차' then 'ㅈ' when cust_name < '카' then 'ㅊ'

  • 05.11.12 11:39

    when cust_name < '타' then 'ㅋ' when cust_name < '파' then 'ㅌ' when cust_name < '하' then 'ㅍ' when cust_name < '힣' then 'ㅎ' else '기타' end as chr, count(*) from customer group by 1;

  • 05.11.12 11:40

    상기 5항의 문장은 위와 같이 Ansi 표준 SQL 로 바뀌어 지겠죠 이경우 Mysql, firebird, Oracle, Sql-Server, MDB,.... 모두 통용이 가능합니다.

  • 05.11.12 11:47

    그리고 상기와 같이 이미 알고 있는 최대 레코드수가 적고 또한 한정적일때에는 Fech record를 쓸 이유가 없습니다. 또한 그렇게 사용해야 Client Porgram에서도 Looping하면서 비교할 필요도 없고요 그리고 또한, 쓸데없는 네트워크 트랙픽을 유발할 이유도 없고요 상기는 한건의 레코드로 유도하는 것이 정답입니다.

  • 05.11.12 12:00

    Select count(case when (cust_name < '가' or cust_name > '힣') then cust_name end) as f0,

  • 05.11.12 12:00

    count(case when (cust_name >= '가' and cust_name < '나') then cust_name end) as f1,

  • 05.11.12 12:00

    count(case when (cust_name >= '나' and cust_name < '다') then cust_name end) as f2,

  • 05.11.12 12:00

    count(case when (cust_name >= '다' and cust_name < '라') then cust_name end) as f3,

  • 05.11.12 12:00

    count(case when (cust_name >= '라' and cust_name < '마') then cust_name end) as f4,

  • 05.11.12 12:01

    count(case when (cust_name >= '마' and cust_name < '바') then cust_name end) as f5,

  • 05.11.12 12:01

    count(case when (cust_name >= '바' and cust_name < '사') then cust_name end) as f6,

  • 05.11.12 12:01

    count(case when (cust_name >= '사' and cust_name < '아') then cust_name end) as f7,

  • 05.11.12 12:02

    count(case when (cust_name >= '아' and cust_name < '자') then cust_name end) as f8,

  • 05.11.12 12:02

    count(case when (cust_name >= '자' and cust_name < '차') then cust_name end) as f9,

  • 05.11.12 12:02

    count(case when (cust_name >= '차' and cust_name < '카') then cust_name end) as f10,

  • 05.11.12 12:03

    count(case when (cust_name >= '카' and cust_name < '타') then cust_name end) as f11,

  • 05.11.12 12:03

    count(case when (cust_name >= '타' and cust_name < '파') then cust_name end) as f12,

  • 05.11.12 12:03

    count(case when (cust_name >= '파' and cust_name < '하') then cust_name end) as f13,

  • 05.11.12 12:04

    count(case when (cust_name >= '하' and cust_name < '힣') then cust_name end) as f14 from customer

  • 05.11.12 12:09

    여기서의 문제는 상기 5항을 수정해서 Ansi SQL로 최적화 한 제가올린 쿼리보다 최고 4배의 비교루틴을 엔진에서 감당해야 함인데 그러나 이것은 1회 패치에서 이루어진 메모리연산이므로 크게 성능의 차이는 없다고 봅니다. 쿼리상의 장점은 Grouping에 따른 레코드 정렬이 필요없고요

  • 05.11.12 12:12

    한건의 레코드의 이득은 오히려 그것을 상쇄시켜 줍니다. 그리고 쿼리문장이 길다고 가독성이 떨어지는 것도 물론 아닙니다. 오히려 더 직관적이죠.. 그럼이만...

  • 06.01.31 17:31

    그런데 case문보다 decode문이 더 효율적이라 들었습니다만....

최신목록