다음 쿼리는 테이블 컬럼의MySql을 사용하면 별도의 쿼리 나 하위 쿼리를 더 빨리 사용할 수 있습니까?
(SELECT 1, `name` FROM `tab1` WHERE `reg` = 5 and `lang` = 9 and `queue` =
(select min(`queue`) from tab1 where `reg` = 5 and `lang` = 9)
limit 5)
UNION ALL
(SELECT 2, `name` FROM `tab1` WHERE `reg` = 1 and `lang` = 3 and `queue` =
(select min(`queue`) from tab1 where `reg` = 1 and `lang` = 3)
limit 5)
UNION ALL
(SELECT 3, `name` FROM `tab1` WHERE `reg` = 3 and `lang` = 11 and `queue` =
(select min(`queue`) from tab1 where `reg` = 3 and `lang` = 11)
limit 5)
가있을 것입니다, 이론적으로, 성능에 대한 혜택을 감지하기 위해, 경우를 MIN(value)
에서 85,862 행의 총 2,477 행을 선택 초0.2630했다 , 하위 쿼리 대신 별도의 쿼리를 실행하겠습니까?
열 reg
및 색인 lang
, queue
하지
가 EXPLAIN입니다 :
| id | select_type | table | type | possible_keys | key | key_len | ref | rows| Extra
-----+-------------+-------------+-------------+---------------+----------+---------+------+-----+---------------------------------------
| 1 | PRIMARY | tab1 | index_merge | reg,lang | lang,reg | 1,1 | NULL | 813 | Using intersect(lang,reg); Using where
| 2 | SUBQUERY | tab1 | index_merge | reg,lang | lang,reg | 1,1 | NULL | 813 | Using intersect(lang,reg); Using where
| 3 | UNION | tab1 | index_merge | reg,lang | lang,reg | 1,1 | NULL | 830 | Using intersect(lang,reg); Using where
| 4 | SUBQUERY | tab1 | index_merge | reg,lang | lang,reg | 1,1 | NULL | 830 | Using intersect(lang,reg); Using where
| 5 | UNION | tab1 | index_merge | reg,lang | lang,reg | 1,1 | NULL | 834 | Using intersect(lang,reg); Using where
| 6 | SUBQUERY | tab1 | index_merge | reg,lang | lang,reg | 1,1 | NULL | 834 | Using intersect(lang,reg); Using where
|NULL| UNION RESULT| <union1,3,5>| ALL | NULL | NULL | NULL | NULL | NULL| Using temporary
'show indexes from tab1'을 실행하고'explain {your query}'를 실행하고 질문에 결과를 게시하십시오. –
원하는 결과 세트에 적절한 DDL (및/또는 sqlfiddle)을 제공하십시오. – Strawberry
* ... 2477 행을 선택하는 중 ... * 쿼리에서 'limit 5'가 15 점을 넘는 이유는 무엇입니까? –