Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
jose_c27
Starting Member
2 Posts |
Posted - 2010-10-07 : 11:33:07
|
Hello everyone, this is my first post.. im from dominican republic.A few days ago I ran the Database Engine Tuning Advisor on my database and this gave me some tips to create some indexes and statistics and decided to implement these recommendations, the first day after implemented these recommendations, all was well until I had to run a query for a daily process that I have and this experiment a 200% degradation in run time, so I decided to delete all indexes and statistics created by the tuning advisor, rebuild indexes and update statistics the entire database, but I am still experiencing the same problem. Any suggestions? SELECT A.ACQUIRERINSTITUTIONID,A.MERCHANTID,A.CARDACQID,A.CLEARINGINSTITUTIONID,C.BANKCODE,C.BANKACCOUNT,C.BANKACCOUNTTYPE,C.BANKACCOUNTPERCENTAGE,C.PAYMENTFORM,A.CURRENCY FROM INTERCHG A,MERCHANT B,BANKACCOUNTSBYMIDCAIDCI C,PAYMENTCYCLES D WHERE A.MERCHANTID=B.MERCHANTID AND B.PAYMENTCYCLECODE=D.PAYMENTCYCLECODE AND substring(D.PAYMENTCYCLEDAYS,datepart(dw,'2010-09-30'),1)='1' AND B.PAYMENTGROUPINGLEVEL='2' AND A.MERCHANTID=C.MERCHANTID AND A.CARDACQID=C.CARDACQID AND A.CLEARINGINSTITUTIONID=C.CLEARINGINSTITUTIONID AND A.PAYED='0' AND A.PRESENTED='1' AND A.SETTLED='1' AND A.ONHOLD='0' AND A.TRANSACTIONTYPE IN (SELECT TRANSACTIONTYPE FROM TRANSACTIONTYPES WHERE FINANCIALTRANSACTION='1' AND TRANSACTIONTYPEGROUP='S') AND A.PREPAID='0' AND SUBSTRING(ISNULL(A.ADDITIONALDATA,'**'),1,2)<>'AT' GROUP BY A.ACQUIRERINSTITUTIONID,A.MERCHANTID,A.CARDACQID,A.CLEARINGINSTITUTIONID,C.BANKCODE,C.BANKACCOUNT,C.BANKACCOUNTTYPE,C.BANKACCOUNTPERCENTAGE,C.PAYMENTFORM,A.CURRENCY HAVING SUM(A.AMOUNTTOTAL) > 0 ORDER BY A.ACQUIRERINSTITUTIONID,A.MERCHANTID,A.CARDACQID,A.CLEARINGINSTITUTIONID,C.BANKCODE,C.BANKACCOUNT,C.BANKACCOUNTTYPE,C.BANKACCOUNTPERCENTAGE,C.PAYMENTFORM,A.CURRENCY |
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2010-10-07 : 12:07:38
|
Well I cenrtainly have a few suggestions.1) Use ANSI Standard JOINs rather than joining everying in the WHERE clause. It's easier to read and it sometimes gives you better execution plans.2) Don't use functions on columns. If you do then you can't use any index on that column.I've rewritten your querySELECT A.ACQUIRERINSTITUTIONID ,A.MERCHANTID ,A.CARDACQID ,A.CLEARINGINSTITUTIONID ,C.BANKCODE ,C.BANKACCOUNT ,C.BANKACCOUNTTYPE ,C.BANKACCOUNTPERCENTAGE ,C.PAYMENTFORM ,A.CURRENCYFROM INTERCHG A JOIN MERCHANT B ON B.[MERCHANTID] = A.[MERCHANTID] JOIN BANKACCOUNTSBYMIDCAIDCI C ON C.[MERCHANTID] = A.[MERCHANTID] AND C.[CARDACQID] = A.[CARDACQID] AND C.[CLEARINGINSTITUTIONID] = A.[CLEARINGINSTITUTIONID] JOIN PAYMENTCYCLES D ON D.[PAYMENTCYCLECODE] = A.[PAYMENTCYCLECODE]WHERE -- JOINS -- A.MERCHANTID=B.MERCHANTID AND -- B.PAYMENTCYCLECODE=D.PAYMENTCYCLECODE AND -- A.MERCHANTID=C.MERCHANTID AND -- A.CARDACQID=C.CARDACQID AND -- A.CLEARINGINSTITUTIONID=C.CLEARINGINSTITUTIONID AND -- FILTERS A.PAYED='0' AND A.PRESENTED='1' AND A.SETTLED='1' AND A.ONHOLD='0' AND A.PREPAID='0' AND B.PAYMENTGROUPINGLEVEL='2' AND A.TRANSACTIONTYPE IN ( SELECT TRANSACTIONTYPE FROM TRANSACTIONTYPES WHERE FINANCIALTRANSACTION='1' AND TRANSACTIONTYPEGROUP='S' ) -- THESE ARE PROBLEMS -- THEY CAN'T USE ANY INDEX ON THE RELEVENT -- COLUMN AND SUBSTRING(ISNULL(A.ADDITIONALDATA,'**'),1,2)<>'AT' AND substring(D.PAYMENTCYCLEDAYS,datepart(dw,'2010-09-30'),1)='1'GROUP BY A.ACQUIRERINSTITUTIONID ,A.MERCHANTID ,A.CARDACQID ,A.CLEARINGINSTITUTIONID ,C.BANKCODE ,C.BANKACCOUNT ,C.BANKACCOUNTTYPE ,C.BANKACCOUNTPERCENTAGE ,C.PAYMENTFORM ,A.CURRENCYHAVING SUM(A.AMOUNTTOTAL) > 0ORDER BY A.ACQUIRERINSTITUTIONID ,A.MERCHANTID ,A.CARDACQID ,A.CLEARINGINSTITUTIONID ,C.BANKCODE ,C.BANKACCOUNT ,C.BANKACCOUNTTYPE ,C.BANKACCOUNTPERCENTAGE ,C.PAYMENTFORM ,A.CURRENCY Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2010-10-07 : 12:11:40
|
This partAND substring(D.PAYMENTCYCLEDAYS,datepart(dw,'2010-09-30'),1)='1' The best performing thing you could do is probably to implement a calendar table and join to it on this condition. That way you would be able to use index on the column.http://weblogs.sqlteam.com/dang/archive/2010/07/19/calendar-table-and-datetime-functions.aspxCharlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
jose_c27
Starting Member
2 Posts |
Posted - 2010-10-07 : 13:48:39
|
Hey thnks for the suggestions, i tried but still experiencing the same problem |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2010-10-07 : 15:16:15
|
Avoid implicit conversions. Use original datatype as long as possible.SELECT ic.AcquirerInstitutionID, ic.MerchantID, ic.CardAcqID, ic.ClearingInstitutionID, c.BankCode, c.BankAccount, c.BankAccountType, c.BankAccountPercentage, c.PaymentForm, ic.CurrencyFROM dbo.Merchant AS mINNER JOIN dbo.InterChg AS ic ON ic.MerchantID = m.MerchantID AND ic.Payed = 0 AND ic.Presented = 1 AND ic.Settled = 1 AND ic.OnHold = 0 AND ic.PrePaid = 0 AND (ic.ADDITIONALDATA NOT LIKE 'AT%' OR ic.ADDITIONALDATA IS NULL)INNER JOIN ( SELECT TransactionType FROM dbo.TransactionTypes WHERE FinancialTransaction = 1 AND TransactionTypeGroup = 'S' GROUP BY TransactionType ) AS x ON x.TransactionType = ic.TransactionTypeINNER JOIN dbo.BankAccountsByMIDCAIDCI AS c ON c.MerchantID = ic.MerchantID AND c.CardAcqID = ic.CardAcqID AND c.ClearingInstitutionID = ic.ClearingInstitutionIDINNER JOIN dbo.PaymentCycles AS pc ON pc.PaymentCycleCode = m.PaymentCycleCode AND SUBSTRING(pc.PAYMENTCYCLEDAYS, DATEPART(WEEKDAY, '20100930'), 1) = '1'WHERE m.PaymentGroupingLevel = 2GROUP BY ic.AcquirerInstitutionID, ic.MerchantID, ic.CardAcqID, ic.ClearingInstitutionID, c.BankCode, c.BankAccount, c.BankAccountType, c.BankAccountPercentage, c.PaymentForm, ic.CurrencyHAVING SUM(ic.AmountTotal) > 0ORDER BY ic.AcquirerInstitutionID, ic.MerchantID, ic.CardAcqID N 56°04'39.26"E 12°55'05.63" |
 |
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2010-10-08 : 04:22:28
|
Hey peso.I see you've moved the InterChg filters from the where clause to the INNER JOIN.Any particular reason for this? Shouldn't that produce the same query plan?Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2010-10-08 : 05:16:47
|
Not necessarily. Doing this in the past have yielded much better plans.Also changing the order of tables sometimes have an effect. N 56°04'39.26"E 12°55'05.63" |
 |
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2010-10-08 : 05:28:12
|
cheers. good to know. Any particular reason you re-ordered the JOINS the way you did? Obviously we've go no data to play around with to check. <HINT>Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
|
|
|
|
|