Showing posts with label working. Show all posts
Showing posts with label working. Show all posts

Monday, March 26, 2012

Performance Degradation

We have a view in production that have been working fine. Recently, the performance on it has changed signficantly. The view is "union" (not "union all") of select statements on four other views. In the past, it would take a few minutes to return the resultset back, but now, it's taking like 30+ minutes.

The individual select statements only take 1 minutes, 2 minutes, 4 minutes and 9 minutes respectively. But when you run the overall select statement with the unioning of the 4, it takes 30+ minutes. This shows the tempdb resources needed to execute the statement is taxing. When we changed the union to union all, the statement only took 13 minutes to run.

Over the weekend, a decimal field was widened from 9,2 to 11,2. Replication was turned off before the field change and then turned back on after the changes to the field. (I hope I have that replication explained right. I'm not familiar with replication as a process.) There was mention that any custom indexes might have been overwritten/lost due to the replication.

The DBA reindexed all the underlying tables for the views tonight.

My question is if the reindexing doesn't improve the performance. Where else can we check? What else can we do?

Check statistics? Check the transaction log/drive? Does calling a view cause impact on the transaction log? Another thought would be to place indexes on the views. We don't have any in place at the moment.

Unfortunately, I can't post the TSQL due to company rules.

Any ideas to improve the performance would be greatly appreciated.

KenReindexing is a good start. Next you might want to take a look at the query plan. Perhaps, you do not have appropriate index.

Also, if you do not need filtering, consider using 'union all' instead of just 'union'. When you only specify 'union', the system will have to filter out duplicates data. Thus, increase overhead.

Wednesday, March 21, 2012

performance condition alerts are not working

Hi,

I've a problem with my alerts on a SQL 2000 SP3.

I can not add sql server performance condition alerts. The table master..Sysperfinfo is empty.
And the existing ones doe not work properly.

I've already tried unlodctr & lodctr en rebooted the server more than once. But it didn't work.

Can someone help me with this problem ? thanks !!!When you open up performance monitor, do you have any performance counters that work?|||the other performance counters are working. It seems that only sql performance counters aren't working.|||If you go to www.microsoft.com and type in "sql server missing performance counters", the first two posts deal with this issue. See if those help you out.|||I work with sql 2000 sp3 and those solutions apply to sql 6.5 and 7.0. But I do have installed a hotfix of Mdac.
Should I try the workaround described in http://support.microsoft.com/default.aspx?scid=kb;en-us;246328 , although it doesn't mention sql 2000 ?|||I'd check a previous thread (http://www.dbforums.com/t1003397.html) for ideas!

To borrow a line from a signature at SQLTeam.com:

<yoda>
Use the search feature you must. Answers you will find.
</yoda>

-PatP|||I've checked the previous threads and tried some ideas (unlodctr and lodctr) but it didn't work.
can anyone give me another solution ?

THANKSsql

Performance challenge with UNION ALL

Hi all

I have encountered a challenge while working with a UNION ALL statement. At first I was really happy, I had my tsql query go from 1min+ to just above 1sec. Nice...

But my joy didn't last. I have boiled my issue down to this. If I use a variable in my UNION ALL statement it will take approx 50 sec, if I enter a number it will take approx 1 sec. Below is the two queries, the table used contains parent-child relations and my query wan't to recursively fetch all childs and their children etc from the parent with ID = 3939.

My question is now, since this is to be used in a SP, are there any way I can use a variable value in a UNION ALL without my query will be that much slower?

Best regards

Anders

-- Fast example, approx 1 sec

DECLARE @.tempTable TABLE(relationId int);
WITH usesRelations (relationId, childVersionId) AS
(SELECT Id, childVersionID
FROM dbo.relations relation
WHERE relation.ParentVersionID = 3939
UNION ALL
SELECT p.Id, p.childVersionID
FROM dbo.relations AS p INNER JOIN
usesRelations AS A on A.childversionId = p.ParentVersionId
)
INSERT INTO @.temptable SELECT distinct relationID from usesRelations

-- Slow example, approx 50 sec
DECLARE @.ObjectID int
SET @.ObjectID = 3939
DECLARE @.tempTable TABLE(relationId int);
WITH usesRelations (relationId, childVersionId) AS
(SELECT Id, childVersionID
FROM dbo.relations relation
WHERE relation.ParentVersionID = @.ObjectId
UNION ALL
SELECT p.Id, p.childVersionID
FROM dbo.relations AS p INNER JOIN
usesRelations AS A on A.childversionId = p.ParentVersionId
)
INSERT INTO @.temptable SELECT distinct relationID from usesRelations

That is not a fair comparison. May be SQL Server autoparameterized the first statement and used the constant value as the value for the parameter. In the second batch you are using a variable and SQL Server does not uses variables to estimate cardinality. You can use "OPTION (RECOMPILE)" in the "select" statement, or create a stored procedure with parameters, or use sp_executesql also with parameters (I see you are using table variables so this will not be an option).

Code Snippet

create procedure dbo.p1

@.ObjectID int

as

set nocount on

DECLARE @.tempTable TABLE(relationId int);

WITH usesRelations (relationId, childVersionId)

AS

(

SELECT Id, childVersionID

FROM dbo.relations relation

WHERE relation.ParentVersionID = @.ObjectId

UNION ALL

SELECT p.Id, p.childVersionID

FROM dbo.relations AS p INNER JOIN usesRelations AS A on A.childversionId = p.ParentVersionId

)

INSERT INTO @.temptable SELECT distinct relationID from usesRelations

go

exec dbo.p1 3939

go

AMB

|||Thanks for the reply.

The query was to become a stored procedure anyway. I was only having it as a query while i tried optimizing it - but I see now, that it might be an idea to work with it as a stored procedure all the way.

Im not sure i totally understand why SQL server why it has such a huge impact changing a constant with a variable - but anyways...

Making the statement a stored procedure with a parameter instead makes it perfectly fit and fast.

Thanks for helping me out on this one...

/Anders
|||

> Im not sure i totally understand why SQL server why it has such a huge impact changing a constant with a variable - but anyways...

I shouldn't have said that SQL Server does not use variables to estimate cardinality, instead, I should have said that the estimation is not as accurate as when parameters are present, together with useful indexes or statistics.

SQL server uses the values of the parameters during compilation time (when you invoque the sp and there is not a plan in cache) to estimate cardinality based on the expressions in the "where" and "join" clauses. SQL Server does not know the value of variables during that time, or may be is affraid that those values could change before execution the statement, so it uses other estimations, like the value from "All Density" from the statistics. If there is an index or statistic that is useful to estimate cardinality for those expressions, SQL Server uses the histogram when those values are known, like when you recompile the statement (SS 2005).

Statistics Used by the Query Optimizer in Microsoft SQL Server 2005

http://www.microsoft.com/technet/prodtechnol/sql/2005/qrystats.mspx

AMB

Saturday, February 25, 2012

Perform a select asynchronously with ADO (C++)

I'm working with ADO 2.8 en C++ with Visual Studio 2005. I want to perform a "select" in asynchronous mode. I don't really understand the logical of the recordset events. For example, I received a number of MoveComplete event higher than the number of rows in my recordset. It is really not clear for me ...

Does someone knows where I can find a a good example of C++ (or VB) code to manage select statements in asynchronous mode ?

Thanks in advance for your help.

Fran?ois.

ADO Code Examples in Visual C++

other links:

WillMove and MoveComplete Events (ADO)
With Further ADO
Asynchronous Processing (OLE DB)