AWS RDS aurora 5.6 입니다.
aurora5.6 에서 optimizer_switch = derived_merge=on, derived_with_key=on 전역변수 설정 활성화가 안되어서 파생테이블에 참조되는 테이블의 키를 사용할 수 없게 되어있어서
아래 쿼리를 사용시 using temporary, using filesort 가 발생되어서 쿼리가 느리게 동작하는데요 , 고수님들의 튜닝의견 부탁드립니다~!!
-------------------------------------------------------------------------------
<query>
select f_doc .* from f_doc join (
select f_doc.idx from f_doc
join (select f_id from f_m where p_id = 2) as f_m
on f_m.f_id = f_doc.f_id
where state = 'Y'
ORDER BY `f_doc`.`idx` DESC
LIMIT 30 offset 130000) as inview
on f_doc.idx = inview.idx;
-------------------------------------------------------------------------------
<table>
1. f_doc
idx | bigint(20) unsigned | NO | PRI | auto_increment | |
f_id | int(10) unsigned | NO | |||
state | enum('Y','N') | NO | MUL | Y | |
memid | int(10) unsigned | NO | |||
memnick | varchar(40) | NO | |||
created_at | timestamp | NO | CURRENT_TIMESTAMP | ||
updated_at | timestamp | NO | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP | |
title | varchar(200) | YES | |||
content | mediumtext | YES |
2. f_m
idx | int(10) unsigned | NO | PRI | auto_increment | |
p_id | int(10) unsigned | NO | MUL | ||
f_id | int(10) unsigned | NO | MUL | ||
name | varchar(200) | NO |
---------------------------------------------------------------------------------
<execution plan>
PRIMARY | <derived2> | ALL | 130030 | |||||
PRIMARY | f_doc | eq_ref | PRIMARY,idx_fid | PRIMARY | 8 | inview.idx | 1 | |
DERIVED | <derived3> | ALL | 4 | Using temporary; Using filesort | ||||
DERIVED | f_doc | ref | s_i,s_i_f,s_f_i | s_f_i | 5 | const,f_m.f_id | 77436 | Using where; Using index |
DERIVED | f_m | ref | p_f | p_f | 4 | const | 4 | Using index |