I have following sql query and i would like to optimize it to work faster.
select dv.Id, dv.Version, cvco.Time
from DVPST dvps -- cca. 10 000 entries
inner join DVPCT dvpc ON dvps.Value = dvpc.Value
inner join DVPT dvp on dvpc.Id = dvp.Id
inner join DVT dv on dvp.Id = dv.Id
inner join CVCOT cvco ON dv.Id = cvco.Id
inner join DT doc on doc.Id = dv.Id
where dvps.ValueStr in ("value1", "value2", ..., "value1000")
Execution plan evalutes all using correct indexes but it still takes so long. The where condition should filter all entries from DVPCT table so only this is evaluated in most cases:
select dv.Id, dv.Version, cvco.Time
from DVPST dvps
where dvps.ValueStr in ("value1", "value2", ..., "value10000")
Why does the query still executes the joins when it have nothing to join there.
Many thanks for any ideas, Marek