55
1 Advanced ASE Performance Tuning Tips Janis Griffin Senior DBA / Performance Evangelist

Advanced ASE Performance Tuning Tips

Embed Size (px)

Citation preview

Page 1: Advanced ASE Performance Tuning Tips

1

Advanced ASE Performance Tuning Tips

Janis Griffin

Senior DBA / Performance Evangelist

Page 2: Advanced ASE Performance Tuning Tips

2© 2015 SOLARWINDS

Who Am I?

» Senior DBA / Performance Evangelist for Solarwinds§ [email protected] § Twitter - @DoBoutAnything§ Current – 25+ Years in Oracle, Sybase, SQL Server§ DBA and Developer

» Specialize in Performance Tuning» Review Database Performance for Customers and

Prospects» Common Thread – Paralyzed by Tuning

Page 3: Advanced ASE Performance Tuning Tips

3© 2015 SOLARWINDS

Before we start, do you know…

» The most important problem in your database instance?»

» If that new program is hurting database performance?»

» Did that recent fix really solved the database issue?»

» Which bottlenecks in your database directly impacted end-user service?

»

Page 4: Advanced ASE Performance Tuning Tips

4© 2015 SOLARWINDS

Agenda - 4 Tips

» Focus on Tuning Queries

» Utilize Response Time Analysis (RTA)

» Examine Query Execution Plans

» Use SQL or Query Diagramming§ Who registered yesterday for Tuning Class§ Check order status§ Current paychecks for specific employees§

Page 5: Advanced ASE Performance Tuning Tips

5© 2015 SOLARWINDS

Why Focus on Queries

» Most Applications§ Read and Write data to/from database§ Simple manipulation of data§ Deal with smaller amounts of data

» Most Databases§ Examine larger amounts of data, return a little§ Inefficiencies quickly become bottleneck

» Why do SQL tuning?§ “Gives the biggest bang for your buck”§ Changes to SQL are Safer§ Most of performance issues are SQL related

Page 6: Advanced ASE Performance Tuning Tips

6© 2015 SOLARWINDS

Challenges Of Tuning

» SQL Tuning is Hard § Who should tune – DBA or Developer§ Which SQL to tune§

» Requires Expertise in Many Areas§ Technical – Plan, Data Access, SQL Design§ Business – What is the Purpose of SQL?§

» Tuning Takes Time§ Large Number of SQL Statements§ Each Statement is Different§

» Low Priority in Some Companies§ Vendor Applications§ Focus on Hardware or System Issues§

» Never Ending

Page 7: Advanced ASE Performance Tuning Tips

7© 2015 SOLARWINDS

Which SQL to Tune

Methods for Identifying

» User / Batch Job Complaints§ Known Poorly Performing SQL§ Trace Session/Process§

» Queries Performing Most I/O (LIO / PIO)§ Table or Index Scans

» Queries Consuming CPU

» Highest Response Times - DPA (formally Ignite)

Page 8: Advanced ASE Performance Tuning Tips

8© 2015 SOLARWINDS

Response Time Analysis (RTA)

§Understand the total t ime a Query spends in Database§Measure t ime while Query executes§SAP ASE helps by providing Wait Events

Focus on Response Time

Page 9: Advanced ASE Performance Tuning Tips

9© 2015 SOLARWINDS

Wait Time Tables (ASE 12.5.0.3+)

http://froebe.net/blog/wp-content/uploads/2013/09/ASE-15.7-Monitoring-Tables-Diagram-Sybase-Inc_.pdf

Page 10: Advanced ASE Performance Tuning Tips

10© 2015 SOLARWINDS

Response Time Query

» MDA Query Example

SELECT mP.Login, mP.DBName, mPL.ClientHost, RTRIM(mPL.Application), mPP.ObjectName, mP.WaitEventID, mPS.SQLText, mPS.BatchID, mPS.LineNumber, mP.LineNumber CurrentLineNumberFROM monProcessSQLText mPS, monProcessLookup mPL, (monProcess mPLEFT OUTER JOIN monProcessProcedures mPP ON mP.SPID=mPP.SPID AND mP.KPID=mPP.KPID)WHERE mP.SPID=mPL.SPID AND mP.KPID=mPL.KPIDAND mP.SPID=mPS.SPID AND mP.KPID=mPS.KPIDAND coalesce(mP.FamilyID,0) = 0 AND mP.BatchID > 0

