mysql - "Using sort_union"是什么意思?

标签 mysql sql-execution-plan

(不确定之前是否已经讨论过...)

为类别构建 SQL 时

示例类别数据:

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

hardware 将是 hardware : *

的父类别

当我考虑构建 api 来查询数据库时

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

上面的返回(在执行计划中)

Using sort_union(PRIMARY,some_index); Using where

sort_union 是什么意思?
好的 ?坏的?要避免?


(理解我可以将整个查询重写为更优化的方式,
但是我重新构建整个 api 有一些限制)


mysql 版本 5.1

最佳答案

当你有一个 where 子句,你在其中对两个或更多个进行 OR'ing 时,使用 sort_union,MySQL 认为它比使用 index_merge 更好。

欲了解更多信息,see the MySQL docs

总之,还不错(恕我直言);因为它将首先从两个索引中获取行,然后再对它们进行排序。

关于mysql - "Using sort_union"是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6463695/

相关文章:

PHP mySQL 查询忽略十进制值

php - 交响乐 2.8 : Any way in doctrine similar to "DAYNAME(date)" of mysql?

sql-server - SQL Server 2008 : Why table scaning when another logical condition is satisfied first?

Oracle外键执行计划?

sql - Oracle 计划将 'b' 与 'B' 998x 比较慢(10g 或 11g)

mysql - 1 秒内有如此多的请求更新一条特定数据记录

php - MySQL 获取一个选择,如果不可用则获取其他

MYSQL 按不为空的字段分组

sql-server - 这些使用 OR 的 T-SQL 查询有什么区别?

sql - 可选参数, "index seek"计划