I recently got added to a new ASP .NET Project(A web application) .There were recent performance issues with the application, and I am in a team with their current task to Optimize some slow running stored procedures.
The database designed is highly normalized. In all the tables we have a BIT column
as [Status_ID]
. In every Stored procedures
, For every tsql query
, this column is involved in WHERE
condition for all tables.
Example:
Select A.Col1,
C.Info
From dbo.table1 A
Join dbo.table2 B On A.id = B.id
Left Join dbo.table21 C On C.map = B.Map
Where A.[Status_ID] = 1
And B.[Status_ID] = 1
And C.[Status_ID] = 1
And A.link > 50
In the above sql
, 3 tables are involved, [Status_ID]
column from all 3 tables are involved in the WHERE
condition. This is just an example. Like this [Status_ID]
is involved in almost all the queries.
When I see the execution plan of most of the SPs
, there are lot of Key lookup (Clustered) task involved and most of them are looking for [Status_ID] in the respective table.
In the Application, I found that, it is not possible to avoid these column checking from queries. So
Will it be a good idea to
- Alter all
[Status_ID]
columns toNOT NULL
, and then adding them toPRIMARY KEY
of that table.Columns 12,13.. will be (12,1) and (13,1) - Adding
[Status_ID]
column to all the NON Clustered indexes in theINCLUDE PART
for that table.
Please share you suggestions over the above two points as well as any other.
Thanks for reading.