patternsqlMinor
Are there any performance benefits to using a hash table with no clustered index?
Viewed 0 times
clusteredarewithanyhashbenefitsperformanceusingindexthere
Problem
I have this table:
It stores hash matches. Is there any benefit to having this as a heap? It has around 7 million rows, and the values are not unique in either column. I know heaps are generally never good for any large tables. This table currently has no indexes.
I was thinking of altering the table to:
Table queries are generally but not always on
Is it better to create a clustered index like this, as opposed to leaving the table as a heap?
CREATE TABLE [dbo].[relatea] (
[mid] [varchar](16) NOT NULL,
[sid] [varchar](16) NOT NULL
)It stores hash matches. Is there any benefit to having this as a heap? It has around 7 million rows, and the values are not unique in either column. I know heaps are generally never good for any large tables. This table currently has no indexes.
I was thinking of altering the table to:
CREATE TABLE [dbo].[relatea] (
[mid] [varchar](16) NOT NULL,
[sid] [varchar](16) NOT NULL,
CONSTRAINT [pk_relatea] PRIMARY KEY CLUSTERED (
[mid] ASC,
[sid] ASC
)
)Table queries are generally but not always on
sid, and the combination of mid and sid should always be unique.Is it better to create a clustered index like this, as opposed to leaving the table as a heap?
Solution
I would put a clustered index (not a primary key) on the sid column. If you do lookups against the mid column sometimes as well then add an index to the mid column with the sid column as an included index.
If you don't want to create a clustered index, then two non-clustered indexes one on each column with the other column as an included column should give you the same basic read performance.
If you don't want to create a clustered index, then two non-clustered indexes one on each column with the other column as an included column should give you the same basic read performance.
Context
StackExchange Database Administrators Q#14987, answer score: 8
Revisions (0)
No revisions yet.