(不确定之前是否已经讨论过...)
为类别构建 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/