encounter such a scenario in the actual business:
there are three tables wf_cr_borrow_order, wf_admin_last_check_record_content and wf_cr_replan, and the amount of data is wf_cr_borrow_order (755424), wf_admin_last_check_record_content (54253) and wf_cr_replan (321744), respectively. The three tables are linked by the order number, enter the function list and hold the data of the successful wf_cr_borrow_order.br_state= loan and the wf_cr_borrow_order.repayment_state in (overdue, overdue payment) of the three tables, and then display them in reverse order according to wf_admin_last_check_record_content.create_time,wf_admin_last_check_record_content.update_time,wf_cr_borrow_order.update_time. The list shows 25 items, the query time is about 3 seconds +, and the total number of count data items is about 0.9 seconds +.
the question for advice is:
1. The result of explain is how does Using where; Using temporary; Using filesort, avoid file sorting?
Solutions you have tried
1. The corresponding fields of the associated table are indexed.
2. It is certain that if the sorting of the two fields of wf_admin_last_check_record_content.create_time,wf_admin_last_check_record_content.update_time is removed, the query speed and the rows returned by explain will be significantly improved. But the business needs can not be removed!
currently used query SQL:
EXPLAIN
SELECT
cbo.br_order_no,
cbo.loan_date,
cbo.replan_repay_time,
cbo.final_settle_date,
cbo.penalty_money,
cbo.applied_amount,
cbo.br_inst,
cbo.repay_total_default,
cbo.cut_total,
cbo.br_syje,
cbo.br_txje,
cbo.real_repayment_money,
cbo.br_state,
cbo.repayment_state,
cbo.customer_id,
cbo.customer_version,
cbo.param2,
cbo.collect_id,
cbo.product_id,
r.total_penalty_days
FROM
`wf_cr_borrow_order` AS cbo
LEFT OUTER JOIN wf_admin_last_check_record_content c ON cbo.br_order_no = c.br_order_no
LEFT OUTER JOIN wf_cr_replan r ON cbo.br_order_no = r.br_order_no
WHERE
(
cbo.`br_state` = 8
AND cbo.`repayment_state` IN ("3", "4")
)
ORDER BY
c.id,
c.create_time,
cbo.`last_update_time` DESC
LIMIT 0,
25;
result from Explain:
desired results:
1. If you can optimize on the basis of the existing SQL, you want to optimize the file sorting.
2. If there is no room for optimization in the existing SQL, please point out that there are any other optimization solutions or solutions for this scenario.
I hope all the bosses will not hesitate to give us advice [holding fists]