Abfrage-Abfrage mit mehreren Tabellenverbindungen zu viel Zeit trotz der Indizierung
SELECT SUM(sale_data.total_sale) as totalsale, `sale_data_temp`.`customer_type_cy` as `customer_type`, `distributor_list`.`customer_status` FROM `distributor_list` LEFT JOIN `sale_data` ON `sale_data`.`depo_code` = `distributor_list`.`depo_code` and `sale_data`.`customer_code` = `distributor_list`.`customer_code` LEFT JOIN `sale_data_temp` ON `distributor_list`.`address_coordinates` = `sale_data_temp`.`address_coordinates` LEFT JOIN `item_master` ON `sale_data`.`item_code` = `item_master`.`item_code` WHERE `invoice_date` BETWEEN "2017-04-01" and "2017-11-01" AND `item_master`.`id_category` = 1 GROUP BY `distributor_list`.`address_coordinates`
Query neu geschrieben mit der Formatierung.
SELECT SUM(sale_data.total_sale) as totalsale,
sale_data_temp.customer_type_cy as customer_type,
distributor_list.customer_status
FROM distributor_list
LEFT JOIN sale_data
ON sale_data.depo_code = distributor_list.depo_code
and sale_data.customer_code = distributor_list.customer_code
LEFT JOIN sale_data_temp
ON distributor_list.address_coordinates = sale_data_temp.address_coordinates
LEFT JOIN item_master
ON sale_data.item_code = item_master.item_code
WHERE invoice_date BETWEEN "2017-04-01" and "2017-11-01"
AND item_master.id_category = 1
GROUP BY distributor_list.address_coordinates
DESC- Diese Abfrage 7,5 Sekunden bis run.My Anwendung nimmt 3-4 enthält solche queries.Therefore Ladezeit appraches 1 min auf dem Server.
Meine Verkaufsdatentabelle enthält 4.5 Lakh (450K) Datensätze.
Die Verteilerliste enthält 970 Datensätze.
Artikelstamm enthält 7774 Datensätze und sale_data_temp enthält 324 Datensätze.
Ich verwende Indizierung, aber es wird nicht für den Verkauf Datentabelle verwendet.
Alle 4 lakh (400K) Datensätze werden gesucht, wie aus explain sql ersichtlich ist.
Wenn ich die Dauer der BETWEEN-Klausel als Verkauf Daten Tabelle reduziert verwendet Datumsindex ansonsten scannt alle 4 Lakh Zeile.
Die Zeilen zwischen 01-04-2017 und 01-11-2017 sind 84000, aber es scannt noch 4 Lakh Zeilen.
MYSQL EXPLAIN-
Ich habe modifizierte fragt zwei Mal ohne Erfolg. Modifikation 1:
SELECT SUM(sale_data.total_sale) as totalsale, `sale_data_temp`.`customer_type_cy` as `customer_type`, `distributor_list`.`customer_status` FROM `distributor_list` LEFT JOIN `sale_data` ON `sale_data`.`depo_code` = `distributor_list`.`depo_code` and `sale_data`.`customer_code` = `distributor_list`.`customer_code` AND `invoice_date` BETWEEN "2017-04-01" and "2017-11-01" LEFT JOIN `sale_data_temp` ON `distributor_list`.`address_coordinates` = `sale_data_temp`.`address_coordinates` LEFT JOIN `item_master` ON `sale_data`.`item_code` = `item_master`.`item_code` WHERE `item_master`.`id_category` = 1 GROUP BY `distributor_list`.`address_coordinates`
Modifikation 2
SELECT SQL_NO_CACHE SUM(sd.total_sale) AS totalsale, `sale_data_temp`.`customer_type_cy` AS `customer_type` , `distributor_list`.`customer_status` FROM `distributor_list` LEFT JOIN (SELECT * FROM `sale_data` WHERE `invoice_date` BETWEEN "2017-04-01" AND "2017-11-01")sd ON `sd`.`depo_code` = `distributor_list`.`depo_code` AND `sd`.`customer_code` = `distributor_list`.`customer_code` LEFT JOIN `sale_data_temp` ON `distributor_list`.`address_coordinates` = `sale_data_temp`.`address_coordinates` LEFT JOIN `item_master` ON `sd`.`item_code` = `item_master`.`item_code` WHERE `item_master`.`id_category` =1 GROUP BY `distributor_list`.`address_coordinates`
HIER MEIN INDIZES AUF VERKAUF DATA-Tabelle
'func' macht es so, als hätten Sie einige Inkonsistenzen in Datentypen und/oder Kollatierungen. –
Helfen Sie uns - formatieren Sie die beiden Auswahlmöglichkeiten und zeigen Sie auf die Unterschiede. –