Page 11: Advanced ASE Performance Tuning Tips

11© 2015 SOLARWINDS

Top Wait Events At Server Level

select WaitEventID, convert(numeric(16,0),Waits) as "Waits", convert(numeric(16,0),WaitTime) as "WaitTime" into #waits1 from monSysWaitsgoselect Description, convert(int,sum(w.Waits)) as "Count", convert(int,sum(w.WaitTime)/1000) as "Seconds" from #waits1 w, monWaitEventInfo ei where w.WaitEventID = ei.WaitEventID group by Description order by 3 desc

Page 12: Advanced ASE Performance Tuning Tips

12© 2015 SOLARWINDS

RTA – Proactive

Refreshed on :08/12/14 02:35:18 PM

Page 13: Advanced ASE Performance Tuning Tips

13© 2015 SOLARWINDS

Users Complain: 10am – 12pm Slow

Top 15 SQL Statements | GIBSON:5000 | August 8, 2014 to August 12, 2014Daily Time Range: 10:00 AM-12:00 PM

Page 14: Advanced ASE Performance Tuning Tips

14© 2015 SOLARWINDS

RTA – Firefighting

Day: Tuesday – August 10,2014 Refreshed on: 08/12/2014 05:09:57 PM

Page 15: Advanced ASE Performance Tuning Tips

15© 2015 SOLARWINDS

RTA - Blocking Issue

Day: Tuesday – August 10,2014 Refreshed on: 08/12/2014 05:02:02

SQL Statements Executed by Blocking Session 125 while Holding the Lock | GIBSON:5000August 10, 2014 – 12:00PM to 4:00PM

Page 16: Advanced ASE Performance Tuning Tips

16© 2015 SOLARWINDS

RTA – Long Term Trends

Top 15 SQL Statements | GIBSON:5000 | July 31,2014 to August 24, 2014

Page 17: Advanced ASE Performance Tuning Tips

17© 2015 SOLARWINDS

RTA – Current Problem

Refreshed on: 08/12/2014 05:34:42 PM

Page 18: Advanced ASE Performance Tuning Tips

18© 2015 SOLARWINDS

RTA – Current Problem

Refreshed on: 08/12/2014 05:39:06 PM

Page 19: Advanced ASE Performance Tuning Tips

19© 2015 SOLARWINDS

Identify End-to-END Time

Accurate End-to-End Response Time Analysis

Page 20: Advanced ASE Performance Tuning Tips

20© 2015 SOLARWINDS

Get Table & COLUMN Info

» Understand objects in execution plans§ Table Definitions & Segment sizes

• Is it a View – get underlying definition• Number of Rows / Partitioning

§ Examine Columns in Where Clause• Cardinality of columns • Data Skew / Histograms

§

§ Statistic Gathering • Tip: Out-of-date statistics can impact performance

» Understand expensive data access targets§ TableScans versus IndexScans§

» Know the indexes – if multi-column, order is important

Page 21: Advanced ASE Performance Tuning Tips

21© 2015 SOLARWINDS

Get The Execution Plan

» SET SHOWPLAN ON § set statistics io, time on

simulate, subquerycache, plancost

§ set noexec on http://help.sap.com/Download/Multimedia/ASE_16.0/ptstats.pdf

» Interactive SQL (Sybase iAnyWhere or SAP dbisql) § Plan Viewer– must execute query§ Details, XML & Advanced (abstract & missing)

» Abstract Plans-sysqueryplans /sysquerymetrics§ sp_configure'enable metrics capture', 1

» Application Tracing (v15.0.2+)§ set tracefile "<file-path>" for <spid>§ Works when you know a problem will occur

Page 22: Advanced ASE Performance Tuning Tips

22© 2015 SOLARWINDS

Get The Execution Plan - tracing

set statistics plancost onset tracefile ’/db1/trc/trc32.tx’ for 32

