php - How to optimize Mysql Select Query with Union? -


i working on mysql database innodb storage engine. table structure follows:

table name : archiveincomingsms

enter image description here

index detail of : archiveincomingsms

enter image description here

table name : archiveoutgoingsms enter image description here

index detail of : archiveoutgoingsms enter image description here

above table structure , index detail !

both table have minimum more 1 billion records(rows) respectively.

now problem when execute following sqlquery :

      ( select  id id, `recieved_datetime` `date`, 'mt' type, src_adress msisdn,                text text, char_length(text) qtyofsymbols, 'ok' `status`              archiveincomingsms              1=1               ,  recieved_datetime between '2015-06-14 00:00:00'                                          , '2015-07-14 23:59:59'       )     union        ( select  id id, `send_date` `date`, 'mo' type, scr_adress msisdn,                 text text, char_length(text) qtyofsymbols, 'ok' `status`              archiveoutgoingsms              1=1               ,  send_date between '2015-06-14 00:00:00'                                  , '2015-07-14 23:59:59'       )     order  `date` asc     limit  0 ,100  

above query takes more 30 second time data tables. , 1 have count number of row pagination purpose , take more 30 second time.

overall takes more 1 minute execute. there proper way optimize time ? have take down maximum 5 sec. ! how can possible ? using mysql database !

enter image description here here result of query explain !

image can view open in new tab ! it's small here !


Comments