Solved

cost of complex query that returns zero records.

Posted on 2014-11-13
6
107 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 47

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 47

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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 69

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

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…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

776 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