Solved

cost of complex query that returns zero records.

Posted on 2014-11-13
6
111 Views
Last Modified: 2014-11-25
if a complex SELECT statement should return 0 rows, does it still consume approximately the same level of resources to finish the query to say 'no records'.
0
Comment
Question by:25112
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 25

Assisted Solution

by:Lee Savidge
Lee Savidge earned 84 total points
ID: 40439673
The cost of the query is the actual running of the query, not specifically the number of rows returned. The number of rows returned is the result of the query and this constitutes almost nothing to the query cost.
0
 
LVL 51

Assisted Solution

by:Vitor Montalvão
Vitor Montalvão earned 166 total points
ID: 40439729
Sure. How the engine knows that there's no record to return? It needs to process the query to return records or no records in the case of no rows found that satisfies the query.
0
 
LVL 51

Assisted Solution

by:Vitor Montalvão
Vitor Montalvão earned 166 total points
ID: 40439735
You can activate the option "Include Actual Execution Plan" to get the Query Plan and see what the engine is performing in background.
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 70

Assisted Solution

by:Qlemo
Qlemo earned 83 total points
ID: 40439783
Of course the overall costs are including retrieving the results. So, if the Optimizer is able to supply an execution plan having index-only access, you will see not much of a difference, and execution is "fast".
If a full table scan is involved, you won't see a difference either - but because the full table scan will have high costs, the query is expensive, no matter how many rows will result.
0
 
LVL 66

Assisted Solution

by:Jim Horn
Jim Horn earned 83 total points
ID: 40440460
If you look at SQL Server's Query Order of Execution, the only savings with a zero-row query vs. a non-zero row query is that it doens't process the SELECT on down, as there are no rows.  It still has to process FROM with JOINs, WHERE, GROUP BY, HAVING, etc.

< kind of piling on, I know.. >
0
 
LVL 23

Accepted Solution

by:
Racim BOUDJAKDJI earned 84 total points
ID: 40441125
There is no direct relationship between resource consumption and number of rows returned (server wise).  The indirect relationship is made by the optimizer whom based on statistics of existing rows will determine the best course of action to retrieve rows at the lowest cost.
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question