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 |
|
quest3297
Starting Member
2 Posts |
Posted - 2011-12-20 : 17:11:27
|
| I have a table with around 3 million records with couple of date columns. When i query the table directly with no dates specified i get data directly. But when i pass with dates it is taking about 1-2 mins to get data. Not sure how can i manipulate this single query to increase performance. Please provide insights on doing this. Query goes as below.select b.acct_nbr, b.REGVALUE, b.Addr1, b.Addr2, b.Addr3, b.Addr4, b.city, b.state_id, b.zipfrom FIRM f, PROD p, (select a.acct_nbr, a. REGVALUE, a.Addr1, a.Addr2, a.Addr3,a.Addr4, a.city, a.state_id, a.zipfrom ACCOUNT awhere (UPPER(A.REGVALUE) LIKE '% 3150IAC %' or UPPER(A.REGVALUE) LIKE '% 3150 IAC %'or UPPER(A.REGVALUE) LIKE '% 3150 (IAC) %'or UPPER(A.REGVALUE) LIKE '% 3150_IAC %'or UPPER(A.REGVALUE) LIKE '% WARD %')and (UPPER(A.REGVALUE) NOT LIKE '% JTWROS %'and UPPER(A.REGVALUE) NOT LIKE '% BOTHYACK %'and UPPER(A.REGVALUE) NOT LIKE '% MYCOLLECTION %')) bwhere b.tech_id = f.tech_idand b.prod_cd = p.prod_cdand (b.est_dt between '01-JAN11' and '31-DEC-11'or b.closed_dt between '01-JAN-11' and '31-DEC-11')and b.IB_cd in ('EXN', 'DTS', 'ALP') |
|
|
Bustaz Kool
Master Smack Fu Yak Hacker
1834 Posts |
Posted - 2011-12-20 : 18:13:27
|
| A few thoughts/questions off the top of my head...1) Is there a reason that you are performing the subquery on ACCOUNTS before joining the other tables?2) Have you tried putting the additional filtering (Dates and IB_cd) inside the subquery?3) What indexes are on the two date columns?4) What does the execution plan look like?My (blind) attempt at re-writing the query:[CODE]select a.acct_nbr, a.REGVALUE, a.Addr1, a.Addr2, a.Addr3, a.Addr4, a.city, a.state_id, a.zipfrom ACCOUNT ainner join FIRM f on a.tech_id = f.tech_idinner join PROD p on a.prod_cd = p.prod_cdwhere ( UPPER(A.REGVALUE) LIKE '% 3150IAC %' or UPPER(A.REGVALUE) LIKE '% 3150 IAC %' or UPPER(A.REGVALUE) LIKE '% 3150 (IAC) %' or UPPER(A.REGVALUE) LIKE '% 3150_IAC %' or UPPER(A.REGVALUE) LIKE '% WARD %' )and (UPPER(A.REGVALUE) NOT LIKE '% JTWROS %'and UPPER(A.REGVALUE) NOT LIKE '% BOTHYACK %'and UPPER(A.REGVALUE) NOT LIKE '% MYCOLLECTION %')and ( a.est_dt between '01-JAN11' and '31-DEC-11' or a.closed_dt between '01-JAN-11' and '31-DEC-11' )and a.IB_cd in ('EXN', 'DTS', 'ALP')[/CODE]=======================================Faced with the choice between changing one's mind and proving that there is no need to do so, almost everyone gets busy on the proof. -John Kenneth Galbraith |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
quest3297
Starting Member
2 Posts |
Posted - 2011-12-21 : 09:53:24
|
quote: Originally posted by Bustaz Kool A few thoughts/questions off the top of my head...1) Is there a reason that you are performing the subquery on ACCOUNTS before joining the other tables?2) Have you tried putting the additional filtering (Dates and IB_cd) inside the subquery?3) What indexes are on the two date columns?4) What does the execution plan look like?My (blind) attempt at re-writing the query:[CODE]select a.acct_nbr, a.REGVALUE, a.Addr1, a.Addr2, a.Addr3, a.Addr4, a.city, a.state_id, a.zipfrom ACCOUNT ainner join FIRM f on a.tech_id = f.tech_idinner join PROD p on a.prod_cd = p.prod_cdwhere ( UPPER(A.REGVALUE) LIKE '% 3150IAC %' or UPPER(A.REGVALUE) LIKE '% 3150 IAC %' or UPPER(A.REGVALUE) LIKE '% 3150 (IAC) %' or UPPER(A.REGVALUE) LIKE '% 3150_IAC %' or UPPER(A.REGVALUE) LIKE '% WARD %' )and (UPPER(A.REGVALUE) NOT LIKE '% JTWROS %'and UPPER(A.REGVALUE) NOT LIKE '% BOTHYACK %'and UPPER(A.REGVALUE) NOT LIKE '% MYCOLLECTION %')and ( a.est_dt between '01-JAN11' and '31-DEC-11' or a.closed_dt between '01-JAN-11' and '31-DEC-11' )and a.IB_cd in ('EXN', 'DTS', 'ALP')[/CODE]=======================================Faced with the choice between changing one's mind and proving that there is no need to do so, almost everyone gets busy on the proof. -John Kenneth Galbraith
Thanks Bustaz Kool for replying. I tried with this but its not making any difference.1) Is there a reason that you are performing the subquery on ACCOUNTS before joining the other tables?-- Just to filter out the records i tried different ways and this was one of it.2) Have you tried putting the additional filtering (Dates and IB_cd) inside the subquery?-- I tried so but not much yield.3) What indexes are on the two date columns?-- Non Clustered indexes are specified on the 2 columns.4) What does the execution plan look like?-- In execution most of the cpu time is linked where dates filter is applied. I am unable to think of a way to speed up. I did all i could.Let me know if you think if there are any alternate ways. |
 |
|
|
|
|
|
|
|