HOW TO VALIDATE SQL PERFORMANCE TUNING VIA SAP ST04 SQL CACHE
Sometimes, you have to tune SQL to improve SAP program performance. After SAP SQL tuning is done, is new SQL statement having better performance than original SQL statement? This post would show you an example on how to verify this via SAP ST04 SQL cache.
1 The background
ST04 SQL cache showed that one SQL was a top expensive SQL statement based on CPU utilization.
2 Tuning on the SQL in SAP ABAP program
To improve the performance, SQL is tuned in the way that source table was swapped from /SAPAPO/MATKEY to /SAPAPO/MATMAP since primary key of /SAPAPO/MATKEY matches existing selection criteria and new table returns same result under the same selection criteria. Please refer to Figure 1 to know the new code and old code—
Figure 1 Old code and new code
The change is quite simple and done in SAP SCM system. So would the new SQL have better performance than the old SQL?
3 Performance validation on the tuned SQL via ST04 SQL cache
Since all executed SQL statements would be kept SQL cache with many performance metrics like response time, CPU time etc. So both old SQL and new SQL execution history data is available in the system. That data is pulled and showed in Figure 2.
Figure 2 ST04 SQL Cache
Figure 2 shows that each execution of new SQL accessing /SAPAPO/MATMAP table is spending about 13,006,591 microseconds against 21,495,315+ microseconds spent by old SQL statements accessing /SAPAPO/MATKEY. That is at least 39% performance improvement on CPU time consumption per SQL execution.
Total CPU time consumed by a SQL is the times of two numbers – CPU time per SQL execution and number of times which the SQL is executed. Improvement on individual SQL execution is not a guarantee for overall improvement if number of SQL execution is increased.
In this particular case, Figure 1 shows the change is just replacing the old table with a new table without logic changes. So number of times which the SQL should be executed would not be changed after tuning. Also Figure 2 shows number of rows retrieved (column Rows/Exec) per SQL execution has no big difference between new SQL and old SQL and it also shows 43+% improvement on SQL elapsed time/execution. So the SQL/ABAP performance tuning is successful based on ST04 SQL cache performance analysis.
So far, ST04 SQL cache performance analysis helped us to achieve our goal – whether the SQL/ABAP tuning is good/bad for performance. You might wonder why it helped to improve performance by a simple table swap? The developer replaced the old table with the new table since EXT_MATNR is a primary key of /SAPAPO/MATMAP (Figure 5). Reading a table via primary key is faster – is this the reason for the performance improvement? If you would like to know more, continue readingJ.
4 Why changes make a performance improvement
A tuned SQL can make performance improvement due to many reasons – execution plan, table size etc.
4.1 Execution plan comparison
Figure 3 is the SQL execution plan with original table before the change. Figure 4 is the SQL execution plan with the new table.
Figure 3 SQL Execution plan before change
Figure 4 SQL execution plan after change
From the above execution plan, we can see that primary key is not used to read the new table. It is using the “Full table scan”. Index /SAPAPO/MATKEY~MAT has only “MATNR” field. Comparing cost of SQL execution plan between old table and new table, you can see “Estimated Costs” with the new table is 788 against 1,223 with old table.
Figure 5 Table structure
Based on the code and new table structure, the primary key could be used to read the table normally. Why not? We need table size information to understand this.
4.2 Review table size
Using ST04 SQL command editor, We can enter SQL and execute it to get following information from Oracle table DBA_TABLES .
Figure 6 – Number of table records
So number of rows is similar but average row length is different – this is approved by the table size from DB02 transaction (Figure 4)
Figure 7 – Table storage size
So the new table is almost 1/3 of old table in size.
4.3 Performance improvement
When an index is used to access a table data record, Oracle would need to read index block to get address for the data block and then it would fetch data block. When number of records needed reaches a threshold, it would be more efficient to bypass index and read data block directly. In this particular case, whenever the sql is executed, it would fetch 247K record out of 250K records. So the full table access is used by Oracle with the new table. So the performance improvement is coming from a much smaller table and full table access not due to primary index with the new table.
5 Other methods for validating a SQL performance tuning
There are other ways to determine whether a SQL tuning in SAP program is good to performance.
Based on program runtime difference – Get program runtime before and after changes against same testing data.
Based on analysis of program execution statistics – statistics for program execution before changes and statistics for program execution after changes.
Based on performance trace analysis – Do a before and after trace.
Based on technical analysis like where-clause and table index.
Each of above method has their own pros and cons. You need to choose the best one fit for your case. For example, when you measure the performance by program/job runtime or execution statistics, you need to be sure that runtime is not impacted by many factors like volume, application lock and database lock, resource contention etc. If you changed many SQL statements in a program to tune performance, it might be a tedious work to find out how each change is performing.
Someone might notice that the cost in the execution plan with a new table is lower. You cannot say for sure that lower cost means faster access when different table are involved. Even with the same table, an execution plan with a “lower” cost can be a bad plan – that is why Oracle provides Oracle hints for program to influence execution plan. So using cost is not an error-proof method to measure performance of two different SQL statements.
In this post, I have used ST04 SQL cache to validate performance improvement from SQL tuning. You can click How to run ST04 for more information.
HOW TO VALIDATE SQL PERFORMANCE TUNING VIA SAP ST04 SQL CACHEVALIDATE SQL PERFORMANCE TUNING;SQL CHANGE PERFORMANCE ANALYSIS;SQL TUNING PERFORMANCE MEASUREMENT; ST04 SQL CACHE
Post navigation
PREVIOUS POST
Subscribe to:
Post Comments (Atom)
Labels
sap hana
hana database
aws s4 hana
hana db
s4hana conversion steps
sap hana azure
bw4hana
hana migration
s4hana migration
sap cloud migration steps
sap hana migration steps
sap hana migration to azure
s4hana
sap fiori
fiori
performance
fiori erp
s4 hana fiori
sap fiori app
sap fiori client
sap fiori launchpad
sap s4 hana fiori
cisco
ecc
AI
SAP AI
abap dumps
hana
sap
S/4HANA
S/4HANA Conversion
best sap ui5 & fiori training
configuration
database
fiori tutorial on webide
free sap ui5 & fiori training
s/4 hana
sap dumps
sap fiori tutorial
sap ui5
sap ui5 & fiori
sap ui5 & fiori tutorial
sara
ui5cn
2367245 - Troubleshooting performance issues with SAP BPA
Amazon free tier for SAP AWS setup Experience
CALL_FUNCTION_NOT_FOUND
CCMS Configuration and Use
Create New Data Class in SAP (Oracle)
Critical top SAP Abap dumps
DHCP Clients Not Receiving IP Addresses
Download Stack.xml
HAN-DB
HAN-DB-ENG
High CPU Usage Due to Excessive Process Switching
How To
How to Start and Stop SAP Hana Tenant Database
How to change SAP Hana Sql Output results are limited to 5000 Records
How to perform SAP Dual Stack Split - Netweaver
Inactive Objects in SAP
Intercompany transactions in SAP AP / AR : Cross Company Code Transaction
Interface Flapping Due to Duplex Mismatch
KBA
LOAD_PROGRAM_LOST
MSSQL shrinking transaction log file
Migrating to SAP hana database
NAT Overload Causing Internet Access Failure
Note 500235 - Network Diagnosis with NIPING
OSPF Adjacency Not Forming
PRINCE2 Foundation Sample Questions
Preparing for S/4HANA Conversion and the MUST know items
Push to Download Basket
S/4HANA Migration Cockpit
S/4JANA
SAP BI Support Data Load Errors and Solutions
SAP BI/BW Landscape
SAP BPA
SAP Basis
SAP Basis Automation
SAP Business Objects
SAP CPS
SAP Certification
SAP FI Certification
SAP FI Certification Sample Questions
SAP HANA Admin - Cockpit
SAP HANA DB Engines
SAP HANA Database
SAP HANA terminate session connection disconnect cancel kill hang stuck
SAP Hana DB restore
SAP Hana Numeric Error Codes
SAP Landscape
SAP Language installation
SAP MM and Purchase Order Tables
SAP Maintenance Planner
SAP Note 500235
SAP R/3 Glossary
SAP Readiness Check
SAP S/4HANA 1709 Installation Files
SAP S/4HANA 2023
SAP S/4HANA 2023 Installation
SAP S/4HANA 2023 running
SAP S/4HANA Installation
SAP Scheduling
SAP Solman 7.2 CHARM:
SAP Support Package Stack Strategy
SAP Support package
SAP Upgrade
SAP support stack upgrade
SP stacks
STORAGE_PARAMETERS_WRONG_SET
SUSE/SLES/Kernel versions
Setup of S/4hana 2023
TSV_TNEW_PAGE_ALLOC_FAILED
TSV_TNEW_PAGE_ALLOC_FAILED error
Transaction ID
Unable to download an SAP Note
Unix/Linux Command That Are Helpful For SAP Basis
Upgrading SAP Kernel Without Downtime
Upgrading windows server 2008 to windows server 2019
What is OSS Notes? SAP SNOTE Tutorial
accounting
agile
ale idoc
ale/edi
archive FI documents
audit
auditing
auditor
aws
aws cloud
basic type
bluefield approach
ccms
ccmsidb
charm
copilot
datavard
dbacockpit
download sap note
download snote
edi idoc
electronic data interchange
enable sap archiving objects
erpprep
ffid
firefighter
fraud
functional
hana admin
how to apply sap security note
https://www.erpprep.com/
idoc
install
install sap fiori
installation
interfaces
intermediate document
internal control
license key
linux version
materials management
messsage
niping test
order type
port
prince2 agile
prince2 agile practitioner
purchasing
quick info
s4 hana
sap abap dumps
sap abbreviations
sap activate certification
sap activate project manager
sap authorization
sap aws
sap brownfield
sap ccms
sap ccms configuration
sap erp
sap error
sap grc
sap greenfield
sap internet demo system
sap license
sap maintenance certificate
sap material management
sap meaning
sap mm
sap mm consultant
sap monthly security note
sap netweaver
sap network diagnostic
sap niping
sap note
sap oss
sap patch day
sap performance
sap performance issue
sap purchase order
sap s/4hana
sap sales and distribution
sap sap otc
sap sd
sap sd certification training
sap sd course
sap sd jobs
sap sd module
sap sd online training
sap sd training
sap sd tutorial
sap sd tutorial for beginners
sap security
sap security note
sap snote
sap snote tutorial
sap solution manager
sap sql
segregation of duties
separation of duties
sles
slicense
smc
snote
snote in sap system
sod conflict
solution manager
solution maneger
stop start hana database
suse linux
techie
trex
two step upgrade required
waterfall
1 comment:
Validating SQL performance will be curious. It is awesome post. Kindly know maggam work blouse designs
Post a Comment