|
|
Question : Forcing the correct join order...
|
|
Hello...
This is an extension of question http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/Q_21611429.html
I managed to split the AP into a seperate table. This table contains about 4 Million Rows for 4 main tabels.
Now i am trying to optimize the querry that need information from these AP. I managed to create a small subquerry that will extract the GUIDs of the master table that i need to fetch. This subquerry will return 315 Rows for a search i am using to test.
These 315 Rows are returned in under a second so i thought great... But now i need to join this subquerry to the master table but the querry analyser shows me some bad execution plans including a clustered index scan over the main master table just to look for some stupid status that could be passed into the querry also.
Now what i want SQL Server to do is to FIRST execute the Subquerry and THEN look for that stupid status in the remaining 315 rows instead of scanning 100 K + rows.
If this works the querry would run in about 1 second instead of 3 minutes (original version) or 30 Seconds (current Version)
Any clues how i could enforce this?
|
Answer : Forcing the correct join order...
|
|
Can you enlighten us with the table and index structure, please?
you could use query join hints, but I think to force the execution, the best is this:
declare @t table ( guidfield uniqueidentifier ) insert into @t select guidfield from
select * from yourtable t join @t j on j.guidfield = t.guidfield
|
|
|
|