如何以自动增量字段为主键提高查询性能

时间:2017-03-22 09:46:04

标签: php mysql sql performance

我正在使用以下查询第三方应用程序,这些应用程序似乎花费太多时间在PHP中执行。 Table Structure

SELECT auto_id, customer_id, apply_dt, priority_opt, cust_apl_by, cust_upd_by, cust_upd_dt, agent, second_agent, follow_up, funding_dt, amt_granted, cred_review_fee_amt, cred_review_fee_dt_paid, cred_estab_fee_amt, cred_estab_fee_dt_paid, liq_fee_amt, liq_fee_dt_paid, miscel_fee_amt, miscel_fee_dt_paid, df_cnslt_fee_amt, df_cnslt_fee_date_paid, cred_repair_fee_amt, cred_repair_fee_dt_paid, lead_src, bst_time_to_call, p_psn2, p_fl_nm, p_ph1, p_ph2, p_eml1, p_eml2, p_amt_req, p_cmt, p_fr_nm, p_mi_nm, p_la_nm, p_hm_ph, p_hm_addr, p_ye_addr, p_city, p_state, p_zip, p_dob, p_ss, p_is_us, p_mam_maiden_nm, p_drv_lic, p_unq_id, p_hv_af, p_wh_af, p_hv_dod, p_wh_dod, p_bnk_nm, b_stg, b_leg_nm, b_ent_typ, b_ind_typ, b_fed_tax_id, b_ph, b_fax, b_addr, b_city, b_state, b_zip, b_ye_busi, b_empl, b_reg_state, b_wb_site, b_bnk_nm, b_acpt_cred_card, b_hv_cred_card, b_seeking, b_hv_not_show_cred_card, b_wht_bnk_issu_thm, b_hv_401k_ira, b_how_much, b_cred_premis, b_cred_usr, b_cred_pwd, p2_ph1, p2_ph2, p2_eml, manager, p2_relation, p2_dob, p2_ss, p2_cred_usr, p2_cred_pwd, b_new_buss, p2_hm_addr, p2_city, p2_state, remarks, p_psn3, p3_ph1, p3_ph2, p3_relation, p3_dob, p3_ss, p3_eml, p3_cred_usr, p3_cred_pwd, p3_hm_addr, p3_city, p3_state, p1_cred_usr, p1_cred_pwd, b_facs_no, b_eml, b_acc, b_acc_ph, b_own_lease, b_type, b_addition_addr, b_landlord, b_landlord_ph, b_landlord_fr, b_landlord_to, b_landlord_month_pmt, b_landlord_renew_opt, b_landlord_renew_ye, b_landlord_payment, b_landlord_approx, b_cash, b_amex, b_vs_mc, b_other, b_is_season, b_month_season_begin, b_month_season_to, is_opportunity_yes, p2_zip, p3_zip, drip, last_action_day, drip_start_dt, language, opt_yes_no, opportunity, sms_log_agent, call_log_agent, mail_log_agent, quali_guide_result, quali2_guide_result, p2_quali_guide_result, p2_quali2_guide_result, p3_quali_guide_result, p3_quali2_guide_result, quali_result, rev_total_bal, rev_total_limit, rev_total_ups, rev_total_downs, rev_fund_needed, p2_rev_total_bal, p2_rev_total_limit, p2_rev_total_ups, p2_rev_total_downs, p2_rev_fund_needed, p3_rev_total_bal, p3_rev_total_limit, p3_rev_total_ups, p3_rev_total_downs, p3_rev_fund_needed, keepaneye, p_agency, p2_agency, p3_agency, vendor_priority_opt, cur_credit_report1, cur_credit_report2, cur_credit_report3, quali_range, quali_cond, quali_name, quali_state, p2_quali_range, p2_quali_cond, p2_quali_name, p2_quali_state, p3_quali_range, p3_quali_cond, p3_quali_name, p3_quali_state, quali_range_value, p2_quali_range_value, p3_quali_range_value, max_quali_range_value, max_quali_cond, max_quali_range 
FROM customer_info 
USE INDEX (customer_id) where customer_id='xxxxx'

解释结果:

id  select_type     table   type    possible_keys   key     key_len     ref     rows    Extra   
1   SIMPLE  customer_info   ALL     NULL    NULL    NULL    NULL    1025952     

此表在PHP文件中多次使用。

2 个答案:

答案 0 :(得分:3)

您发布的查询没有WHERE或过滤条件,从解释结果中可以看出它没有使用任何索引。在任何索引列中包含一些过滤条件(where条件)并再次查看查询计划

答案 1 :(得分:0)

没有WHERE子句且没有太多数据的简单选择不应该那么长。连接问题?

如果第三方花了很长时间才能在没有连接问题的情况下做出回应,那么您将无法做任何事情。

只需缓存返回的数据,并每x次刷新一次,与您当前正在执行的操作无关。并且只对您的缓存数据起作用。如果数据是来自MySQL的DataSet,您可以使用SqlChangeMonitoran example here)。