複数のテーブルと1つのビューを結合するというかなり複雑なビューがあります。これは単純ですが、数百万のレコードを処理する必要があります。
SELECT wo.id_primary AS id_primary,
wo.id_station AS id_station,
wo.id_stage AS id_stage,
wo.id_type AS id_type,
wo.id_options AS id_options,
wo.id_warehouse AS id_warehouse,
wo.id_customer AS id_customer,
wo.id_manufacturer AS id_manufacturer,
wo.date_advanced AS date_advanced,
wo.date_received AS date_received,
wo.date_approved AS date_approved,
wo.date_promised AS date_promised,
wo.date_inspected AS date_inspected,
wo.date_scheduled AS date_scheduled,
wo.date_completed AS date_completed,
sh.date_shipped AS date_shipped,
wo.rpi_revision AS rpi_revision,
wo.rpi_number AS rpi_number,
wo.purchase_order AS purchase_order,
wo.serial_number AS serial_number,
wo.model_number AS model_number,
wo.part_number AS part_number,
wo.part_name AS part_name,
wo.quantity AS quantity,
wo.status AS status,
wo.quote AS quote,
wo.notes AS notes,
sm.name AS manufacturer_name,
wh.name AS warehouse_name,
sc.name AS customer_name,
ss.name AS station_name,
sc.certs AS customer_certifications,
sc.address1 AS customer_address,
sc.city AS customer_city,
sc.email AS customer_email,
sc.phone1 AS customer_phone,
sc.postal AS customer_postal,
sc.fax AS customer_fax,
sh.shipped AS shipped,
sh.waybill AS waybill,
sh.invoice AS invoice,
wq.type_currency AS type_currency,
wq.date_quoted AS date_quoted,
wq.grand_total AS grand_total,
Round(( ( sh.date_shipped - IF(( wo.date_approved =
0 ), sh.date_shipped, wo.date_approved) ) /
86400 ), 2) AS TAT,
ws.stations AS stations
FROM aerospace_erp.erp_workorder wo
LEFT JOIN aerospace_erp.system_manufacturers sm
ON wo.id_manufacturer = sm.id_primary
LEFT JOIN aerospace_erp.system_stations ss
ON wo.id_station = ss.id_primary
LEFT JOIN aerospace_erp.crm_customer sc
ON wo.id_customer = sc.id_primary
LEFT JOIN aerospace_erp.list_workorder_warehouse wh
ON wo.id_warehouse = wh.id_primary
LEFT JOIN aerospace_erp.erp_shipping sh
ON wo.id_primary = sh.id_workorder
LEFT JOIN aerospace_crm.crm_quoting wq
ON wo.id_primary = wq.id_workorder
LEFT JOIN aerospace_erp.erp_workorder_scope ws
ON wo.id_primary = ws.id_primary
これもビューにあります。erp_workorder_scopeはネストされたVIEWであり、シンプルですが、毎回処理する必要のあるデータ量が多いため、かなりの時間がかかります。
上記のビュー全体は、erp_workorder_scopeJOINなしで約15秒または約1.5秒で実行されます
15秒は許容できますが、ビューにORDER BY xxxを追加すると、文字通り45分間実行されます。
この値は、ユーザーが何を並べ替えるかによっても変わるため、この基準をVIEW自体にハードコーディングすることはできません。
何か案は?