Uniqueidentifier Causing Strange Execution Plan

Jul 20, 2005

Can anyone help me with this strange problem please?

I have a stored procedure, with a parameter defined as a
uniqueidentifier. The procedure does a select with a number of joins,
and filters within the Where clause using this parameter.


(@orderHeader_iduniqueidentifier)

SELECT*
FROM originalOrderHeader ooh
INNER JOIN originalOrderLine ool
ON ooh.id = ool.id
FULL OUTER JOIN orderLine ol
on ool.id = ol.id
AND ool.productCode = ol.productCode
where (ooh.id = @orderHeader_id)


There is a clustered index on the id column of originalOrderHeader,
and on id and productCode of both originalOrderLine and orderLine.
These indexes are regularly rebuilt. The execution plan shows a seek
against these indexes, but the estimated row count values are huge,
and should be single figures.

If I change the SP to accept the parameter as a varchar, and then
explictly cast back to a uniqueidentifier in the where clause, the SP
runs much, much quicker, the execution plan is doing far less work,
and crucially the estimated row counts on the clustered index seeks
are correct (single figures).

Does anyone have any ideas what might be causing this?

View 1 Replies


ADVERTISEMENT

Using Execution Plan Generates Strange Errors

Feb 27, 2007

After installing SP2 for SQL Serve 2005, I get strange errors when using either "Estimated Execution Plan" or "Actual Execution Plan".

Using "Estimated Execution Plan" generates this error
An error occurred while executing batch. Error message is: Error processing execution plan results. The error message is:
There is an error in XML document (1, 3998).
Unexpected end of file while parsing has occurred. Line 1, position 3998.

Using "Actual Execution Plan" generates this error
An error occurred while executing batch. Error message is: Error processing execution plan results. The error message is:
There is an error in XML document (1, 4001).
Unexpected end of file has occurred. The following elements are not closed: RelOp, ComputeScalar, RelOp, Update, RelOp, QueryPlan, StmtSimple, Statements, Batch, BatchSequence, ShowPlanXML. Line 1, position 4001.

All I do is testing this solutiondeclare@t table (dt datetime)

insert@t
select'02-Jan-2007' union all
select'01-Feb-2007' union all
select'10-Feb-2007' union all
select'28-Feb-2007' union all
select'18-Mar-2007'

DECLARE@DaysRange INT,
@NumOfCalls INT

SELECT@DaysRange = 35,
@NumOfCalls = 4

SELECTt1.dt AS theDate
FROM@t AS t1
CROSS JOIN@t AS t2
WHEREt2.dt >= DATEADD(day, DATEDIFF(day, 0, t1.dt), 0)
AND t2.dt < DATEADD(day, DATEDIFF(day, 0, t1.dt), @DaysRange)
OR
t2.dt >= DATEADD(day, DATEDIFF(day, @DaysRange, t1.dt), 1)
AND t2.dt < DATEADD(day, DATEDIFF(day, 0, t1.dt), 1)
GROUP BYt1.dt
HAVINGCOUNT(*) >= @NumOfCallsHas anyone else experienced this?


Peter Larsson
Helsingborg, Sweden

View 9 Replies View Related

Actual Execution Plan Vs Estimated Execution Plan

Jul 7, 2006

The benefit of the actual execution plan is that you can see the actual number of rows passing through each step - compared to the estimated number of rows.But what about the "cost percentages" ?I believe I've read somewhere that these percentages is still just an estimate and is not based on the real execution.Does anyone know this and preferable have a link to something that documents it?Thanks

View 1 Replies View Related

Simple Query Causing Strange Problem.

Feb 11, 2004

declare @l decimal(38,2)
select @l = 24.35

if @l - convert(int,@l) = 0
select floor (@l)
else
select @l

select case
when @l - convert(int, @l) = 0 then floor (@l)
else @l
end

The if statement is giving correct result, but the case statement is not. I am fed up why it is so. Please advise.

View 14 Replies View Related

Strange Query Plan

