1> select * from table1,table2 where table1.id=table2.id and substr(table2.code,1,3)='001'效率高。
to wangybyangxr(王永斌) 你的意思是用表连接比较的快,对吗
用in关键字会造成全表扫描. 第一条改为 select * from table1,table2 where table1.id=table2.id and table2 like '001%' 会好得多.
哦.错.少个字段. select * from table1,table2 where table1.id=table2.id and table2.code like '001%'
应该是 select * from table1,table2 where table1.id=table2.id and substr(table2.code,1,3)='001' 比较快吧。set timing on,打开记时,看看他的执行事件。
to hero1981(英雄) 对,我的意思是用表连接比较的快。
select * from table1,table2 where table1.id=table2.id and table2.code like '001%'; 比较快, 条件左边尽量不要使用函数,会破坏索引.
使用substr会使索引失效.除非你建立基于函数的索引. 因此like还是适合些.
肯定是1快,至于like还是substr自己看看哪个执行时间短就知道了,我们不清楚你的数据结构。
select * from table1,table2 where table1.id=table2.id and substr(table2.code,1,3)='001' 快一些,而且你可以写成 select * from table1,table2 where table1.id=table2.id and table2.code >='001' and table2.code <='001' + 'z'这样你在索引里包含table2.code会更快一些
哈哈 见识 谢谢老大们 select * from table1,table2 where table1.id=table2.id and table2.code >='001' and table2.code <='001' + 'z'其中的'z'这种是什么写法
用IN 的比较慢 别的不说,碰到集合查询像IN, NOT IN, EXISTS ..,Oracle 本身会试图把集合查询转换成表连接,如果转换不成,则会照原样查询 另外,IN也会造成全表扫描,table1中有8千条记录就要判断8千次
哈哈 见识 谢谢老大们 select * from table1,table2 where table1.id=table2.id and table2.code >='001' and table2.code <='001' + 'z'其中的'z'这种是什么写法你的这种写法是错误的,字符串不能象'001' + 'z'这样相加,这样还'001'||'z'差不多
select * from table1,table2 where table1.id=table2.id and substr(table2.code,1,3)='001'效率高。
你的意思是用表连接比较的快,对吗
第一条改为
select * from table1,table2 where table1.id=table2.id and table2 like '001%'
会好得多.
select * from table1,table2 where table1.id=table2.id and table2.code like '001%'
select * from table1,table2 where table1.id=table2.id and substr(table2.code,1,3)='001'
比较快吧。set timing on,打开记时,看看他的执行事件。
对,我的意思是用表连接比较的快。
and table2.code like '001%';
比较快,
条件左边尽量不要使用函数,会破坏索引.
因此like还是适合些.
快一些,而且你可以写成
select * from table1,table2 where table1.id=table2.id and table2.code >='001' and table2.code <='001' + 'z'这样你在索引里包含table2.code会更快一些
TABLE2记录较少,你可以让它做基表即"from table1,table2 ",你现在是对的!如果是三张表以上一般以起中间联系作用的那张表作为基表. 所谓基表就是放在"FROM"最后的那张表.
别的不说,碰到集合查询像IN, NOT IN, EXISTS ..,Oracle 本身会试图把集合查询转换成表连接,如果转换不成,则会照原样查询
另外,IN也会造成全表扫描,table1中有8千条记录就要判断8千次