着急,sql优化问题~求高手

stevenzxl 2011-03-24 08:21:32
以前一直写sql从来没做过优化,这次碰到了傻了,感觉没啥问题啊,但是人家说效率低,可以提高。
不知道怎么办,求助高手~
1.select a from table where b <> 'aaaa' (table without index)
2.select * from table where b like '%a%'
3.select name from person where birthday in (select birthday from table)
4.select * from table where a = 10
我就知道第二个应该用全文索引,第三个是不是用exist代替in啊
其他两个完全没概念,坐等高手指点~
...全文
93 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
秋雨飘落 2011-03-24
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 stevenzxl 的回复:]
引用 3 楼 zftang 的回复:
1.select a from table where b <> 'aaaa' (table without index)
2.select * from table where b like '%a%'

select * from table where instr(b,-1,'a')
3.select name from person wher……
[/Quote]

第一个就要看你其它的值是什么了,如果其它的值不多,可以写成 = '' or = '' or 这个方法,不用 不等于,然后再增加个索引,该给分啦
stevenzxl 2011-03-24
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 psufnxk2008 的回复:]
若1和4是经常用到的话,会不会是想让你用成 绑定变量啊???
[/Quote]

我也不知道,1的原文是这样的,select 'not found' from userTable where memberid <> 'aaaa'
我感觉能动的地方也就是'not found' 和后面的不等于号了。
stevenzxl 2011-03-24
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 zftang 的回复:]
1.select a from table where b <> 'aaaa' (table without index)
2.select * from table where b like '%a%'

select * from table where instr(b,-1,'a')
3.select name from person where birthday in (select birthday from table)

select name from person a where exists (select 1from table b where a.birthday = b.birthday )

4.select * from table where a = 10
----这个a是什么类型,如果是varchar2,就改为‘10’
[/Quote]
a确实是varchar2类型的,这个问题解决了,第一个问题怎么解决呢?
psufnxk2008 2011-03-24
  • 打赏
  • 举报
回复
若1和4是经常用到的话,会不会是想让你用成 绑定变量啊???
秋雨飘落 2011-03-24
  • 打赏
  • 举报
回复
1.select a from table where b <> 'aaaa' (table without index)
2.select * from table where b like '%a%'

select * from table where instr(b,-1,'a')
3.select name from person where birthday in (select birthday from table)

select name from person a where exists (select 1from table b where a.birthday = b.birthday )

4.select * from table where a = 10
----这个a是什么类型,如果是varchar2,就改为‘10’
stevenzxl 2011-03-24
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 jacklee1981 的回复:]
如果不更改Table schema
好像只有第三个可以改

select name from person a where exists (select 1from table b where a.birthday = b.birthday )
[/Quote]

我就知道第三个怎么优化,我想知道的是其他几个,尤其是1,4
jacklee1981 2011-03-24
  • 打赏
  • 举报
回复
如果不更改Table schema
好像只有第三个可以改

select name from person a where exists (select 1from table b where a.birthday = b.birthday )

3,491

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 高级技术相关讨论专区
社区管理员
  • 高级技术社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