???????????????
?????????????????????cost???????explain?????????explain??????????????????????????????????????
????Explain???
?????????????SQL??????explain??
????select id from r_ibeacon_biz_device_d where ftime >= 20151126 and ftime <= 20151126 and biz_id = 11602 limit 50;

????IDX_BID_FTIME???r_ibeacon_biz_device_d???????????????
????Biz_id??ftime???bigint?????
???????????????????????ε???????
????- type:????????÷??
????eq_ref      …  ??????????????????
????ref          …  ????(??)???
????range        …  ??????Χ?(BETWEEN??IN??>=??LIKE)???????
????index        …  ????????
????all           …  ??????
?????????????????????????????Χ??裬????type?range
????- possible_keys?????ò?????????б???????????????????????β????
????- key: ???????????????????????????IDX_BID_FTIME
????- key_len??????????????????
????null    1???
????tinyint  1???
????int    4???
????bigint  8???
????double  8???
????datetime 8???
????timestamp 4???
????varchr(10)???????????NULL: 10*(Character Set??utf8=3??gbk=2??latin1=1)+1(NULL)+2(?????)
????char(10)????????????NULL: 10*(Character Set??utf8=3??gbk=2??latin1=1)+1(NULL)
???????????????????????????key_len?18??????8???(biz_id bigint)+1???(biz_id?????null)+8???(ftimebigint)+1???(ftime?????null)????????β?????????????????????μ?????
????- rows????????????????
????Explain????????
????????????????????????????С??壬?漰?????SQL??
???????SQL?????????????select d.id from r_ibeacon_biz_page_d d where d.ftime >= 20151126 and d.ftime <= 20151126 and d.biz_id = 11023 and d.page_id = 778495 limit 0??20??
??????r_ibeacon_biz_page_d ??????????????£?
????ftime  bigint(20)
????biz_id  bigint(20)
????page_id varchar(200)
???????????IDX_BID_PID_FTIME
????Explain???????

???????????explain???????????????????SQL“???????”????????????????rows??????????????????“????”ok????????????????塣
??????????飺
???????????????????explain?е?type??????ref?????????????????????????????????range?????????
??????Σ????key_len??9??????????Щ?????????????С?????????????????9????biz_id?????????????SQL???????????????????????biz_id??Ρ???????
??????????“desc r_ibeacon_biz_page_d”???????????????Σ???????page_id???????????varchar?????SQL??page_id=11023?????????????????????Υ???????????????????????SQL“page_id=11023”?“page_id=‘11023’”?????????

???????????type=range??key_len=621?????????????????????????????page_id???????bigint??????????????????????
????Explain????????????????????????SQL??????????????????????????SQL????????????????????????????????profile??optimizer_trace??????????????????????????
???????????????
????- Range????????????
???????????
????- Order by?????????
???????????????????????????
????SQL queries with an order by clause don’t need to sort the result explicitly if the relevant index already delivers the rows in the required order. That means the same index that is used for the where clause must also cover the order by clause.
?????????仰????????????????????????????????????????????????order by??????????????????????
????- order by?????
????????????????????????????(??????????д??)
????- limit offset?????
?????????offset?????where???????????С?????ο????????Efficient Pagination Using MySQL??
????- ?????????????????????????????????
??????????????: int vs char??varchar????varchar??32??vs varchar(64)
??????????????£??漰????????????????????????