슬로우 쿼리 질문드립니다. 이것이 어디서 발생하는 쿼리인지요?

매출이 오르면 내리는 수수료! 지금 수수료센터에서 전자결제(PG)수수료 비교견적 신청해 보세요!
슬로우 쿼리 질문드립니다. 이것이 어디서 발생하는 쿼리인지요?

QA

슬로우 쿼리 질문드립니다. 이것이 어디서 발생하는 쿼리인지요?

본문

# Time: 230405 21:26:05

# Query_time: 4  Lock_time: 0  Rows_sent: 1  Rows_examined: 351231

select wr_id, wr_subject from g4_write_free where wr_is_comment = 0 and wr_num < '-354793'  order by wr_num desc, wr_reply desc limit 1;

 

이것이 어떤것을 할시에 발생되는 쿼리인가요? 검색은 기본정보에서 3000개로 설정해놓은 상태입니다. 검색은 아닌것 같기도 하고, 업데이트 쿼리가 아니라 쓰기관련은 아닌것같고.. 3만건 이상의 데이터를 가져오는 이런 쿼리가 발생할수 있는것이 글쓰기나 삭제, 정렬, 검색 등 어떤것을 할때 발생할수 있는 쿼리일까요?

 

해당쿼리로 인하여 슬로우쿼리가 발생하여 사이트가 계속 지연된다는 호스팅업체의 답변을 받았습니다. 

 

도움좀 부탁드리겠습니다. 

이 질문에 댓글 쓰기 :

답변 6

// 윗글을 얻음

    $sql = " select wr_id, wr_subject from $write_table where wr_is_comment = 0 and wr_num = '$write[wr_num]' and wr_reply < '$write[wr_reply]' $sql_search order by wr_num desc, wr_reply desc limit 1 ";

    $prev = sql_fetch($sql);

    // 위의 쿼리문으로 값을 얻지 못했다면

    if (!$prev[wr_id]) {

        $sql = " select wr_id, wr_subject from $write_table where wr_is_comment = 0 and wr_num < '$write[wr_num]' $sql_search order by wr_num desc, wr_reply desc limit 1 ";

        $prev = sql_fetch($sql);

    }

 

여기서

and wr_num < '$write[wr_num]'

 and wr_id > '$write['wr_id']' 

로 바꿔 보세요

https://github.com/gnuboard/gnuboard4/blob/master/bbs/view.php#L32

이부분 인것 같습니다.

배르만님 알려주셔서 너무 감사합니다. 너무나도 외람된 말씀입니다만 슬로우 쿼리 내용을 보니까 Rows 30만건 이상이 들어가 지연되는것 같은데. 이것을 어떻게 처리를 하면 속도 개선이 될지 도움을 부탁드릴수 있을까요. 가능하다면 비용을 드리고 요청을 드리고 싶을 정도입니다. 사이트가 갈수록 너무 느려지거나 먹통이 발생되는 현상이 계속 되고 있어서. ㅜㅜ

index hint를 사용하시거나

 index를 추가해 보세요.

 

엑스엠엘님 답변 너무나 감사합니다. 혹 좀더 도움을 주실수 있으시다면..
bbs/view.php 파일에서 해당문구 상단에 보면
if (!$board[bo_use_list_view]) {} 전체목록을 사용을 안할시 해당쿼리가 돌아가게 되있는데 현재 게시판에서는 전체목록을 사용하고 있고 체크가 되어 있습니다만 해당쿼리가 돌아가는 상황이 있을수 있을까요?
<input type=checkbox name=bo_use_list_view value='1' checked>사용

Phpmyadmim 등에서

Explain elect wr_id, wr_subject from g4_write_free where wr_is_comment = 0 and wr_num < '-354793' order by wr_num desc, wr_reply desc limit 1;

실행한 결과를 올려 보세요.

Explain select wr_id, wr_subject from g4_write_free where wr_is_comment = 0 and wr_num < '-354793' order by wr_num desc, wr_reply desc limit 1;

table: g4_write_free
type: ref
possible_keys: wr_num_reply_parent,wr_is_comment,list_index,comment_index,wr_num_idx
key: list_index
ref: const
key_len: 1
rows: 217297
Extra: Using where

이전글 또는 다음글을 추출해 오는 부분입니다.

 

개인적으로 생각했을 때 없어도 무방한 내용입니다.

 

해당 쿼리, 이전글/다음글 표시 부분을 모두 삭제하는 방법이 있습니다.

Show index  from g4_write_free
실행 결과

 

Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment
g4_write_free 0 PRIMARY 1 wr_id A 436570 NULL NULL   BTREE  
g4_write_free 1 wr_num_reply_parent 1 wr_num A 436570 NULL NULL   BTREE  
g4_write_free 1 wr_num_reply_parent 2 wr_reply A 436570 NULL NULL   BTREE  
g4_write_free 1 wr_num_reply_parent 3 wr_parent A 436570 NULL NULL   BTREE  
g4_write_free 1 wr_is_comment 1 wr_is_comment A 2 NULL NULL   BTREE  
g4_write_free 1 wr_is_comment 2 wr_id A 436570 NULL NULL   BTREE  
g4_write_free 1 list_index 1 wr_is_comment A 2 NULL NULL   BTREE  
g4_write_free 1 list_index 2 wr_num A 436570 NULL NULL   BTREE  
g4_write_free 1 list_index 3 wr_reply A 436570 NULL NULL   BTREE  
g4_write_free 1 comment_index 1 wr_is_comment A 2 NULL NULL   BTREE  
g4_write_free 1 comment_index 2 wr_parent A 436570 NULL NULL   BTREE  
g4_write_free 1 comment_index 3 wr_comment A 436570 NULL NULL   BTREE  
g4_write_free 1 comment_index 4 wr_comment_reply A 436570 NULL NULL   BTREE  
g4_write_free 1 wr_1_idx 1 wr_1 A 5 NULL NULL   BTREE  
g4_write_free 1 wr_6_idx 1 wr_6 A 6929 NULL NULL   BTREE  
g4_write_free 1 wr_datetime_idx 1 wr_datetime A 436570 NULL NULL   BTREE  
g4_write_free 1 ca_name_idx 1 ca_name A 14 NULL NULL   BTREE  
g4_write_free 1 wr_num_idx 1 wr_num A 436570 NULL NULL   BTREE  
g4_write_free 1 wr_reply_idx 1 wr_reply A 1 NULL NULL   BTREE  
답변을 작성하시기 전에 로그인 해주세요.
전체 10,635
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT