ORACLE中Like与Instr性能大比拼
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内建的一些函数,是经过相当程度的优化的。
Tags: oracle like Instr zhaolinjnu 丹
臣
Related posts
No related posts.
--EOF--
Trackback:
http://rdc.taobao.com/blog/dba/html/246_like_instr_performance.html/trackback
相关文档:
转载
DML statements on temporary tables do not generate redo logs for the data changes. However, undo logs for the data
and redo logs for the undo logs are generated. Data from the temporary table is automatically
dropped in the case of session termination, either when the user logs o ......
添加引用
using System.Data.OracleClient;
主要用到了两个类
System.Data.OracleClient.OracleConnection 表示一个到数据库的连接。此类无法继承。
System.Data.OracleClient.OracleCommand 表示针对数据库执行的 SQL 语句或存 ......
Oracle to_date的使用方法
日期格式参数 含义说明
D 一周中的星期几
DAY 天的名字,使用空格填充到9个字符
DD 月中的第几天
DDD 年中的第几天
DY 天的简写名
IW ISO标准的年中的第几周
IYYY ISO标准的四位年份
YYYY 四位年份
YYY,YY,Y 年份的最后三位,两位,一位
HH 小时,按12小时计
......
TO_DATE格式(以时间:2007-11-02 13:45:25为例)
Year:
yy two digits 两位年 &n ......