Page 23: Advanced ASE Performance Tuning Tips

© 2015 SOLARWINDS

Examine the Execution Plan

» Find Expensive Operators§ Examine cost of each step§ Look for full table or index scans

» Review the ‘restrict’ & ‘sort’ operators§ Are the ‘restrict’ steps early in plan? § Large sorts that don’t fit into memory§ Look for Implicit conversions when using parmeters

» Review JOIN operators§ Nested loop

• effective when there is a useful index available§ Merge Join

• good when most of the rows must be processed and they are already sorted by join keys

§ Hash Join• good when most of the rows from source sets are processed

§ Nary Nested Loop • More efficient when you have more than 2 nested loops

23

Page 24: Advanced ASE Performance Tuning Tips

© 2015 SOLARWINDS

Engineer out the Stupid

» Look for Performance Inhibitors

§ Cursor or row by row processing

§ Parallel processing - OLAP vs OLTP§

§ Hard-coded Hints§

§ Nested views that use link servers

§ Abuse of Wild Cards (*) or No Where Clause§

§ Code-based SQL Generators (e.g. Hibernate)§

§ Non-SARG-able / Scalar Functions• Select… where upper(first_name) = ‘JANIS’

24

Page 25: Advanced ASE Performance Tuning Tips

25© 2015 SOLARWINDS

Execution Plan Example

Page 26: Advanced ASE Performance Tuning Tips

26© 2015 SOLARWINDS

» Who registered yesterday for SQL Tuning

SELECT s.FNAME, s.LNAME, r.SIGNUP_DATEFROM STUDENT s INNER JOIN REGISTRATION r ON s.STUDENT_ID =

r.STUDENT_IDINNER JOIN CLASS c ON r.CLASS_ID = c.CLASS_IDWHERE c.NAME = 'SQL TUNING'AND r.SIGNUP_DATE BETWEEN @BegDate AND

@EndDateAND r.CANCELLED = 'N‘

Case Study 1

Page 27: Advanced ASE Performance Tuning Tips

27© 2015 SOLARWINDS

Relationship Diagram for Tables in Query

Page 28: Advanced ASE Performance Tuning Tips

28© 2015 SOLARWINDS

Execution Plan

Page 29: Advanced ASE Performance Tuning Tips

29© 2015 SOLARWINDS

SQL Diagramming

» Great Book “SQL Tuning” by Dan Tow§ Great book that teaches SQL Diagramming§ http://www.singingsql.com

REGISTRATION

STUDENT CLASS

5

1

30

1

.05

.002

select count(1) from registration where cancelled = 'N'and signup_date between '2015-01-29 00:00' and '2015-01-30 00:00'

4,141 / 79,999 = 0.05

select count(1) from class where name = 'SQL TUNING'

2 / 1,000 = .002

Page 30: Advanced ASE Performance Tuning Tips

30© 2015 SOLARWINDS

create index cl_name ON CLASS(NAME)

New Execution Plan

Why would an TableScan still occur on REGISTRATION?

Page 31: Advanced ASE Performance Tuning Tips

31© 2015 SOLARWINDS

Database Diagram

Page 32: Advanced ASE Performance Tuning Tips

32© 2015 SOLARWINDS

create index reg_alt on REGISTRATION(CLASS_ID)

New Execution Plan

Page 33: Advanced ASE Performance Tuning Tips

33© 2015 SOLARWINDS

create index reg_alt ON REGISTRATION (CLASS_ID, SIGNUP_DATE,CANCELLED)

Better Execution Plan

Page 34: Advanced ASE Performance Tuning Tips

34© 2015 SOLARWINDS

» Lookup Shipment Status for caller

SELECT o.OrderID, c.FirstName, c.LastName, p.ProductID, p.Description, s.ActualShipDate, s.ShipStatus, s.ExpectedShipDateFROM SalesOrder oINNER JOIN OrderItem i ON i.OrderID = o.OrderIDINNER JOIN Customer c ON c.CustomerID = o.CustomerIDINNER JOIN Shipment s ON s.ShipmentID = i.ShipmentIDLEFT OUTER JOIN Product p ON p.ProductID = i.ProductIDLEFT OUTER JOIN Address a ON a.AddressID = s.AddressIDWHERE c.LastName LIKE ISNULL('Griffin','') + '%'AND o.OrderDate >= DATEADD(day, -30,getdate())AND s.ShipStatus <> 'C'order by LastName

