sql - mysql query run slow -
i have query
select debtdinar, creditdinar, debtdollar, creditdollar creditdollar, companyid, costcenter, accountnumber, accountname, activityno, activityname, name, if((debtdinar-creditdinar) >= 0.000,(debtdinar-creditdinar),0.000) debtdinarex, if((debtdinar-creditdinar) >= 0.000,0.000,abs(debtdinar-creditdinar)) creditdinarex, if((debtdollar-creditdollar) >= 0.00,(debtdollar-creditdollar),0.00) debtdollarex, if((debtdollar-creditdollar) >= 0.00,0.00,abs(debtdollar-creditdollar)) creditdollarex (select sum(recordsdetails.debtor) debtdinar, sum(recordsdetails.creditor) creditdinar, sum(recordsdetails.debtdollar) debtordollar, sum(recordsdetails.creditdollar) creditdollar, companies.name name, recordsdetails.companyid companyid, costcenter costcenter, accounts.accountnumber accountnumber, accounts.accountname accountname, recordsdetails.activityno activityno, recordsdetails.activityname activityname (records, accounts join (companies left join recordsdetails on((recordsdetails.companyid = companies.companyid)))) left(recordsdetails.accountnumber,1)=accounts.accountnumber , (recordsdetails.companyid = 1) group accounts.accountnumber, costcenter order accounts.sortorder) recordsdetails
it's run 30-60 sec data , it's got more slow when data increase , there idea make query simple
i'd start neatening query. have used mixed joining syntax, missing aliases , renaming temp tables same name real table , result hard follow happening.
are using table records
? appears cross joined in without criteria..
you may able refactor out select (select ... )
well.
once neat , tidy, should run explain ...
, see indexes being used , query may falling down.
Comments
Post a Comment