I am new to Database Administration
. I am following information provided by: http://www.brentozar.com/blitzindex/
I have a table VehicleMonitoringLog
. When I execute the sp_BlitzIndex
script it shows that this is a Heap
, because it doesn't have a clustered index
.
Now, all of our searches on this table are done based on iAssetId
and dtUTCDateTime
. This is the Query:
Select top (1) *
from VehicleMonitoringLog
where iAssetId = 1
Order By dtUtcDateTime DESC
We don't search based on the PK, BUT we are inserting data into this table every few seconds.
My questions are:
Because we are inserting data every few seconds do I need to create a clustered index on the PK?
OR, should I create a clustered index on iAssetId
and dtUtcDateTime
like this?
CREATE CLUSTERED INDEX
[VehicleMonitoringLog_Asset_dtmUTCDateTime_ClusteredIndex]
ON [dbo].[VehicleMonitoringLog] ( [iAssetId] ASC, [dtUTCDateTime] ASC )
WITH ( PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF,
DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON,
ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
EDIT: These are the 3 columns in Question:
I have added an image showing the PK and FK of the Table. Another search we do is something like this:
Select * from VehicleMonitoringLogs
where iAssetId = 1
and dtUTCDateTime > GetDate() - 1
and dtUTCDateTime < GetDate()
Order by dtUTCDateTime ASC
dtUTCDateTime
, and you are probably doing range searches on it, it would make sense to create a clustered index on that column and a non clustered index oniAssetId
. But there are many possible answers. You need to 1. Measure insert and select performance and capture the query plan, 2. Apply Indexes 3. Measure insert and select performance and capture the query plan. 4. Repeat from 2, but with a different set of indexes. Then you can make a decision on what is the best index. Heaps aren't always bad as long as you have a reason for implementing it that way.