SQL Server - Tune your Subquery-1

Who is online?  107 guests and 0 members
home  »  blogs  »  akash gautam  »  SQL Server - Tune your Subquery-1
  Rate This Blog Entry:  register  or  login

Author

akshmi1 akash gautam  (Member since: 6/2/2012 3:31:51 AM)

View akash gautam 's profile

Comments (4)

Ananthram
8/28/2012 5:54:52 AM Ananthram Venugopal said:

Hey Akash,

 

Nice blog. I had a question here :

The physical read, as you mentioned influences the cost, for the first time the query hits SQL SERVER, assuming the cache doesn't get cleared out, the subsequent hits wil read data from the memory.

Considering the example above, you can clearly see that the physical reads are zero(0) indicating that the data is already present in the cache and the SQL SERVER need not go back to the files to fetch the data.

So I believe we should concentrate on reducing the logical reads instead of the physical ones. This is in my opinion. Is it different in your line of thinking?

by
akshmi1
8/30/2012 2:35:19 PM akash gautam  said:

Whenever query hits first on a database parsing ,optimization,code generation and execution occurs,to avoid parsing and optimization phase SQL Server stores SQL Server query plan in plan cache.We can retrieve plan by querying sys.dm_exec_cached_plans,if you will see the XML plan,it will tell you the estimated subtree cost,now takes its text from dm_exec_query_text and run the same query including actual execution plan.If statistics of columns has not been changed drastically the estimated cost of the plan present in cache and the actual execution plan will remain same.It means it is using plan present in Plan cache, if stats has been changed by huge amount ,it will create a new plan.

What i want to say is the cost which is coming here is the first time query was compiled so it depends on physical reads and not much on logical reads.hope you understand

by
Ananthram
9/4/2012 4:25:21 PM Ananthram Venugopal said:

Akash,

     Thanks for the reply. If I understand your explanation properly, each time a query is executed, the execution plan that the optimizer uses considers that the data is read from the disk and not from memory?

Or am I not understanding the point here?

-Thanks in advance,

Ananthram

by
akshmi1
9/5/2012 6:40:29 AM akash gautam  said:

Yes 

 Reading data from Memory is very fast,you can check buffer cache hit ratio,or L1,L2,L3 cache.Cost of query depends on number of free pages present in Memory(Free Memory available) which will directly influence your Logical reads.

Logically, Cost should be independent on the type of resources present in your server ,If I am accessing data from SAN and then from SSD,duration of the query would be different in both the cases,but cost of query will remain same,same goes whether you have AMD processor or INTEL

by

Leave a comment


 
Type the characters:
 *
 
   

Training on Microsoft Products & Technologies

Email Subscriptions

   Get the Most Recent Blogs in your inbox
Blogs RSS Feed

akash gautam 's latest blog posts

  • I love giving interviews, one of the question asked in one of my interview question was “on which particular edition automatic page repair is possible (in context of database mirroring)”. ...
  • Hello friends One of the Fav question asked in most of the interviews is to explain diff recovery model . All they want to listen from you is word "Minimally logged". Actually there are two types of L...
  • Here goes my 2nd part of Tune your subquery Well,if my query is having UNION operator,we normally replace it by UNION ALL to improve performance According to itzik-ben gan UNION ALL returns one result...
  • Hi Guys Sorry for discontinuation from tune your queries.I was preparing for a interview and got to know very intresting thing. As a DBA we all know about IAM page but exactly its page number is littl...
  • Hello As a DBAs we get lot of request to tune queries and we normally suggest to create Index or Update Statistics but tuning also needs rewriting of actual query and the normally performance Issue is...
  • Locking behaviour of Indexes while updating rows Hello all The theory I am presenting you is from Reading in database systems and I find it valuable Today I will discuss about locking mechanism at ind...
  • Its my first blog so want to dedicate someone and make it special in some ways. You cann't use it practically but it will clear some of your concepts. I have a table with clustered index , they say up...
Blogs RSS Feed

Latest community blog posts

  • A few days back I was resolving a memory issue which caused sql server to stop responding. I was able to figure out the issue by looking into DBCC MemoryStatus output. It was the full text search whic...
  • This is an update to the DB-Migrate ( http://www.sqlservergeeks.com/blogs/AhmadOsama/personal/797/db-migrate-a-powershell-module-to-migrate-databases ) powershell module to migrate database between sq...
  • This blog is part of the series The TSQL Classes: Stored Procedure The links to previous post are given below. http://sqlservergeeks.com/blogs/AhmadOsama/personal/762/the-tsql-classes-stored-procedure...
  • Reporting With SSRS Part 1 : In this serires of blogs, i will try to introduce you with some of the key features of the tool which will help you get on board to become a proficient report developer.If...
  • Hi Folks, I am sure that all of you would be aware about the role of Identity column in a table, i.e., it is column which keeps on incrementing without supplying the value explicitly during insertion....
  • Recently I wrote powershell scripts to move databases, logins and SQL Agent Jobs between instances. Another one I wrote was to fix orphan users. I have now combined all of these different functions in...
  • Hi SQL Geeks, Here are the blog posts by Ahmad Osama for the month of April. We would expect more of his informative blogs this month. Happy Learning! If you like our blogs do like us on Facebook at h...
  • This blog is part of the series The TSQL Classes: Stored Procedure The link to previous post are given below. http://sqlservergeeks.com/blogs/AhmadOsama/personal/762/the-tsql-classes-stored-procedures...
  • As DBAs we are always challenged of unexpected size growth of log or data files and need to shrink files based on available free space in each file. Most of the times we are stuck and do a lot of scri...
  • One of the major migration activities is to fix orphan users. Though, it can be easily fixed by sp_change_users_login procedure, however what if you need to do this for multiple servers. A powershell ...
  • This blog is part of the series The TSQL Classes: Stored Procedure. http://www.sqlservergeeks.com/blogs/AhmadOsama/personal/764/the-tsql-classes-stored-procedures-nested-proc-recursion-and-plan-cachin...