Mar 19, 2008

I have a query like below .. if i add where Served = 1 , the query takes foreever... if i remove it, it takes only 6 sec...

I am not sure why this is hapening?


select distinct a.Episode_Key,
case when ag.Category IN ('ASMI', 'COOC', 'SPCL') then 'SMI'
when ag.Category = 'SEDC' then 'SED'
when ag.Category = 'ACCA' then 'SA'
when ag.Category like 'CGA%' then 'Gam'
end as [Category],
ag.Agreement_Type_Name as [Agreement],
p.ServiceProvider,
s2.Served
from dbo.Assessment a
INNER JOIN (
select distinct Episode_Key, p.ServiceProvider, max(CSDS_Object_Key) as [Sequence]
from dbo.Assessment a
INNER JOIN dbo.CD_Provider_Xref p
ON a.Provider_CD = p.Provider_CD
where Creation_DT >= '07/01/2007'
and Reason_CD = 1
group by Episode_Key, p.ServiceProvider
) as s1
ON a.CSDS_Object_Key = s1.Sequence
INNER JOIN dbo.CD_Provider_XREF p
ON a.Provider_CD = p.Provider_CD
INNER JOIN dbo.CD_Agreement_Type ag
ON ag.Agreement_Type_CD = a.Agreement_Type_CD
LEFT OUTER JOIN (
select distinct Episode_Key, p.ServiceProvider,
1 as [Served]
from dbo.Encounters e
INNER JOIN dbo.CD_Provider_Xref p
ON e.Provider_CD = p.Provider_CD
where Encounter_Begin_DT between '01/01/2008' and '01/31/2008'
and Procedure_CD is not null
and Encounter_Units > 0
) as s2
ON a.Episode_Key = s2.Episode_Key
and p.ServiceProvider = s2.ServiceProvider
????---where Served = 1
group by a.Episode_Key, ag.Agreement_Type_Name, p.ServiceProvider, Served,
case when ag.Category IN ('ASMI', 'COOC', 'SPCL') then 'SMI'
when ag.Category = 'SEDC' then 'SED'
when ag.Category = 'ACCA' then 'SA'
when ag.Category like 'CGA%' then 'Gam'
End

View 2 Replies View Related

Bad Execution Plan

Aug 21, 2001

I'm new to SQL server but familiar enough with databases to know this doesn't seem right.
Here's the situation:
I have a table with real estate property information. There are about 650,000 rows in it. I have a nonclustered non-unique index on the city where the property is located. There are about 40 unique values in this index.

I do a simple query like:
SELECT city,address from propinfo where city= 'CARLSBAD'. The query will return about 4,000 rows. The problem is that the execution plan that it chooses is to do a full table scan. I.E. Even though there is an index on City, it chooses to look through 650,000 rows rather than do an index seek. Something sounds inefficient here. BTW, this happens in both SQL 7 and SQL 2000. Can anyone explain why this happens? I've got to think that SQL Server is more efficient here.

View 5 Replies View Related

Execution Plan

Feb 2, 2006

Hello, I have been looking at the execution plan for a procedure call and the select, compute scalar, stream aggregates, constant scan, nested loops, asserts are all at 0% cost, the PK costs are 2% apart from a rogue 7% and a few 20%, tables scans are all at 23%. The query cost realtive to the batch is 100%. What does this all mean?
I have put non-clustered indexes on all the table attributes that are involved in the select statements but this has made no difference, i am guessing this is because my tables are not heavily populated and i may have seen a difference if i had thousands of entries in the tables the select statements acted on, is this assumption correct?
Does anyone else bother using the execution plan to tweak there DB or is it a negligible tool?

Jill

View 5 Replies View Related

Execution Plan

Aug 29, 2007

In sql server 2005 management studio where do I find the option to run the sql query in the query analyser and also show the execution plan?
At present I see the option under Query menu which is "Display estimated Execution plan" which only shows the plan but does not execute the query.

Thanks

View 2 Replies View Related

Execution Plan

Feb 29, 2008

Does anyone know of a good way to copy the execution plan when using "Include Actual Execution Plan"?
I often need to copy this and mail it.

I know I can use PrintScreen button, but I need a more efficient way to do this.
If I just could rightclick the execution plan and select "Copy" and get complete plan it would be great.

Mladen?


E 12°55'05.25"
N 56°04'39.16"

View 14 Replies View Related

Execution Plan

Jul 20, 2005

Which of the following does NOT cause the execution plan of a query to berecompiled ?- new column is added to a table accessed by a query OR- index used by a query has been dropped from the database OR- query perfoms a join to return data from multiple tables OR- significant amount of data in a table has been mofified

View 1 Replies View Related

Execution Plan Of UDF

Jul 20, 2005

Hi,I have a table-valued user defined function (UDF) my_fnc.The execution of statement "select * from my_fnc" takes much longertime than runnig the code inside my_fnc (with necessary changes).What can be the reason?How can I see an execution plan used for UDF?Thanks a lotMartin

View 1 Replies View Related

Strange Package Startup/execution Slowdown

Aug 9, 2006

We seem to be having a rather strange issue. We just
finished migrating from 2000 to 2005. I've been working on converting packages
from DTS to SSIS. Everything has been going well in testing, but a problem has
shown up going into production. The first package I deployed ran significantly
slower on the production server, going from about 7 seconds to 90 seconds. The
production server is much more powerful, so this was rather confusing. The
major difference is that the server is running 64 bit.



After searching around, I haven't found much that is helpful. To test things
out, I created a blank package that does absolutely nothing. All it contains is
a single connection manager (OLE DB). Executing this package takes 45 seconds.
If I remove the connection manager, it executes in 0.1 seconds. Setting
DelayValidation to TRUE has no effect. If the connection is to a nonexistent
server, or if an incorrect login is used, the execution time is still 45
seconds. Adding a second connection manager increases execution time to 75
seconds. The package runs on my local computer in 0.1 seconds.



Any ideas what could be going on here? I can€™t believe that
no one would have seen an issue like this. Is there some sort of strange
configuration issue going on here?



Thanks in advance.

View 1 Replies View Related

Get Real XML Execution Plan

Jul 9, 2007

 Hi,I want to access the real execution plan via my webapplication after I have executed an SQL statement. I know how to get the estimated execution plan:1 cmd.CommandText = "SET SHOWPLAN_XML ON";2 cmd.ExecuteNonQuery();3 4 cmd.CommandText = myStatement;5 SqlDataReader dataReader = cmd.ExecuteReader();6 7 String plan = String.Empty;8 9 while (dataReader.Read()) {10 plan += dataReader.GetSqlString(0).ToString();11 }12 13 cmd.CommandText = "SET SHOWPLAN_XML OFF";14 cmd.ExecuteNonQuery();I want do compare the estimated costs with the real costs of the same statement. If I change code line 1 an 13 to "SET STATISTICS XML [ON|OFF]" the string "plan" will contain the result of the submitted SELECT statement, but I just need to get the plan and not the result itself. Thanks in Advance,Dominik 

View 6 Replies View Related

Estimated Execution Plan

Jul 28, 1999

What does 'tablename. index... cost: 100%' mean when I use display estimated execution plan?

View 1 Replies View Related

SQL 6.5 Query Execution Plan .

Sep 24, 2002

Hello ,

I wanted to know whether we have an execution plan enabled in SQL 6.5 as we have it in SQL 7.0 and SQL 2000 .
I.e when we execute a query and if we enable ' show execution plan 'then it creates a map and shows the vital statistics .
If that is available on SQL 6.5 then i am missing that tool .

How can i have it installed on my SQL 6.5 server ??

Thanks.

View 3 Replies View Related

Execution Plan Analysis

Jul 9, 2003

Hi,

