title: Optimizing mysql IN query having large values
body: <p>I have a mysql query like </p>
  
  <pre><code> SELECT `tbl_ticket`.`id`, `tbl_ticket`.`hd_user_username`, 
  `tbl_ticket`.`hd_user_email`, `tbl_ticket`.`ticket_title`, 
  `tbl_complain_type`.`complains` FROM `tbl_ticket` LEFT JOIN 
  `tbl_ticket_complain` ON tbl_ticket_complain.ticket_id=tbl_ticket.id 
  LEFT JOIN `tbl_complain_type` ON tbl_complain_type.id=tbl_ticket_complain.complain_id 
  LEFT JOIN `tbl_assignment` ON tbl_assignment.ticket_id=tbl_ticket.id 
  WHERE ((((`hd_user_username` LIKE '%searchterm%') 
  AND (`tbl_assignment`.`id` IN ($array))) 
  OR (`hd_user_email`='searchterm')) 
  OR (`ticket_title`='searchterm')) OR (`tbl_complain_type`.`complains`='searchterm')
  
  $array contains around 7000 values like `$array=array(1,2,3,..)`
  </code></pre>
  
  <p>This query takes around 8 seconds  to execute. Is there any alternative solution for this query ?
  The value of $array is got from another query</p>
  
  <pre><code>select max(id) from tbl_assignment group by ticket_id
  </code></pre>
  
  <p>The slowness of query is due to  multiple joins between tables</p>