レポートに使用される mysql ビューがあります。つまり、タラの注文、前払いの注文、タラの注文額、前払いの注文額、総計、および 1 日の計算数を計算し、5 つのテーブルを結合します。あまりにも遅くなりすぎています。ビューを使用する以外に、このような要件を実行するためのより良い方法はありますか。または、そのような種類の要件をより速くする方法
SELECT
DATE_FORMAT(`orders`.`placed_date`,'%Y-%m%-%d 00:00:00') AS `orderdate`,
DATE_FORMAT(`orders`.`placed_date`,'%Y-%m%-%d') AS `orderdt`,
COUNT(DISTINCT `orders`.`order_id`) AS `orderscount`,
SUM(`order_item`.`quantity`) AS `qunty`,
SUM((`order_item`.`quantity` * `order_item`.`a_unitprice`)) AS `price`,
COUNT(DISTINCT (CASE `payment_type`.`a_name` WHEN 'COD' THEN `orders`.`order_id` END)) AS `codorderscount`,
COUNT(DISTINCT (CASE `payment_type`.`a_name` WHEN 'Prepaid' THEN `orders`.`order_id` END)) AS `prepaidorderscount`,
ROUND(SUM(IF((`payment_type`.`a_name` = 'COD'),ROUND((((((`order_item`.`quantity` * `order_item`.`a_unitprice`) - IFNULL(ABS(`getdisc_function`(`order_item`.`order_item_id`,`order_item`.`quantity`)),0)) + IFNULL(`getgiftwrap_amount_function`(`order_item`.`order_item_id`,`order_item`.`quantity`),0)) + IFNULL(`order_item`.`sales_tax`,0)) + IFNULL(`getshipping_charge_function`(`order_item`.`order_item_id`,`order_item`.`quantity`),0)),2),0)),0) AS `cod`,
ROUND(SUM(IF((`payment_type`.`a_name` = 'Prepaid'),ROUND((((((`order_item`.`quantity` * `order_item`.`a_unitprice`) - IFNULL(ABS(`getdisc_function`(`order_item`.`order_item_id`,`order_item`.`quantity`)),0)) + IFNULL(`getgiftwrap_amount_function`(`order_item`.`order_item_id`,`order_item`.`quantity`),0)) + IFNULL(`order_item`.`sales_tax`,0)) + IFNULL(`getshipping_charge_function`(`order_item`.`order_item_id`,`order_item`.`quantity`),0)),2),0)),0) AS `Prepaid`,
ROUND((SUM(IF((`payment_type`.`a_name` = 'COD'),ROUND((((((`order_item`.`quantity` * `order_item`.`a_unitprice`) - IFNULL(ABS(`getdisc_function`(`order_item`.`order_item_id`,`order_item`.`quantity`)),0)) + IFNULL(`getgiftwrap_amount_function`(`order_item`.`order_item_id`,`order_item`.`quantity`),0)) + IFNULL(`order_item`.`sales_tax`,0)) + IFNULL(`getshipping_charge_function`(`order_item`.`order_item_id`,`order_item`.`quantity`),0)),2),0)) + SUM(IF((`payment_type`.`a_name` = 'Prepaid'),ROUND((((((`order_item`.`quantity` * `order_item`.`a_unitprice`) - IFNULL(ABS(`getdisc_function`(`order_item`.`order_item_id`,`order_item`.`quantity`)),0)) + IFNULL(`getgiftwrap_amount_function`(`order_item`.`order_item_id`,`order_item`.`quantity`),0)) + IFNULL(`order_item`.`sales_tax`,0)) + IFNULL(`getshipping_charge_function`(`order_item`.`order_item_id`,`order_item`.`quantity`),0)),2),0))),0) AS `grandtotal`,
ROUND((ROUND((SUM(IF((`payment_type`.`a_name` = 'COD'),ROUND((((((`order_item`.`quantity` * `order_item`.`a_unitprice`) - IFNULL(ABS(`getdisc_function`(`order_item`.`order_item_id`,`order_item`.`quantity`)),0)) + IFNULL(`getgiftwrap_amount_function`(`order_item`.`order_item_id`,`order_item`.`quantity`),0)) + IFNULL(`order_item`.`sales_tax`,0)) + IFNULL(`getshipping_charge_function`(`order_item`.`order_item_id`,`order_item`.`quantity`),0)),2),0)) + SUM(IF((`payment_type`.`a_name` = 'Prepaid'),ROUND((((((`order_item`.`quantity` * `order_item`.`a_unitprice`) - IFNULL(ABS(`getdisc_function`(`order_item`.`order_item_id`,`order_item`.`quantity`)),0)) + IFNULL(`getgiftwrap_amount_function`(`order_item`.`order_item_id`,`order_item`.`quantity`),0)) + IFNULL(`order_item`.`sales_tax`,0)) + IFNULL(`getshipping_charge_function`(`order_item`.`order_item_id`,`order_item`.`quantity`),0)),2),0))),0) / COUNT(DISTINCT `orders`.`order_id`)),0) AS `avgtickectsize`,
ROUND((ROUND((SUM(IF((`payment_type`.`a_name` = 'COD'),ROUND((((((`order_item`.`quantity` * `order_item`.`a_unitprice`) - IFNULL(ABS(`getdisc_function`(`order_item`.`order_item_id`,`order_item`.`quantity`)),0)) + IFNULL(`getgiftwrap_amount_function`(`order_item`.`order_item_id`,`order_item`.`quantity`),0)) + IFNULL(`order_item`.`sales_tax`,0)) + IFNULL(`getshipping_charge_function`(`order_item`.`order_item_id`,`order_item`.`quantity`),0)),2),0)) + SUM(IF((`payment_type`.`a_name` = 'Prepaid'),ROUND((((((`order_item`.`quantity` * `order_item`.`a_unitprice`) - IFNULL(ABS(`getdisc_function`(`order_item`.`order_item_id`,`order_item`.`quantity`)),0)) + IFNULL(`getgiftwrap_amount_function`(`order_item`.`order_item_id`,`order_item`.`quantity`),0)) + IFNULL(`order_item`.`sales_tax`,0)) + IFNULL(`getshipping_charge_function`(`order_item`.`order_item_id`,`order_item`.`quantity`),0)),2),0))),0) / SUM(`order_item`.`quantity`)),0) AS `avgitemprice`,
ROUND((SUM(`order_item`.`quantity`) / COUNT(DISTINCT `orders`.`order_id`)),0) AS `avgitemperorder`,
COUNT(DISTINCT (CASE `status`.`status_code` WHEN 'S' THEN `orders`.`order_id` WHEN 'DE' THEN `orders`.`order_id` END)) AS `dispached`,
(COUNT(DISTINCT `orders`.`order_id`) - COUNT(DISTINCT (CASE `status`.`status_code` WHEN 'S' THEN `orders`.`order_id` WHEN 'DE' THEN `orders`.`order_id` END))) AS `notdispached`
FROM (((((`orders`
JOIN `order_item`
ON ((`order_item`.`order_id` = `orders`.`order_id`)))
JOIN `payment_instruction`
ON ((`payment_instruction`.`order_id` = `orders`.`order_id`)))
JOIN `subpayment_type`
ON ((`payment_instruction`.`payment_method` = `subpayment_type`.`subpayment_type_id`)))
JOIN `payment_type`
ON (((`payment_type`.`payment_type_id` = `subpayment_type`.`payment_type_id`)
AND (`payment_type`.`a_name` = ('Prepaid'
OR 'COD')))))
LEFT JOIN `status`
ON ((`status`.`a_statusid` = `orders`.`orderstatus_id`)))
WHERE (`status`.`status_code` NOT IN('PP','PE','X'))
GROUP BY DATE_FORMAT(`orders`.`placed_date`,'%y-%m%-%d')