开发者

What does "Using sort_union" mean?

开发者 https://www.devze.com 2023-03-15 06:38 出处:网络
(Not sure is this has been discussed before ...) When building SQL for category example category data: ID | NAME

(Not sure is this has been discussed before ...)

When building SQL for category

example category data:

ID | NAME
--------------------------
1  | hardware
2  | hardware : notebooks
3  | hardware : phones
4  | hardware : desktops
5  | review
6  | review : photo gallery

hardware will be the parent category for hardware : *

When I considering building api to query database

desc select * from category 
where id=1 or 
name like concat((select name from category where id in(1)), '_%');

the above return (in the execution plan)

Using sort_union(PRIMARY,some_index); Using where

What is the 开发者_运维问答sort_union means ?

Good ? Bad? To be avoid ?


(understand I could rewrite the entire query into a more optimize way,

but there are some constraints for me to re-build the entire api)


mysql version 5.1


sort_union is used when you have a where clause in which you are OR'ing two or more, for which MySQL thinks it's better than using index_merge.

For more information, see the MySQL docs

In short, it's not bad (imho); since it will fetch the rows from both indexes first, before sort-unioning them.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号