oracle递归查询效率问题

爱张小哲啊 2021-02-19 08:10:40
小白开发,今天在开发过程中遇到这样一个问题,对业务表进行查询,但需要到配置表中查询到匹配的数据,由于配置表需要进行递归。所以这样写了查询语句: select * from persion a where exists (select 1 from pe_zhi_db where a.user name= code start with id = ‘00000000’ connect by prior id = parent_id) persion表一万条数据,pe_zhi_db表四十万条数据, 该条语句查询了两三分钟。 感觉很慢,就将语句改成了: select * from persion a where exists ( select 1 from (select code from pe_zhi_db start with id = ‘00000000’ connect by prior id = parent_id) where a.username = code) 结果瞬间查询出结果。 百度了一下oracle的递归,递归完成后才会执行where。 两种语句就是写法不同,但效率却差了好多,实在搞不清为什么,求大神指点。
...全文
304 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
nayi_224 2021-02-20
  • 打赏
  • 举报
回复
猜测上面的是对主表每一行都完整执行一遍递归查询,下面用括号括上相当于是将递归查询的结果缓存了起来,然后对这个缓存表正常执行半连接查询

17,082

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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