Solved

cost of complex query that returns zero records.

Posted on 2014-11-13
6
110 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 50

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 50

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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe 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 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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Syntax 6 58
TSQL Assignining CTE column in to a variable 3 27
get count of orders by customer Sql Server table. 3 48
T-SQL: Number of Records is Greater Than One 7 51
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

751 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