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 `MsBarang` ADD INDEX `msbarang_idx_kodebarang` (`KodeBarang`);
ALTER TABLE `PenjualanDTL` ADD INDEX `penjualandtl_idx_kodebarang` (`KodeBarang`);
ALTER TABLE `SPKJahit` ADD INDEX `spkjahit_idx_nospkjahit` (`NoSPKJahit`);
ALTER TABLE `StokBS` ADD INDEX `stokbs_idx_kodebarang` (`KodeBarang`);
ALTER TABLE `es_temp1` ADD INDEX `es_temp1_idx_kodebarang` (`KodeBarang`);
ALTER TABLE `es_temp2` ADD INDEX `es_temp2_idx_kodebarang` (`KodeBarang`);
ALTER TABLE `es_temp3` ADD INDEX `es_temp3_idx_kodebarang` (`KodeBarang`);
ALTER TABLE `es_temp4` ADD INDEX `es_temp4_idx_kodebarang` (`KodeBarang`);
ALTER TABLE `es_temp5` ADD INDEX `es_temp5_idx_kodebarang` (`KodeBarang`);
ALTER TABLE `es_temp6` ADD INDEX `es_temp6_idx_kodebarang` (`KodeBarang`);
ALTER TABLE `es_temp7` ADD INDEX `es_temp7_idx_kodebarang` (`KodeBarang`);
ALTER TABLE `es_temp8` ADD INDEX `es_temp8_idx_kodebarang` (`KodeBarang`);
SELECT
a.NoSPKJahit AS 'TglSPKJahit',
c.TglSPKJahit AS 'spkJahit',
a.SeriBarang AS 'KodeSeri',
b.NamaBarang AS 'NamaBarang',
a.JmlTotalPotong - a.JmlTotalRusakSablon AS 'JumlahSPKJahit',
a.JmlTotalSelesaiJahit AS 'JumlahHasilJahit',
es_temp1.JumlahPenjualan,
es_temp2.JumlahRetur,
es_temp3.JumlahRusak,
(a.JmlTotalSelesaiJahit - (SELECT
sum(PenjualanDTL.Qty)
FROM
PenjualanDTL
WHERE
PenjualanDTL.KodeBarang = a.KodeBarang) + ((SELECT
sum(JumlahRetur)
FROM
StokBS
WHERE
StokBS.KodeBarang = a.KodeBarang) - (SELECT
sum(JumlahRusak)
FROM
StokBS
WHERE
StokBS.KodeBarang = a.KodeBarang))) AS 'SisaBarang',
es_temp4.Gudang,
es_temp5.GudangAtas,
es_temp6.Mobil,
es_temp7.MissMode,
es_temp8.SilverLeafM
FROM
DetilBarang a
LEFT JOIN
MsBarang b
ON b.KodeBarang = a.KodeBarang
LEFT JOIN
SPKJahit c
ON c.NoSPKJahit = a.NoSPKJahit
LEFT JOIN
es_temp1
ON es_temp1.KodeBarang = a.KodeBarang
LEFT JOIN
es_temp2
ON es_temp2.KodeBarang = a.KodeBarang
LEFT JOIN
es_temp3
ON es_temp3.KodeBarang = a.KodeBarang
LEFT JOIN
es_temp4
ON es_temp4.KodeBarang = a.KodeBarang
LEFT JOIN
es_temp5
ON es_temp5.KodeBarang = a.KodeBarang
LEFT JOIN
es_temp6
ON es_temp6.KodeBarang = a.KodeBarang
LEFT JOIN
es_temp7
ON es_temp7.KodeBarang = a.KodeBarang
LEFT JOIN
es_temp8
ON es_temp8.KodeBarang = a.KodeBarang