sql - Mysql Indexing problem with multiple 'or' and 'and' -



sql - Mysql Indexing problem with multiple 'or' and 'and' -

i've big database beingness used record events occurring. it's ticketing system. now, since stored info different status know action on ticket in same column i've utilize multiple 'or' in statement know current status in ticket.

for example: 1 ticket opened, 2 acknowledgement, 3 event closed. query select events 1,2,3 be:

select * tbl_name status in (1, 2, 3) , event_id = 1;

i've created indexes id field, , index event_status event_id , status field.

now, when run explain on query doesn't utilize event_status index rather uses other existing index event_status_dept consist of event_id, status , department.

if utilize 2 fields in in i.e 'in (1,2)' statement, uses event_status index otherwise uses other index i.e event_status_dept. don't know wrong statement.

i don't think wrong query. optimizer uses best index can find according conditions in query , statistics holds. index not effective if more percent of records satisfy condition.

example: if optimizer's statistics 5% of events in table of types 1,2, effective index , utilize it. if 70% of events of types 1,2,3, index not effective , optimizer may utilize index or no index @ all.

mysql sql indexing

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -