Solved

cost of complex query that returns zero records.

Posted on 2014-11-13
6
104 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
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 45

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 45

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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 68

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 65

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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now