Hi,
I have a part of a query that is quite expensive:
LEFT JOIN
myTable t1
ON t1.SyId = pos.SyId and t1.CuId = cu.CuId and t1.Date = @AsOfDate
LEFT JOIN
myTable t2
ON t2.SyId = pos.SyId and t2.CuId = cu.CuId and t2.Date = @StartDate-1
LEFT JOIN
myTable t3
ON t3.SyId = pos.SyId and t3.CuId = cu.CuId and t3.Date = @StartDate-1
As you can see, it's joining against itself depending on the "Date". Yes, I see that t2 and t3 appear to be doing the same thing! I removed one of them, but the execution plan didn't change one iota.
The problem is, this particular part of the query is taking up 100% of the cost with 2 full index scans on myTable's PK, and a corresponding "Hash Match".
The PK is on (SyId, CuId, Date) in that order. Why is it still doing index scans??
Any suggestions on how to tune this sucker? Alternative ways of writing this part of the query? Any advice appreciated!!!
I have a part of a query that is quite expensive:
LEFT JOIN
myTable t1
ON t1.SyId = pos.SyId and t1.CuId = cu.CuId and t1.Date = @AsOfDate
LEFT JOIN
myTable t2
ON t2.SyId = pos.SyId and t2.CuId = cu.CuId and t2.Date = @StartDate-1
LEFT JOIN
myTable t3
ON t3.SyId = pos.SyId and t3.CuId = cu.CuId and t3.Date = @StartDate-1
As you can see, it's joining against itself depending on the "Date". Yes, I see that t2 and t3 appear to be doing the same thing! I removed one of them, but the execution plan didn't change one iota.
The problem is, this particular part of the query is taking up 100% of the cost with 2 full index scans on myTable's PK, and a corresponding "Hash Match".
The PK is on (SyId, CuId, Date) in that order. Why is it still doing index scans??
Any suggestions on how to tune this sucker? Alternative ways of writing this part of the query? Any advice appreciated!!!