Adding a non clustered index to a table with less than 1000 rows but accessed frequently will increase performance?

StackOverflow https://stackoverflow.com/questions/8542075

  •  19-03-2021
  •  | 
  •  

Question

I have a table with just 400-500 rows but this table is being accessed very often so I was wondering if should add a non clustered index on one of its columns to see any improvement?

This table keeps the same data all the time and rarely is updated.

Here's the structure of the table

CREATE TABLE [dbo].[tbl_TimeZones](
    [country] [char](2) NOT NULL,
    [region] [char](2) NULL,
    [timezone] [varchar](50) NOT NULL
) ON [PRIMARY]

With this Cluster Index:

CREATE CLUSTERED INDEX [IX_tbl_TimeZones] ON [dbo].[tbl_TimeZones] 
(
    [country] ASC,
    [region] ASC,
    [timezone] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO

This table doesn't has a primary key because the region column could be null so that's why I haven't used a key yet.

So I want to add a non cluster index on the column timezone in order to increase it's performance.

Was it helpful?

Solution

Short answer: an index will probably improve performance for you.

Longer answer. Even with just that number of records, you could see query improvement with a well-chosen index. Assuming this table is used in joins, you could see changes (improvements) in the query plans that join through that table, which may give you a bigger benefit than you might anticipate.

You seem to give the impression that you expect to index "one" column. Indexing just one column is probably not the optimal solution. A "covering" index is generally going to be a better solution (Google for "covering index").

Now, having said all of that, I suspect that the best performance may come from how the clustered index is defined. You did not indicate the nature of the clustered index on this table, or of the use of the data. But, if the queries almost always access the table in the same way (e.g., the WHERE and JOIN clauses always reference the same columns), then you might find that changing the clustered index is gives the most improvement.

Also, part of the art of choosing indexes involves balancing query performance versus insert/update performance. You don't have that challenge if the data aren't changing. Keep that in mind when reading general index-tuning advice.

Bottom line: I suspect that a clustered index over the columns used in the WHERE and JOIN clauses is the answer. Consider column order matters. Selectivity matters.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top