Case Study 2

Page 35: Advanced ASE Performance Tuning Tips

35© 2015 SOLARWINDS

Database Diagram

Page 36: Advanced ASE Performance Tuning Tips

36© 2015 SOLARWINDS

Execution Plan

Page 37: Advanced ASE Performance Tuning Tips

37© 2015 SOLARWINDS

SQL Diagramming

o .02

.005

SELECT COUNT(1)*1.0/(SELECT COUNT(1) FROM Customer) FROM Customer WHERE LastName LIKE 'Griffin%'0.005

SELECT COUNT(1)*1.0/(SELECT COUNT(1) FROM [SalesOrder]) FROM [SalesOrder] WHERE OrderDate >= DATEADD(day, -30, GETDATE()).02

SELECT COUNT(1)*1.0/(SELECT COUNT(1) FROM [Shipment]) FROM [Shipment] WHERE ShipStatus <> 'C'.04

i c

ps

a

.04

Page 38: Advanced ASE Performance Tuning Tips

38© 2015 SOLARWINDS

New Execution Plan

» CREATE INDEX CUST_LASTNAME ON Customer(LastName)

»

Page 39: Advanced ASE Performance Tuning Tips

39© 2015 SOLARWINDS

SQL Diagramming

o .02

.005

SELECT COUNT(1)*1.0/(SELECT COUNT(1) FROM Customer) FROM Customer WHERE LastName LIKE 'Griffin%'0.005

SELECT COUNT(1)*1.0/(SELECT COUNT(1) FROM [SalesOrder]) FROM [SalesOrder] WHERE OrderDate >= DATEADD(day, -30, GETDATE()).02

SELECT COUNT(1)*1.0/(SELECT COUNT(1) FROM [Shipment]) FROM [Shipment] WHERE ShipStatus <> 'C'.04

i c

ps

a

.04

Page 40: Advanced ASE Performance Tuning Tips

40© 2015 SOLARWINDS

CREATE INDEX SALESORDER_ODATE ON SalesOrder (OrderDate)

New Execution Plan

Page 41: Advanced ASE Performance Tuning Tips

41© 2015 SOLARWINDS

SQL Diagramming

o .02

.005

SELECT COUNT(1)*1.0/(SELECT COUNT(1) FROM Customer) FROM Customer WHERE LastName LIKE 'Griffin%'0.005

SELECT COUNT(1)*1.0/(SELECT COUNT(1) FROM [SalesOrder]) FROM [SalesOrder] WHERE OrderDate >= DATEADD(day, -30, GETDATE()).02

SELECT COUNT(1)*1.0/(SELECT COUNT(1) FROM [Shipment]) FROM [Shipment] WHERE ShipStatus <> 'C'.04

i c

ps

a

.04

Page 42: Advanced ASE Performance Tuning Tips

42© 2015 SOLARWINDS

Data Skew Problems

» Only 4% of rows are <> ‘C’» How about changing the query?

§ AND s.ShipStatus = 'I'

» Add Histogram on ShipStatus

SELECT ShipStatus, COUNT(1)CntFROM [Shipment]GROUP BY ShipStatus

Page 43: Advanced ASE Performance Tuning Tips

43© 2015 SOLARWINDS

UPDATE STATISTICS example.dbo.Shipment (ShipStatus)go

New Execution Plan

Page 44: Advanced ASE Performance Tuning Tips

44© 2015 SOLARWINDS

Case Study 3

» Current paychecks for specific employees

SELECT e.empno, e.first_name, e.last_name, d.dname,l.street_address,l.city, l.state_province, l.postal_code FROM emp e INNER JOIN dept d ON e.deptno = d.deptno INNER JOIN loc l ON d.location_id = l.location_id WHERE (e.first_name = @first or e.last_name = @last) AND EXISTS ( SELECT 1 FROM wage_pmt w WHERE w.empno = e.empno AND w.pay_date>= DATEADD(day,-31,GETDATE()) )

