网上看了一些例子,说是oracle的instr性能要比like的要好,我自己测试了一下:
select count(*) from t_log_app ; 总数据为13558892行
select count(*) from t_log_app where instr(fentityid,'CE7AE')>0;
这条语句执行结果为:2606 耗时 40s
select count(*) from t_log_app where fentityid like '%CE7AE%' ;
这条语句执行结果为:2606 耗时 41s
这样看其实性能都差不多。(注:fentityid非索引)
再测试一下索引
select count(*) from t_log_app where instr(fitemname,'addnew')>0;
这条语句执行结果为:268126 耗时 40s
select count(*) from t_log_app where fitemname like '%addnew%' ;
这条语句执行结果为:268126 耗时 ≈7s
这样看 like又比instr性能要好了。这究竟是什么原因???