테스트 사이트 - 개발 중인 베타 버전입니다

디비 부하 해당쿼리 튜닝방법 있을까요?

최호진 2년 전 조회 1,088

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')

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

플래토
2년 전

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는 너무 많아도 안되지만 너무 난해해도 안되니 최대한 필요한것만 간결하게 적용하세요

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

현재 인덱스가 어떻게 구성되어 있나요

로그인 후 평가할 수 있습니다

답변에 대한 댓글 2개

엑스엠엘
2년 전
where절에
wr_parent와 함께 wr_num도 넣어 보세요
엑스엠엘
2년 전
date_format(wr_datetime, '%Y-%m-%d') = '2023-01-19'
대신
wr_datetime between '2023-01-19' and '2023-01-19 23:59:59'
로 해 보세요

댓글을 작성하려면 로그인이 필요합니다.

기본적으로 게시물 자체가 엄청나게 많은가 보네요..

index 를 잘 활용하면 도움이 될 것 같습니다.

기본적으로 아래의 내용을 참고해서 테이블을 최적화 하는 방법 밖에 없을 것입니다.

https://dev.mysql.com/doc/refman/8.0/en/optimizing-database-structure.html

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인