????rows???????????????????????????????????????????????????order by + limit???????????????????????????????SQL?????????order by ?? limit?????????????????????????
????select
????count(*)
????from
????contact c 
????inner join
????contact_branch cb
????on  c.id = cb.contact_id 
????inner join
????branch_user bu
????on  cb.branch_id = bu.branch_id
????and bu.status in (
????1??
????2) 
????inner join
????org_emp_info oei
????on  oei.data_id = bu.user_id
????and oei.node_left >= 2875
????and oei.node_right <= 10802
????and oei.org_category = - 1 
????+----------+
????| count(*) |
????+----------+
????|   778878 |
????+----------+
????1 row in set (5.19 sec)
???????????????????????778878?????????????70??????????????????????????????????????????????????·???????contact??created_time????????join??????????
???????????????????????????straight_join?????
????select
????c.id??
????c.name??
????c.position??
????c.sex??
????c.phone??
????c.office_phone??
????c.feature_info??
????c.birthday??
????c.creator_id??
????c.is_keyperson??
????c.giveup_reason??
????c.status??
????c.data_source??
????from_unixtime(c.created_time) as created_time??
????from_unixtime(c.last_modified) as last_modified??
????c.last_modified_user_id
????from
????contact c
????where
????exists (
????select
????1
????from
????contact_branch cb
????inner join
????branch_user bu
????on cb.branch_id = bu.branch_id
????and bu.status in (
????1??
????2)
????inner join
????org_emp_info oei
????on oei.data_id = bu.user_id
????and oei.node_left >= 2875
????and oei.node_right <= 10802
????and oei.org_category = - 1
????where
????c.id = cb.contact_id
????)
????order by
????c.created_time desc limit 0 ??
????10;
??????????Ч?? ?????1ms?????????13000????
????10 rows in set (0.00 sec)
?????????????????????????????????????????????????????join????join?????????????????????????????????????????????limit????????й??????mysql??????????????10?????????????join??????????????10???????????10???????join????????????join??????????????????????????????????????????????????????mysql?????????????10???????????????????????
?????ò????????SQL??????
????select
????sql_no_cache   c.id??
????c.name??
????c.position??
????c.sex??
????c.phone??
????c.office_phone??
????c.feature_info??
????c.birthday??
????c.creator_id??
????c.is_keyperson??
????c.giveup_reason??
????c.status??
????c.data_source??
????from_unixtime(c.created_time) as created_time??
????from_unixtime(c.last_modified) as last_modified??
????c.last_modified_user_id   
????from
????contact c  
????where
????exists (
????select
????1       
????from
????contact_branch cb        
????inner join
????branch_user bu                    
????on  cb.branch_id = bu.branch_id                    
????and bu.status in (
????1??
????2)               
????inner join
????org_emp_info oei                          
????on  oei.data_id = bu.user_id                          
????and oei.node_left >= 2875                          
????and oei.node_right <= 2875                          
????and oei.org_category = - 1               
????where
????c.id = cb.contact_id          
????)       
????order by
????c.created_time desc  limit 0 ??
????10;
????Empty set (2 min 18.99 sec)
????2 min 18.99 sec??????????????????????mysql??nested loop?????????????????????????????????????????????????????????????????????
??????????????????????????????????????????????????????????????????SQL????????????Щ?????????????????????????????????????????????????????????SQL?????????????????????????????case??????????????????????????
?????????????????????????????????Щ?????????????????????????????????????1000?У??漰??16????join??“????SQL”????????????????????????????????????????????????????varchar?????????д???????????????????????????????????????????????????Щ???????????????????????????????????????????????????Щ??????????????
????д???????
????????????????????????????MySQL???????????????????Щ??????;?????????????????????????????????????????????????????????????κ?????????????????????????????????????MySQL?????????????Google/FaceBook/Taobao????????????????????????????????y???????е????“??????????????????д???????”
?????ο?
?????ο????????£?
????1.????????MySQL??
????2.?????????????????