sql - mysql execution plan explanation -
there following query
select count(*) my_table my_t my_t.c1 = '3' , my_t.c2 = '123'
this table has index on (c1, c2) , both these columns have not null
constraint.
its execution plan:
# id, select_type, table, type, possible_keys, key, key_len, ref, rows, 1, simple, my_t, ref, my_idx, my_idx, 157, const,const, 1, using where; using index
it uses where, purpose? both columns not null index contain records , necessary count them.
am missing something?
the documentation says:
using index
the column information retrieved table using information in index tree without having additional seek read actual row. strategy can used when query uses columns part of single index.
if
extra
column saysusing where
, means index being used perform lookups of key values. withoutusing where
, optimizer may reading index avoid reading data rows not using lookups. example, if index covering index query, optimizer may scan without using lookups.
as far understand above, using index
means reading index specified in key
column enough data needed compute result; there no need read table data. doesn't how index information used.
using where
1 says values read index mentioned in key
column compared against values of columns or constants indicated in ref
column of output. ref
column contains const, const
because values use compare against string constants ('3'
, '123'
).
Comments
Post a Comment