select * from g5_write_free where wr_parent = '265004' and wr_is_comment = 1 order by wr_comment , wr_comment_reply
select count(*) as cnt from g5_write_free where mb_id = 'qwerer' and wr_is_comment = '1' and date_format(wr_datetime, '%Y-%m-%d') = '2023-01-19'
select * from g5_write_gallery where wr_parent = '17574' and wr_is_comment = 1 order by wr_comment , wr_comment_reply
이것들때문에 부하가 상당한데.
이거 튜닝이나 개선방법 있을까요?ㅠㅠ
답변 4개 / 댓글 2개
* 인덱스 추가
1. wr_parent, wr_is_comment
2. mb_id, wr_is_comment
* 2번째 쿼리 변경
select count(*) as cnt from g5_write_free where mb_id = 'qwerer' and wr_is_comment = '1' and date_format(wr_datetime, '%Y-%m-%d') = '2023-01-19'
->
select count(*) as cnt from g5_write_free where mb_id = 'qwerer' and wr_is_comment = '1' and (wr_datetime between '2023-01-19 00:00:00' and '2023-01-19 23:59:59')
optimize g5_write_free ;
optimize g5_write_gallery ;
를 한번 실행해보세요
그리고 날짜비교는
date(wr_datetime) = '2023-01-19' 로 하는것도 방법입니다.
index를 하나 추가하자면
wr_id , wr_is_comment , wr_datetime
이 묶인걸 하나 추가해보세요
그래도 좀 아쉬우면
wr_comment , wr_comment_reply 묶인index 하나더 추가후 이상없으면 그대로 적용
별차이 없으면 제거
index는 너무 많아도 안되지만 너무 난해해도 안되니 최대한 필요한것만 간결하게 적용하세요
답변을 작성하려면 로그인이 필요합니다.
wr_parent와 함께 wr_num도 넣어 보세요