Very simple mysql query not using index -
sorting of mysql table not use index , don't know why.
i've got:
create table if not exists `test` ( `a` int(11) not null, `b` int(11) not null, key `kk` (`a`) ) engine=myisam default charset=utf8;
and this:
explain select * test order
as this
explain select * test use index ( kk ) order
gives me this:
id select_type table type possible_keys key key_len ref rows 1 simple test null null null null 10009 using filesort
i'd not see filesort, , use key kk sort table. doing wrong?
thank posts guys, answer question! however, not undestand meant "table scan" , "filesort"? if selecting fields , rows of table, isn't faster sort table 1 column walking in o(n) internal tree of index of column (and looking in table file columns requested, in o(1) each row => index file stores each row's physical position in table file, or?), sort e.g. quick sort in o(n * log n) (potentially) randomly stored rows in table file, without touching index? guess understanding of how indexes work in mysql wrong.
- you're selecting rows
- you're selecting columns
following said above - mysql estimates more efficient use full scan.
to using index need add where
limit reasonable number of rows returned (say 50)
Comments
Post a Comment