I want optimize this select:
Select Dane1, Dane5, Dane6, Dane7 FROM Test
INNER JOIN Test2 ON Test.Id=Test2.IdTest
WHERE Dane5 > 199850
My database has 2 tables test, test2:
test design: Id int ->PRIMARY KEY, Dane1 int, Dane2 int, Dane3 int, Dane4 int, Dane5 int,
test2 design: Id int ->PRIMARY KEY, Dane6 int, Dane7 int, IdTest int,
Default index: PK__test__7C8480AE(Clustered), PK__test2__7E6CC920(Clustered)
The question is: Which indexes to attach or remove?
There's few things to consider when creating indexes, for example in this case:
You could try something like this:
Weather to include Dane1 depends on how much rows there are and if key lookups are causing issues
Id is already included since it's the clustered index
Weather to have Dane6 and Date7 as included columns depends also here on the total amount of key lookups that needs to be done to the table to get them
You should turn on statistics io to see what causes the most logical reads, and weather to have the included columns in the indexes are needed or not.