CREATE TABLE [dbo].[session]
(
[id] [int] IDENTITY(1,1) NOT NULL,
[user_id] [int] NOT NULL,
[session_id] [uniqueidentifier] NOT NULL,
[supervisor_id] [int] NULL,
some columns ..
CONSTRAINT [PK_session]
PRIMARY KEY CLUSTERED ([id] ASC)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
) ON [PRIMARY]
CREATE TABLE [dbo].[tbl2]
(
[id] [int] IDENTITY(1,1) NOT NULL,
[close_date] [datetime] NULL,
[edit_date] [datetime] NULL,
[session_id] [uniqueidentifier] NOT NULL,
some columns ..
CONSTRAINT [PK_tbl2]
PRIMARY KEY CLUSTERED ([id] ASC)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
) ON [PRIMARY]
I have those two tables which I can join on the session_id
column. There are more than 20 000 rows in each table, and the join is too slow. Is it a good idea to create a nonclustered index on session_id
columns which are of uniqueidentifier
type? Or there is another way to do the join faster ?
Edit:
For example query is like :
SELECT some_columns...
FROM [dbo].[session] s
INNER JOIN [dbo].[tbl2] t2 on s.[session_id] = t2.[session_id]
WHERE t2.some_column = something