在oracel 中, 写的SQL用到了 or, 如果太多的话会影响执行的效率, 那么我们可以指定 让优化器执行 将 where后面的or 条件转化为 union all 的组合查询。
/*+USE_CONCAT*/
SELECT /*+USE_CONCAT*/ FROM TABLE WHERE id = '123' OR name = '张三'
转化后的结果
select * from table where id = '123'
union all
select * from table where name =' 张三'
union all 与 union 的区别
union all 允许查询结果有重复值,速度较快。
union 会过滤重复的值, 速度较 union all 会慢一点。