小表驱动大表


1.为什么使用小表驱动大表

  小表驱动大表,小的数据集驱动大的数据集

  因为连接比较消耗时间

  所以,小表写在先查询的地方

select * from employee where id in (select id from department)

  

2.exists

select * from employee e where id exists (select 1 from department d where e.id = d.id)

  

3.in与exists

  区别:

  in是小表驱动大表

  exists是大表驱动小表

 

  说明:

  在上面的2中,department的数据量大于employee,所以使用exists


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM