| Author |
Topic |
|
tee11732
Starting Member
4 Posts |
Posted - 2009-07-13 : 10:16:20
|
My sql knowledge is extremely limited. Can someone please help me understand why this query is so slow and how I can speed it up. It took 15 secs. to return just 30 rows.  SELECT distinct a.deviceId, sum(b.pointsUPS) as upspoints, sum(b.pointsIovations) as iovationspoints, case when z.deviceid is null then 'Good' else 'Bad' end as devicestatus, isnull(acct.cus_id_nr,'') as cus_id_nr, isnull(acct.uuid,'') as uuid from dbo.fpsdeviceId_iovationelements as a join dbo.fpsiovationselements as b on(a.elementcode=b.code) LEFT outer join dbo.fpsbaddevice as z on(a.deviceId=z.deviceId) left outer join dbo.tfpstxmldtl as acct on(a.deviceId=acct.deviceId) where a.deviceid is not null and convert(varchar,a.updatedDate,101) = '07/13/2009' group by a.deviceID,acct.uuid,acct.cus_id_nr,ac_nr,z.deviceid order by deviceId |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-07-13 : 10:26:05
|
First step is this:SELECT distinct a.deviceId, sum(b.pointsUPS) as upspoints, sum(b.pointsIovations) as iovationspoints, case when z.deviceid is null then 'Good' else 'Bad' end as devicestatus, isnull(acct.cus_id_nr,'') as cus_id_nr, isnull(acct.uuid,'') as uuid from dbo.fpsdeviceId_iovationelements as a join dbo.fpsiovationselements as b on(a.elementcode=b.code) LEFT outer join dbo.fpsbaddevice as z on(a.deviceId=z.deviceId) left outer join dbo.tfpstxmldtl as acct on(a.deviceId=acct.deviceId)where a.deviceid is not nulland a.updatedDate >= '20090713' -- = '07/13/2009'and a.updatedDate < '20090714' group by a.deviceID,acct.uuid,acct.cus_id_nr,ac_nr,z.deviceid order by deviceId Next step would be to see if indexes are proper set. No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
tee11732
Starting Member
4 Posts |
Posted - 2009-07-13 : 10:33:15
|
| Thanks for the help. It sped it up by 3 seconds. Table tfpstxmldtl is the largest with 1021248 records but it has 10 indices. The other tables are small...30-40 rows max and are not indexed. |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-07-13 : 10:42:52
|
Maybe there is an easy way to minimize the joined entries from tfpstxmldtl? For example tfpstxmldtl has that updatedDate too or other columns to exclude rows from joining?Is there an index for deviceId in tfpstxmldtl? No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-07-13 : 13:38:33
|
quote: Originally posted by tee11732 Thanks for the help. It sped it up by 3 seconds. Table tfpstxmldtl is the largest with 1021248 records but it has 10 indices. The other tables are small...30-40 rows max and are not indexed.
what does excution plan sugest? is index used ? what are costly steps? |
 |
|
|
GhantaBro
Posting Yak Master
215 Posts |
Posted - 2009-07-13 : 23:47:34
|
| make sure you have indexes on fields used for joins and where clause and proper indexes should be created else bookmark look up will slow up the query... sometimes doing smaller joins and creating temporary table and then using that in further join speeds up too... but yeah like other suggested check the estimation plan and work on the most expensive part. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2009-07-14 : 01:42:09
|
post the DDL of the table, sampe data and exxpected results SELECT a.deviceId , SUM (b.pointsUPS) AS SUM_upspoints , SUM(b.pointsIovations) AS SUM_pointsIovations , CASE WHEN z.deviceid IS NULL THEN 'Good' ELSE 'Bad' END AS devicestatus , COALESCE(acct.cus_id_nr, '') AS cus_id_nr , COALESCE(acct.uuid, '') AS uuid FROM fpsdeviceId_iovationelements AS aINNER JOIN fpsiovationselements AS b ON a.elementcode = b.code LEFT JOIN fpsbaddevice AS z ON a.deviceId=z.deviceId LEFT JOIN tfpstxmldtl AS acct ON a.deviceId=acct.deviceId WHERE a.deviceid is not null-- AND CONVERT(varchar, a.updatedDate101) = '07/13/2009' AND a.updateDate101 > = '07/13/2009' AND a.updateDate101 < = '0713/2009 12:59:59:999' GROUP BY a.deviceIDacct.uuidacct.cus_id_nrac_nrz.deviceid ORDER BY deviceId Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam |
 |
|
|
|