union all 和 or 效率问题

网上都说union all效率比or快,可是实际使用过程中发现or比union all快,sql语句如下,使用or查询耗时1s多,union all耗时2s多,表数据大概有8千万左右,是按天分区的。
union all 的sql语句1:
select * from t_m_train_record t where t.stunum='5111786145333504' and t.traintime between to_date('20180710122954','yyyymmddhh24miss') and to_date('20180710153940','yyyymmddhh24miss') union all select * from t_m_train_record t where t.stunum='5111786145333504' and t.traintime between to_date('20180711141455','yyyymmddhh24miss') and to_date('20180711161920','yyyymmddhh24miss');

or 的sql语句2:
select * from t_m_train_record t where t.stunum='5111786145333504' and t.traintime between to_date('20180710122954','yyyymmddhh24miss') and to_date('20180710153940','yyyymmddhh24miss') union all select * from t_m_train_record t where t.stunum='5111786145333504' and t.traintime between to_date('20180711141455','yyyymmddhh24miss') and to_date('20180711161920','yyyymmddhh24miss');

不考虑走索引优化之类的。从理论上or是要快一点,因为or只扫描一遍表, union要两次。 但是如果考虑索引的话union all可以比or要快
这个要看具体执行计划和表数据的分布情况

or的那句sql贴错了,两句是一样的

union all和or要看用在哪

select * from t where a=xx or a=yy

select * from t where a=xx
union all
select * from t where a=yy
应该union all 会快一点


select * from t where (a=xx or a=yy) and b=zz

select * from t where a=xx and b=zz
union all
select * from t where a=yy and b=zz
这种可能or会快一点

select * from t_m_train_record t where t.stunum='5111786145333504' and( t.traintime between to_date('20180710122954','yyyymmddhh24miss') and to_date('20180710153940','yyyymmddhh24miss') or t.traintime between to_date('20180711141455','yyyymmddhh24miss') and to_date('20180711161920','yyyymmddhh24miss')); or的sql语句代码贴错了

通常,
如果查询上有索引,union all比or快,因为前者会利用索引查找,后者不会;
如果查询上没有索引,or 比union快,因为前者查询引擎会一次性完成指令分析
但是,
具体哪个更快,与数据的体量,分区的方式,查询数据落入的区间都相关