I want to know how to analyze query execution plan for complex queries and what information is useful from that for improving the performance. I have gone through details in some sites like www.like sql-performance.com (http://www.sql-server-performance.com/query_execution_plan_analysis.asp), where it was more generic. I want more info regarding this.

Can any one tell about the resources for this or do you have any white papers or documents, which you can share with me.


Thanks in advance,
sekhar

View 1 Replies View Related

Execution Plan Different For = And &<&> Operators

Jun 12, 2006

Hi ,

when
operator = then index SEEK
operator <> then index SCAN

Is normal ?

Example

SELECT *
FROM dbo.Batch
WHERE (Status = 'Batch Completed')

(1 row(s) affected)

StmtText
---------------------------------------------------------------------------------------------------------------------------------
|--Bookmark Lookup(BOOKMARK:([Bmk1000]), OBJECT:([PriceAvisPr].[dbo].[Batch]))
|--Index Seek(OBJECT:([PriceAvisPr].[dbo].[Batch].[IX_Batch]), SEEK:([Batch].[Status]='Batch Completed') ORDERED FORWARD)

StmtText
---------------------------------------------------------------------------------
SELECT *
FROM dbo.Batch
WHERE (Status <> 'Batch Completed')

(1 row(s) affected)

StmtText
------------------------------------------------------------------------------------------------------------------------
|--Clustered Index Scan(OBJECT:([PriceAvisPr].[dbo].[Batch].[PK_Batch]), WHERE:([Batch].[Status]<>'Batch Completed'))

View 2 Replies View Related

Execution Plan Degradation

Mar 24, 2008

Hi all,

I am experiencing performance problems with one of my stored procedures. When the stored procedure is first compiled an executed, it behaves as expected (it usually takes 1 or 2 seconds to complete). But its performace it is degradated, so in 1 day, it usually takes 120 seconds to complete !!!. Once the stored procedure is compiled, its performance it is then the expected.

It is a complex stored procedure with two integer parameters with only one select, but composed by multiple views and sub-queries. We have been trying to break the query into small pieces using temporary tables but without success. The SQL Profiler shows an unusual number of reads when it goes wrong (more than a million reads).

I think the problem is in the execution plan. I know than compiling the stored procedure, the problem is fixed, but I do not know exactly when and why it starts to happen.

The stored procedure is running under the following configuration:

- Microsoft SQL Server Standard Edition (64-bit).
- Version: 9.00.1399.06
- RAM 16 MB
- 8 CPUs

Anyone has any ideas or possible solutions?

Thanks in advance,

Carlos.

View 2 Replies View Related

Functions And Execution Plan

Aug 5, 2005

The cost of query with usage of functions is as same as that of withoutfunctionsIn the below code, the query cost of insert is 0.02% and two selectstatements costs same 0.04%Declare @t table(mydate datetime)Declare @i intset @i=1while @i<=5000Begininsert into @t values(getdate())set @i=@i+1EndSelect mydate from @tSelect convert(varchar,mydate,112) from @tBut I thought usage of convert function will take more query costWhat do you think of this?Madhivanan

View 5 Replies View Related

Execution Plan Hinting

Mar 9, 2006

We've got as slightly unusual scenario happening whereby a statement ispassed to SQL which consists of two parts.BEGIN TRANSACTIONDELETE * FROM WhateverBULK INSERT INTO Whatever...(etc)COMMIT TRANSACTIONThe first is a deletion of the data and the second is the bulk insertof replacement data into that table. The error that we see is aviolation of the primary key (composite).The violation only happens if we run both processes together. If we runone, then the other, it works fine. If we set a line by line insert, itworks fine.My suspicion is that the execution plan that is being run is mostlikely working the two parts in parallel and that the records stillexist at the point that the insert is happening. Truncate is not anoption. The bulk insert was added for performance reasons. There is anoption of trying the bulk insert, and if that fails, do the line byline insert, but it's far from ideal.I think we can probably wrap this into two individual transactionswithin the one statement as follows :BEGIN TRANSACTIONDELETE * FROM WhateverCOMMIT TRANSACTIONBEGIN TRANSACTIONBULK INSERT INTO Whatever...(etc)COMMIT TRANSACTIONWill this give sufficient hint to SQL about the order it processes itso that it completes as we intend and not as it sees being the mostefficient method ?Or, is there a better approach to this ?I've seen that some hints can be passed to SQL for optimizing, but myunderstanding was that it was always better to trust the optimiser andre-work the query as needed.With the server having two processors, is it feasible that one is doingone part and the other processor the other part in parallel ? Willtelling it to use a single processor be worthwhile looking at ? MAXDOP1 ?Finally, I'd imagine that the insert is quicker to process than thedeletion. Is this correct ?ThanksRyan

View 14 Replies View Related

Stuck Execution Plan?

May 2, 2006

Using SQL Server 2000 SP4.There is a relatively complex stored procedure that usually completes inless than 20 seconds. Occasionally it times out after 180 seconds. The SPis called via ADO 2.8, using adCmdStoredProc command type. If I useProfiler to capture the EXEC that ADO sends to run the procedure, and runthat from QA, the procedure completes in less than 20 seconds as it should.The procedure is created WITH RECOMPILE. One additional twist is thatsp_setapprole is called from the client before running the procedure inquestion. This may be irrelevant, because even if I include the samesp_setapprole call when running the procedure from QA, it still executesquickly, and even if I comment out the call to sp_setapprole in the clientcode, the proc still times out when run from the client.The only thing that fixes it, at least for a day or two, is DBCCFREEPROCCACHE. So it appears that a bad plan is somehow stuck in memory andis only used when the procedure is called from the client app, and is notflushed even though the procedure was created WITH RECOMPILE.Other than scheduling the DBCC call to run every night, is there anythingelse I could try to get this resolved? Thanks.--(remove a 9 to reply by email)

View 5 Replies View Related

Execution Plan Mystery

May 31, 2006

I was hoping someone could shed some light on wierd situation i'm experiencing. I have the following query:

select count(*) LeadCount
from auto_leads al
where received > dbo.GetDay(GetDate())

dbo.GetDay simply returns a smalldatetime value of today's date.

Now I recently got thrown into a data mess and for some reason this query takes 8 seconds to run. Now the first thing I did was update the stats on the Received column of this auto_leads table. I re-run the query and I'm still getting 8 seconds. I look at the execution plan I can make figure out why this is happening.

I then change the above query so the filter received > dbo.GetDay(GetDate()) is now just received > '5/31/2006' and the query comes back immediately. This doesn't make sense to me because the GetDay function is really simple and comes back immediately. I then try the following query to confirm it isn't a problem with the GetDay function:

declare @Today DateTime

set @Today = dbo.getday(GetDate())

select count(*) leads
from auto_leads al
join type_lead_status tls on (tls.type_lead_status_id = al.type_lead_status_id)
where received > @Today

Sure enough, the query came back immediately. Next thing to go through my mind is that the query execution plan has been cached by SQL Server using the execution plan from before I updated the stats on the received column. So I executed sp_recompile 'auto_leads' and tryed the original query again. Still taking 8-10 seconds to come back.

So my question, is why when I remove the GetDay function call in my query filter is the query slow, as opposed to me just passing a variable into the query? Thanks!

- James

View 6 Replies View Related

Execution Plan Question

Apr 27, 2007

I'm new to sql server 2005 and was reviewing the execution plan on one of my queries.



I have a query that selects about 62,000 rows from a table of about 20 million

I see there is a index seek indicated but further down the execution plan I see that a large percent is being assigned to a RID LOOKUP on the same table.



Should I be concerned with this and if so, what would you recommend I do to correct it?



View 12 Replies View Related

Change Of Execution Plan

Sep 5, 2006

Hi,

We migrated our database from SQL Server 2000 to Yukon last week. Now, when we run our application it has slowed down. We analyzed some stored procedure and they seems to have degarded. The execution plan has changed. Now, this looks like there's lot of work if we have to tune each query w.r.t the new execution plan. Our application has around 4000 stored procs. Is anyone aware of some generic pattern or solution such that these exection plans problem can resolved? Also, does the new execution plan ensure that the once we tune stored procs will perform better than SQL Server 2000.

Need help on this, otherwise it seems we might have to move back to 2000.

Thanks in Advance
Ritesh







View 2 Replies View Related

SQL Compilation And Execution Plan

Jul 5, 2007

Hi all,

I€™m having a test regarding to the image data type. The test program is written with sql native api and just update the image data type column, but I looked the SQL Compilations/sec and Batch Requests/sec counters in SQLServer:QL Statistics using Perfmon, both values are almost the same. It seemed whenever the stored procedure is called, SQLServer compiles it and makes execution plan again. But when I had a test without image data type, SQL Compilation/sec was 0. SQL version is Microsoft SQL Server 2005 - 9.00.3054.00 (Intel X86) (Build 2600: Service Pack 2).

Is SQL server working the way expected or am I missing something?

View 1 Replies View Related

Store Proc Execution Plan

Jun 19, 2003

Is there anyway to force sql server to use the same execution plan?

One of the sp for web page takes about 2 minutes to execute. Once it's executed through query analyser, it takes relatively less time.

Is there any explanation for this?

View 5 Replies View Related

SQL 2012 :: Execution Plan Icons

Apr 8, 2014

I want to find out more information about the execution plan. I saw Parallelism (Gather Streams) in the excution plan. In what situation we can see this icon?If in case if we need to avoid how can we avoid this?

View 5 Replies View Related

SQL 2012 :: How To Check Execution Plan Of A CTE

Jul 4, 2014

We have got a query for fine tuning and it is using lot of CTE ,how can i check the execution plan of that?

CREATE VIEW Mercy
AS
with ADR
as
(
SELECT urpx.RoleID ,
urx.UserID
FROM [DBA].dbo.URPX WITH ( NOLOCK )
INNER JOIN [DBA].dbo.URX WITH ( NOLOCK ) ON urpx.RoleID = urx.RoleID
WHERE PermissionID = '1'
),
SDR
as
(

-- Collect the roles that a configured with Sales Team Create permission

-- This will include Sales Director , Suite Admin,

SELECT urpx.RoleID
FROM [DBA].dbo.URPX WITH ( NOLOCK )
INNER JOIN [DBA].dbo.URX WITH ( NOLOCK ) ON urpx.RoleID = urx.RoleID
LEFT OUTER JOIN ADR ON ADR.UserID = urx.UserID
WHERE ADR.RoleID IS NULL
AND PermissionID='2'
)

View 6 Replies View Related

SQL 2012 :: Sorting Execution Plan

Sep 29, 2014

I have an execution plan that is huge, the pdf it generates if I print it is over 1000 pages. Is there a way to change the graphical plan into a table, so I can sort the %, and find the items that are taking the longest?

View 4 Replies View Related

SQL 2012 :: Same Query But Different Execution Plan

May 15, 2015

I have same query but when executed from different server use different plan. when it runs on QA box it is faster and when it runs on PRD it is slow.

Is it possible to force SQL Server to use QA plan by giving a hint?

View 2 Replies View Related

T-SQL (SS2K8) :: Query Not Use Same Execution Plan?

Jun 5, 2015

if t-sql query is perfectly run in development and when I execute in production at that time I want to use execution plan which is in development . so how I can do using cache? I know about hint we can use hint USE_PLANE. but I want to do with cache .

View 1 Replies View Related

Display Estimated Execution Plan

Apr 4, 2008

What's the use of display estimated execution plan....

View 4 Replies View Related

Execution Plan In Query Analyzer

Jan 31, 2008

This is probably a very stupid question. I have been out of the SQL Server arena for awhile and am now getting re acclimated. It was my understanding that using execution plan in query analyzer does not really execute the query against the query's database tables. Is this right? Tom.

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved