Mysql Improve Search Performance with wildcards (%%)

后端 未结 6 774
青春惊慌失措
青春惊慌失措 2020-11-30 10:24

Below is a query I use for searching a person by email

  SELECT *
    FROM phppos_customers
    JOIN phppos_people ON phppos_customers.person_id = phppos_peo         


        
6条回答
  •  一个人的身影
    2020-11-30 10:49

    You will not be able to make it faster with LIKE just like everyone says (about the % at the beginning), but you can improve it a little by joining after you filter your people first.

    SELECT *
      FROM (SELECT * 
              FROM `phppos_customers`
             WHERE `deleted` = 0
               AND  `email`  LIKE '%f%') `t_customers`
      JOIN `phppos_people` ON `t_customers`.`person_id`=`phppos_people`.`person_id`
     ORDER BY `email` asc
    

提交回复
热议问题