FIND_IN_SET 性能优化
select v_data.*, GROUP_CONCAT(t_fa.Staff_Name) Staff_Name
from (select REC.Riqi_Date,
REC.Vehicle_Id,
t_vc.Vehicle_No,
REC.DeliveryLoading_Hdr_Id,
t_hd.DeliveryLoading_No,
REC.Operate_staff,
REC.Cart_check_State,
(select a.Value_Desc
from Fd_Field_Dtl a
where a.Field_Name = 'Cart_check_State'
and a.Value_Data = REC.Cart_check_State) Cart_check_StateName,
REC.ElectricalEquipment_State,
REC.Chassis_State,
REC.Engine_state,
REC.Exterior_State,
REC.Created_Time,
REC.Submit_Time,
REC.Repair_Item
from Rec_a REC,
Fd_Vb t_vc,
Bill_Dc t_hd
where REC.Vehicle_Id = t_vc.Vehicle_Id
and t_hd.Operator_Id = '174660684877367'
and REC.DeliveryLoading_Hdr_Id = t_hd.DeliveryLoading_Hdr_Id
and REC.Cart_check_State < 4
order by REC.Riqi_Date desc) v_data
LEFT JOIN Fd_Staff t_fa
on FIND_IN_SET(t_fa.Staff_Id, v_data.Operate_staff) > 0
GROUP BY v_data.DeliveryLoading_Hdr_Id
order by v_data.Riqi_Date;
查看执行计划
+----+--------------------+------------+--------+-----------------------------------------------------------+---------------------------+---------+--------------------------------+-------+-----------------------------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+--------------------+------------+--------+-----------------------------------------------------------+---------------------------+---------+--------------------------------+-------+-----------------------------------------------------------------+
| 1 | PRIMARY | <derived2> | ALL | NULL | NULL | NULL |