Sunday 15 September 2013

sql - Why does the SELECT command run faster when WHERE is included? -


In SQL Server Management Studio 2012, I run this query:

  SELECT * Contact   

This query is successfully implemented in approximately 44 seconds. WHERE FirsttName = 'David' from

  SELECT * contacts *   

This query is executed successfully in about 0 seconds, so I think my question is This is going to be the reason for how different these query times are. From my dependable relative perspective, I think that in all the cases, all the table rows should be surveyed to check that FirstName is equal to 'David', and this condition should not be big of that effect. In fact, I assumed that due to additional investigation the query would take a little longer time. > Another example is:

  select Save   

is successfully executed in approximately 25 seconds.

  SELECT * FROM Jobs WHERE JobName = "Sales"   

Successfully exec utes in approximately 0 seconds.

This is not a life-threatening / blocking / O God, why can not I solve the issue of this problem? Just something that makes me wonder.

It depends on many factors as mentioned by Bobbeck, with the passage of time The issue may be time to return all records. Suppose you are only looking at processing time.

The first question is, did you run these results several times, taking account caching effect? If you run the first query, the table loads into the memory and stays there. With the first questions on the table, for the first time, the second time will be very fast, for the second time. To tell the time, you have to be careful.

Another probability index exists, however I suspect that there will be an index on first name . Reduces time to achieve an index record. This index goes to find the right record, sees them, and returns the result. Finally, due to the select * your query, you have to get data on the page.

For the time of investigation, it is actually a non-issue. The amount of time for a page processing can usually be much higher than a bullion operation on a record. Many other factors have a big impact on the performance.

My guess is, in your case, that you have run as questions mentioned in the questions, and performance is due to cross-caching effects.

No comments:

Post a Comment