ORACLE中Like与Instr性能大比拼
2010-02-11 15:07
288 查看
t表中将近有1100万数据,很多时候,我们要进行字符串匹配,在SQL语句中,我们通常使用like来达到我们搜索的目标。但经过实际测试发现,like的效率与instr函数差别相当大。下面是一些测试结果:
SQL> set timing on
SQL> select count(*) from t where instr(title,’手册’)>0;
COUNT(*)
———-
65881
Elapsed: 00:00:11.04
SQL> select count(*) from t where title like ‘%手册%’;
COUNT(*)
———-
65881
Elapsed: 00:00:31.47
SQL> select count(*) from t where instr(title,’手册’)=0;
COUNT(*)
———-
11554580
Elapsed: 00:00:11.31
SQL> select count(*) from t where title not like ‘%手册%’;
COUNT(*)
———-
11554580
另外,我在另外一个2亿多的表,使用8个并行,使用like查询很久都不出来结果,但使用instr,4分钟即完成查找,性能是相当的好。这些小技巧用好,工作效率提高不少。通过上面的测试说明,ORACLE内建的一些函数,是经过相当程度的优化的。
*************************************************************************************
在有28835876条数据的表t_productbilldetails中,本人亲自测试效果如下:
select count(1) as aaa from t_productbilldetails pbd;--9.156 sec
select count(1) as aaa from t_productbilldetails pbd
where pbd.accountid like '200912%';--108.672 sec
select count(1) as aaa from t_productbilldetails pbd
where instr(pbd.accountid,'200912')=1;--39.11 sec
SQL> set timing on
SQL> select count(*) from t where instr(title,’手册’)>0;
COUNT(*)
———-
65881
Elapsed: 00:00:11.04
SQL> select count(*) from t where title like ‘%手册%’;
COUNT(*)
———-
65881
Elapsed: 00:00:31.47
SQL> select count(*) from t where instr(title,’手册’)=0;
COUNT(*)
———-
11554580
Elapsed: 00:00:11.31
SQL> select count(*) from t where title not like ‘%手册%’;
COUNT(*)
———-
11554580
另外,我在另外一个2亿多的表,使用8个并行,使用like查询很久都不出来结果,但使用instr,4分钟即完成查找,性能是相当的好。这些小技巧用好,工作效率提高不少。通过上面的测试说明,ORACLE内建的一些函数,是经过相当程度的优化的。
*************************************************************************************
在有28835876条数据的表t_productbilldetails中,本人亲自测试效果如下:
select count(1) as aaa from t_productbilldetails pbd;--9.156 sec
select count(1) as aaa from t_productbilldetails pbd
where pbd.accountid like '200912%';--108.672 sec
select count(1) as aaa from t_productbilldetails pbd
where instr(pbd.accountid,'200912')=1;--39.11 sec
相关文章推荐
- ORACLE中Like与Instr模糊查询性能大比拼(转载)
- ORACLE中like与instr性能大比拼
- ORACLE中Like与Instr模糊查询性能大比拼(转载)
- ORACLE中Like与Instr模糊查询性能大比拼
- ORACLE中like与instr性能大比拼
- ORACLE中Like与Instr模糊查询性能大比拼(转载)
- Oracle中Like与Instr模糊查询性能大比拼
- ORACLE中Like与Instr模糊查询性能大比拼
- ORACLE中Like与Instr模糊查询性能大比拼
- ORACLE中Like与Instr模糊查询性能大比拼
- ORACLE中Like与Instr模糊查询性能大比拼
- ORACLE中Like与Instr性能大比拼(转)
- ORACLE中Like与Instr模糊查询性能大比拼
- ORACLE中Like与Instr模糊查询性能大比拼
- oracle中Like与Instr的性能比较
- Oracle 中 instr 性能比 like 好
- 【转】ORACLE中Like与Instr性能大比拼
- ORACLE中Like与Instr模糊查询性能大比拼
- Oracle模糊查询之(3.2从使用函数和sql语法角度来提高模糊查询效率 二)ORACLE中Like与Instr模糊查询性能大比拼
- Oracle模糊查询 like与instr