更新时间:2018-10-11 15:27作者:王华老师
1/26 的数据和 1/6 的数据找交集的速度要比 1/52 的数据和 1/3 的数据找交集速度要慢。
select a.member_no,a.firstname,b.region_nofrom(select m.member_no, m.firstname from dbo.member as mwhere m.firstname like 'k%' -- 1/26 数据) a,
(select m.member_no, m.region_no from dbo.member as mwhere m.region_no > 6 and m.member_no < 5000-- 1/3 * 1/ 2 数据) bwhere a.member_no = b.member_no
当然,我们要学习sql 如何优化的话,就会用到查询语句中的一个功能,指定查询使用哪个索引来进行。
比如下面的查询语句
select m.member_no, m.firstname, m.region_nofrom dbo.member as m with (index (0))where m.firstname like 'k%' and m.region_no > 6 and m.member_no < 5000go
select m.member_no, m.firstname, m.region_nofrom dbo.member as m with (index (1))where m.firstname like 'k%' and m.region_no > 6 and m.member_no < 5000goselect m.member_no, m.firstname, m.region_nofrom dbo.member as m with (index (membercovering3))where m.firstname like 'k%' and m.region_no > 6 and m.member_no < 5000goselect m.member_no, m.firstname, m.region_nofrom dbo.member as m with (index (memberfirstname, member_region_link))where m.firstname like 'k%' and m.region_no > 6 and m.member_no < 5000go