HestonJames
Programmer
Good afternoon guys,
I'm looking for some advice on indexing a couple of tables. These tables currently have no indexing on them and the number of records is growing substantially now performance on our report queries are slowly getting worse and worse.
Indexing is a very new topic to me and as I'm very much a 'learn by example' kind of guy thought I would get your advice on this particular scenario.
I've enclosed two queries, one showing the INSERT for the table, another showing a pretty common SELECT type statement which we would use, for which I've attached an execution plan.
and
Can you offer your recomendations on which columns should be indexed here? and what type of index I should be using on those columns?
One thing worth mentioning is that the INSERT statements are actioned from automated tasks or remote client applications and NOT by users, so performance on those isn't so important, the SELECT however is for a reporting tool which has user interaction so performance is quite important and at the moment its just being killed and causing me user experience problems :-(
Thank you all guys, if you can make some suggestions I can action them onto the database and try some testing.
Cheers all,
Heston
I'm looking for some advice on indexing a couple of tables. These tables currently have no indexing on them and the number of records is growing substantially now performance on our report queries are slowly getting worse and worse.
Indexing is a very new topic to me and as I'm very much a 'learn by example' kind of guy thought I would get your advice on this particular scenario.
I've enclosed two queries, one showing the INSERT for the table, another showing a pretty common SELECT type statement which we would use, for which I've attached an execution plan.
Code:
Select c.yyyy,
c.mm,
h.hhname,
Sum(Case When d.LogClassName = 'org.openobex.TransferComplete' Then 1 Else 0 End ) As Success,
Count(Distinct d.Device_ID) As UniqueDevices,
Sum(Case When d.MinDate Is NULL Then 0 Else 1 End) As FirstAppearanceCount
From Calendar As c
Cross Join Hours As h
Left Outer Join (
Select DATEADD(hh,DATEDIFF(hh, 0, MessageLog.LogDateTime), 0) As LogDate,
MessageLog.Device_ID,
LogClass.Name As LogClassName,
FirstAppearance.MinDate
From MessageLog
Inner Join LogClass
On LogClass.LogClass_ID = MessageLog.LogClass_ID
Left Join (
Select Device_ID,
Min(LogDateTime) As MinDate
From MessageLog
Inner Join LogClass
On LogClass.LogClass_ID = MessageLog.LogClass_ID
Where LogClass.Name In (
'org.openobex.TransferComplete',
'org.openobex.Error.ConnectionRefused',
'org.openobex.Error.Forbidden',
'org.openobex.Error.NotAuthorized',
'org.openobex.Error.ConnectionTimeout'
)
And MessageLog.ThinkTank_ID = 8
Group By Device_ID
) As FirstAppearance
On MessageLog.Device_ID = FirstAppearance.Device_ID
And MessageLog.LogDateTime = FirstAppearance.MinDate
Where LogClass.Name In (
'org.openobex.TransferComplete',
'org.openobex.Error.ConnectionRefused',
'org.openobex.Error.Forbidden',
'org.openobex.Error.NotAuthorized',
'org.openobex.Error.ConnectionTimeout'
)
And MessageLog.LogDateTime >= '20081015'
And MessageLog.LogDateTime < '20081016'
And ThinkTank_ID = 8
) As d
On d.LogDate = dateadd(hh, h.hh, c.caldate)
Where c.caldate >= '20081015'
And c.caldate < '20081016'
Group By c.yyyy,
c.mm,
h.hhname
Order By c.yyyy,
c.mm,
h.hhname
and
Code:
INSERT
INTO MessageLog
( Device_ID
, LogDateTime
, LogClass_ID
, Media_ID
, Campaign_ID
, ThinkTank_ID )
SELECT Device.Device_ID
, ##MessageStaging.LogDateTime
, LogClass.LogClass_ID
, ##MessageStaging.Media_ID
, ##MessageStaging.Campaign_ID
, 41
FROM ##MessageStaging
INNER
JOIN LogClass
ON LogClass.Name = ##MessageStaging.LogClass
INNER
JOIN OUI
ON OUI.OUI = LEFT(##MessageStaging.DeviceAddress,8)
INNER
JOIN Device
ON Device.OUI_ID = OUI.OUI_ID
AND Device.Address = SUBSTRING(##MessageStaging.DeviceAddress,10,8)
Can you offer your recomendations on which columns should be indexed here? and what type of index I should be using on those columns?
One thing worth mentioning is that the INSERT statements are actioned from automated tasks or remote client applications and NOT by users, so performance on those isn't so important, the SELECT however is for a reporting tool which has user interaction so performance is quite important and at the moment its just being killed and causing me user experience problems :-(
Thank you all guys, if you can make some suggestions I can action them onto the database and try some testing.
Cheers all,
Heston