Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

view more efficient than before or not? Expand / Collapse
Author
Message
Posted Tuesday, April 16, 2013 5:23 PM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: 2 days ago @ 12:46 PM
Points: 1,776, Visits: 3,222
I have a view, if we runs it individually in SSMS, it runs ok, but we have a batch process at night that uses it for each individual. so overall it makes the process slow.

Now we change the view to hopefully speed it up. But I would like to compare with older version ,
which version runs faster. By running both of them in SSMS, I cannot see much difference, is there a way to see which view cost less time?

I run it in SSMS with Execution plan, I see in :
older version: Sort cost : 58%, Clustered Index scan: 41%
new version: Sort 53%, Clustered index scan 47%

So their total is all 100%, so how can I know which one is more efficient ?
I know we probably can figure that out by running our overnight process, but it usually takes more thatn 3 hours to find out?

Post #1443054
Posted Tuesday, April 16, 2013 6:50 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: 2 days ago @ 11:39 PM
Points: 227, Visits: 2,012
There really isnt much information to go on here.
If you can post the ACTUAL execution plans and the definitions for both views that would be a start.
Post #1443062
Posted Tuesday, April 16, 2013 7:44 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Yesterday @ 8:14 PM
Points: 37,107, Visits: 31,665
sqlfriends (4/16/2013)
Now we change the view to hopefully speed it up.



...but we have a batch process at night that uses it for each individual. so overall it makes the process slow.


I believe that changing the view might not do any good. I've highlighted the problem that I think is the real problem above.

I run it in SSMS with Execution plan, I see in :
older version: Sort cost : 58%, Clustered Index scan: 41%
new version: Sort 53%, Clustered index scan 47%



Perhaps you don't understand that a Clustered Index Scan is really nothing more than a Table Scan. That's what you need to work on first and then you need to work on the "for each" problem.

If you really want help with a performance problem, then read the article at the 2nd lik in my signature below.


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1443070
Posted Tuesday, April 16, 2013 11:59 PM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Yesterday @ 3:43 PM
Points: 43,047, Visits: 36,206
sqlfriends (4/16/2013)
I have a view, if we runs it individually in SSMS, it runs ok, but we have a batch process at night that uses it for each individual. so overall it makes the process slow.


You've tested and benchmarked and confirmed that the view is absolutely the problem with the batch process?

Now we change the view to hopefully speed it up. But I would like to compare with older version ,
which version runs faster. By running both of them in SSMS, I cannot see much difference, is there a way to see which view cost less time?


Run the queries, compare the execution characteristics (via Profiler or the statistics settings). The plan's costings do not tell you how long it will run.



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1443099
Posted Wednesday, April 17, 2013 2:43 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Tuesday, September 16, 2014 1:50 PM
Points: 1,904, Visits: 793
Batch process means SSIS package ?
If you are using SSIS, recently I came across a situation that extracting data using a view from SSIS slower but running the same view in SSMS is faster.

"SSIS - views as data source - very poor performance or SSIS hangs".

Please refer the below links.

http://connect.microsoft.com/SQLServer/feedback/details/258901/ssis-views-as-data-source-very-poor-performance-or-ssis-hangs

http://blogs.msdn.com/b/sqlperf/archive/2007/04/29/set-up-ole-db-source-to-read-from-view-efficiently.aspx


Regards,
Rals
.
Post #1443151
Posted Wednesday, April 17, 2013 10:12 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: 2 days ago @ 12:46 PM
Points: 1,776, Visits: 3,222
GilaMonster (4/16/2013)
sqlfriends (4/16/2013)
I have a view, if we runs it individually in SSMS, it runs ok, but we have a batch process at night that uses it for each individual. so overall it makes the process slow.




Yes, we changed the view at first to accommdate other data change, it slows down the night process. That is why we know it is the view. Then we tried to optmimize the view.
Post #1443363
Posted Wednesday, April 17, 2013 10:13 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: 2 days ago @ 12:46 PM
Points: 1,776, Visits: 3,222
rals (4/17/2013)
Batch process means SSIS package ?
If you are using SSIS, recently I came across a situation that extracting data using a view from SSIS slower but running the same view in SSMS is faster.

"SSIS - views as data source - very poor performance or SSIS hangs".

Please refer the below links.

http://connect.microsoft.com/SQLServer/feedback/details/258901/ssis-views-as-data-source-very-poor-performance-or-ssis-hangs

http://blogs.msdn.com/b/sqlperf/archive/2007/04/29/set-up-ole-db-source-to-read-from-view-efficiently.aspx


Thanks, the night process actually use a web service not SSIS.
Post #1443365
Posted Wednesday, April 17, 2013 10:21 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: 2 days ago @ 12:46 PM
Points: 1,776, Visits: 3,222
Jeff Moden (4/16/2013)
sqlfriends (4/16/2013)
Now we change the view to hopefully speed it up.



...but we have a batch process at night that uses it for each individual. so overall it makes the process slow.


I believe that changing the view might not do any good. I've highlighted the problem that I think is the real problem above.

I run it in SSMS with Execution plan, I see in :
older version: Sort cost : 58%, Clustered Index scan: 41%
new version: Sort 53%, Clustered index scan 47%



Perhaps you don't understand that a Clustered Index Scan is really nothing more than a Table Scan. That's what you need to work on first and then you need to work on the "for each" problem.

If you really want help with a performance problem, then read the article at the 2nd lik in my signature below.


We know it is the sort part makes it slower, but it seems we don't have any choice.
For clustered index scan, because this is a view of schema binding, it uses the index , the index is the PK of the underlying table, I don't know why view make it to index scan not index seek
Post #1443371
Posted Wednesday, April 17, 2013 10:24 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 7:48 AM
Points: 23,400, Visits: 32,257
Unfortunately, without seeing the the DDL for the view and the underlying table(s) and their indexes, plus how the view is being called I don't see how much more we can actually do to help. Anything we provide at this point will be nothing more than shots in the dark.



Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #1443372
Posted Wednesday, April 17, 2013 10:33 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Yesterday @ 3:43 PM
Points: 43,047, Visits: 36,206
sqlfriends (4/17/2013)
For clustered index scan, because this is a view of schema binding


Schema binding does not cause table scans.

Please post table definitions, index definitions and execution plan, as per http://www.sqlservercentral.com/articles/SQLServerCentral/66909/



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1443376
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse