In case you have your own slow SQL query, you can optimize it automatically here.
For the query above, the following recommendations will be helpful as part of the SQL tuning process.
You'll find 3 sections below:
ALTER TABLE `deal_master` ADD INDEX `deal_master_idx_swap_lcr_custo_agree_statu_sales` (`swap_commitment`,`lcr_zone`,`customer_interconnect`,`agreement_no`,`status`,`sales_person`);
ALTER TABLE `trans_details_buy` ADD INDEX `trans_buy_idx_cdr_id` (`cdr_id`);
ALTER TABLE `trans_details_sell` ADD INDEX `trans_sell_idx_lcr_zon_sig_net_cdr_id_start` (`lcr_zone`,`sig_netgroup`,`cdr_id`,`start_position`);
SELECT
m.agreement_no,
m.status,
m.sales_person,
m.swap_carrier,
m.swap_commitment,
m.zone,
m.lcr_zone,
m.customer_interconnect,
SUBSTRING(CAST(m.start_pos AS nvarchar),
1,
4) + '-' + SUBSTRING(CAST(m.start_pos AS nvarchar),
5,
2) + '-' + SUBSTRING(CAST(m.start_pos AS nvarchar),
7,
2) start_date,
SUBSTRING(CAST(m.end_pos AS nvarchar),
1,
4) + '-' + SUBSTRING(CAST(m.end_pos AS nvarchar),
5,
2) + '-' + SUBSTRING(CAST(m.end_pos AS nvarchar),
7,
2) end_date,
m.target_minutes,
m.target_sell_rate,
m.target_buy_rate,
m.target_sales,
m.target_cost,
m.target_profit,
SUM(s.quantized_duration) / 60 DG_minute,
SUM(s.charge) DG_sales,
SUM(b.charge) DG_cost
FROM
deal_master m,
trans_details_sell s,
trans_details_buy b
WHERE
m.lcr_zone = s.lcr_zone
AND m.customer_interconnect = s.sig_netgroup
AND m.swap_commitment = 'Sell'
AND s.cdr_id = b.cdr_id
AND s.start_position BETWEEN m.start_pos AND m.end_pos
GROUP BY
m.agreement_no,
m.status,
m.sales_person,
m.swap_carrier,
m.swap_commitment,
m.zone,
m.lcr_zone,
m.customer_interconnect,
m.start_pos,
m.end_pos,
m.target_minutes,
m.target_sell_rate,
m.target_buy_rate,
m.target_sales,
m.target_cost,
m.target_profit
ORDER BY
1