» Execution Stats – 6681 Logical I/O» Average Execution - 15.012 seconds» Resource - 99% CPU

Page 45: Advanced ASE Performance Tuning Tips

45© 2015 SOLARWINDS

Execution Plan

Page 46: Advanced ASE Performance Tuning Tips

46© 2015 SOLARWINDS

SQL Diagramming

select count(1) from wage_pmtwhere pay_date >= DATEADD(day,-31,GETDATE())

109568 / 1027192 = .106

select max(cnt), min(cnt) from (select last_name, count(1) cnt from emp group by last_name)

128 / 6848 = .018 – max64 /= 6848 = .009 – min

emp

dept

wage_pmt

1000

1

150

1

.02

.10

loc1

9

.009

Page 47: Advanced ASE Performance Tuning Tips

47© 2015 SOLARWINDS

New Execution Plan

» create index IX_EMP_LN on emp(last_name)» Create index IX_EMP_FN on emp(first_name

Page 48: Advanced ASE Performance Tuning Tips

48© 2015 SOLARWINDS

Wage_Pmt table – no index on empno

Page 49: Advanced ASE Performance Tuning Tips

49© 2015 SOLARWINDS

Better Execution Plan

» create index IX_WAGE_EMPNO on wage_pmt(empno)»

»

»

»

»

»

»

»

»

»

»

Execution time = 0.546 seconds

Page 50: Advanced ASE Performance Tuning Tips

50© 2015 SOLARWINDS

Best execution Plan

Covered Index:create index IX_EMP on emp(empno, last_name, first_name, deptno)

Time: 0.066 secs

Page 51: Advanced ASE Performance Tuning Tips

51© 2015 SOLARWINDS

Monitor

» Monitor the improvement§ Be able to prove that tuning made a difference§ Take new metric measurements§ Compare them to initial readings§ Brag about the improvements – no one else will

» Monitor for next tuning opportunity§ Tuning is iterative§ There is always room for improvement§ Make sure you tune things that make a difference

» Shameless Product Pitch - DPA

Page 52: Advanced ASE Performance Tuning Tips

52© 2015 SOLARWINDS

Improved Performance

Average Wait Time per Execution for SQL Statement Current Paychecks by Name | GIBSON:5000 March 15, 2015

Daily Time Range: 5:00 PM-12:00 AM

Logical Reads = 1198 Execution Time = .066 seconds

Page 53: Advanced ASE Performance Tuning Tips

© 2015 SOLARWINDS

Takeaway Points

» Tuning Queries gives more “bang for the buck”» Make sure you are tuning the correct query» Use Wait Events and Response Time Analysis

§ Locking problems may not be a Query Tuning issue§ Wait Events tell you where to start

» Use “Execution or Query Plans”» SQL Diagramming - “Get it right the First Time”

§ Query Tuner Tools can mislead you

» Monitor for next tuning opportunity

Page 54: Advanced ASE Performance Tuning Tips

www.solarwinds.com/dpa-download/

Resolve performance issues quickly—free trial

Try Database Performance Analyzer FREE for 14 daysImprove root cause of slow performance

Quickly identify root cause of issues that impact end-user response time

See historical trends over days, months, and years Understand impact of VMware® performance Agentless architecture with no dependence on Oracle Packs,

installs in minutes

Page 55: Advanced ASE Performance Tuning Tips

© 2014 SOLARWINDS WORLDWIDE, LLC.  ALL RIGHTS RESERVED.

The SOLARWINDS and SOLARWINDS & Design marks are the exclusive property of SolarWinds Worldwide, LLC, are registered with the U.S. Patent and Trademark Office, and may be registered or pending registration in other countries. All other SolarWinds trademarks, service marks, and logos may be common law marks, registered or pending registration in the United States or in other countries. All other trademarks mentioned herein are used for identification purposes only and may be or are trademarks or registered trademarks of their respective companies.

Thank You!

Q & A