Sunteți pe pagina 1din 7

SQL Performance Trace: Overview

SQL Trace
A

record of SQL statements that access the database system

Buffer trace
A

record of data requests for buffered tables

Enqueue trace
A

record of enqueue requests to the enqueue server

RFC trace
A record of received
To obtain an overview of

and sent Remote Function Calls


the behavior of the R/3 System, you can record various processes during
the execution of an individual object. To analyze performance problems with database accesses,
activate the SQL trace and the buffer trace from transaction ST05.
The SQL trace records SQL statements. There may be considerable differences between the SQL
statement formed on the ABAP level and the SQL statement that is received by the database.
A buffer trace lets you trace SQL statements that access buffered tables. SQL statements that access
buffered tables can cause buffer reloads, which are indicated in a buffer trace. An SQL statement
accessing a buffered table can result in a completely different SQL statement if it cannot be satisfied
by the R/3 table buffer.
Additional tools include: the enqueue trace, which records enqueue requests or releases, indicating
the enqueue key and the object involved; as well as the RFC trace, which records the RFC calls
received or sent. These tools are not explained further in this course.
(C) SAP AG BC490 2-12
SAP AG 2002

SQL Performance Trace: Initial Screen


Trace file name D:\sap\KP6\DVEBMGS34\log\TRACE034.LOG
Trace Modes
SQL Trace
Enqueue Trace
RFC Trace
Buffer Trace
Trace Requests
Trace on
Trace on with filter
Trace off
Trace list
Explain one SQL request
State_of_Traces
All traces are switched off
Trace Edit Goto System Help T
Trace requests

To

access the SQL Performance Trace, use transaction ST05 or from the R/3 initial screen, choose
System Utilities SQL Trace.
Before activating an SQL Performance Trace for a report or a transaction, you should execute the
report one time to prevent the buffer load process for the R/3 table buffer, the R/3 program buffer,
and so on, from being included in the subsequent trace.
The trace can be activated in the production system without any risk of creating errors or
inconsistencies.
The trace can be activated by any user and for any object. When activating the trace, ensure that you
are not using multiple user sessions or running other processes such as background jobs or update
processes under the same user ID on this application server. These activities would make the SQL
Performance Trace difficult to interpret.
For each application server, there is only one active trace file. Therefore, on a given application
server, only one user can activate a trace. The default size of the trace file is 800 KB. SAP

recommends increasing the size of the trace file to 16 MB by setting the parameter
rstr/max_diskspace to 16 384 000.
(C) SAP AG BC490 2-13
SAP AG 1999

SQL Performance Trace: SQL Trace Overview


Application Server
R/3 table
buffering
SELECT <field list> FROM vvbak
WHERE ...
R/3 database
interface
ABAP program
Database server
Database
process
Database
buffer
data records

Database
files
SQL
Trace
File
The

R/3 database interface receives an SQL statement from the ABAP program and converts it to an
SQL statement that can be processed by the database.
For each database operation, the SQL trace measures the time taken from the sending of the request
to the database server to the receipt of the results for the request on the application server via the R/3
database interface (including the time spent in the network between the application server and the
database server).
The data written to the trace file includes the database response time, a time stamp, the number of
transferred data records, the database return code, the text of the SQL statement, and additional
administrative information for each database operation.
(C) SAP AG BC490 2-14
SAP AG 2001

SQL Performance Trace: Trace List


Transaction = PID = 9551 Ptype = DIA Client = 100 User
Duration Object Oper Rec RC Statement
41 VVBAP REOPEN 0 0 SELECT WHERE "MANDT" = '100' AND "VBEL
805 VVBAP FETCH 5 1403
41 VVBAP REOPEN 0 0 SELECT WHERE "MANDT" = '100' AND "VBEL
785 VVBAP FETCH 5 1403
41 VVBAP REOPEN 0 0 SELECT WHERE "MANDT" = '100' AND "VBEL
788 VVBAP FETCH 5 1403
40 VVBAK REOPEN 0 0 SELECT WHERE "MANDT" = '100' AND "VBEL
1.061 VVBAK FETCH 10 1403
1.327 VVBAP PREPARE 0 0 SELECT WHERE "MANDT" = :A0 AND "VBELN"
85 VVBAP OPEN 0 0 SELECT WHERE "MANDT" = '100' AND "VBEL
6.919 VVBAP FETCH 49 1403
826 VBAK_VBAP PREPARE 0 0 SELECT WHERE "MANDT" = :A0 AND "VBELN"
41 VBAK_VBAP OPEN 0 0 SELECT WHERE "MANDT" = '100' AND "VBEL
5.924 VBAK_VBAP FETCH 49 1403
800 VVBAK PREPARE 0 0 SELECT WHERE ( T_01 . "MANDT" = :A0 A
46 VVBAK OPEN 0 0 SELECT WHERE ( T_01 . "MANDT" = '100'
5.704 VVBAK FETCH 49 1403
217 VVBAK REOPEN 0 0 SELECT WHERE "MANDT" = '100' AND "VBEL
DDIC info Explain SQL ABAP display Extended list Replace var. Sort

Trace Edit Goto System Help


Basic SQL list - sorted by PID

The trace list is the

same regardless of the database system. Data operations that require more than
100 milliseconds are marked red. Each section of the list has a header identifying the user,
transaction, R/3 work process number, and R/3 client ID. The expanded trace list has the following
columns:
hh:mm:ss:ms Time stamp indicating the begin of sending the database request
(hour:minute:second:millisecond)
Duration Duration of the database operation in microseconds (varies according to
system load)
Program Name of the program calling the SQL statement
Object Name of the table or view, as taken from the SQL statement
Oper Database operation to be executed
Curs Name of the database cursor
ArrSz Size of packets containing the data records sent from the database server to the
application server
Rec Number of data records sent by the database operation
RC Return code of the database system
Statement The text of the SQL statement
(C) SAP AG BC490 2-15
SAP AG 2001

SQL Performance Trace: Database Operations


Application
server
Database
server

SAP cursor cache DB cursor available?


Yes or no
DB SQL Cache Data buffer
SELECT vbeln ...
FROM vvbak
WHERE vbeln = :A1
Shared memory of the database server
DB cursor cache
Data
records
SELECT <field list> FROM vvbak
WHERE vbeln = 0000000100.
ABAP program
PREPARE OPEN FETCH REOPEN FETCH

Database interface
:A1= '0000000100'
During the

processing of an SQL statement performing a read access, the following operations occur:
PREPARE: This operation parses the SQL statement and converts it to a statement that can be
processed by the database. In particular, the access strategy is determined. Placeholders are used
for variables in the SQL statement.
OPEN/REOPEN: This operation replaces the placeholders in the SQL statement with concrete
values, and opens the database cursor.
FETCH: This operation transfers the database records from the database server to the application
server. The number of records transferred per FETCH is given by dividing the length of the data
record to be read in bytes by the value of dbs/io_buf_size, which, by default, is set to 33 792 bytes.
An SQL statement performing a write access is processed in the same way, except that
EXEC/REEXEC is used instead of OPEN/REOPEN and FETCH.

Database

cursors per R/3 work process are buffered in the SAP cursor cache. This enables the
PREPARE operation to be omitted for repeated executions of similar SQL statements. Displacement
occurs in the SAP cursor cache.
(C) SAP AG BC490 2-16
SAP AG 2001

SQL Performance Trace: Explain SQL


SQL Statement
SELECT
"VBELN" , "AUART"
FROM
"VVBAK"
WHERE
"MANDT" = :A0 AND "VBELN" BETWEEN :A1 AND :A2
Execution Plan
SELECT STATEMENT ( Estimated Costs = 3 , Estimated #Rows = 3 )
5 TABLE ACCESS BY INDEX ROWID VVBAK
INDEX RANGE SCAN VVBAK~0
Explain with hint... Optimizer Trace Analyze...
System Help
Show Execution Plan for SQL Statement Table VVBAK
Last statistics date 01.06.2000
Analyze Method Compute
Number of rows 1.000
Number of blocks allocated 626
Number of empty blocks 15
Average space 7.328
Chain count 0
Average row length 454
UNIQUE Index VVBAK~0
Column Name #Distinct
MANDT 1
VBELN 1.000
Index Statistics Analyze...
Table and Index Info for VVBAK

1
2
5
43

access Explain SQL from the trace list, choose Trace Explain SQL. Alternatively, use the
Explain SQL button. Explain SQL is performed for the SQL statement on which your cursor is
currently positioned in the trace list. Explain SQL is only possible for the database operations
PREPARE, OPEN, and REOPEN.
In the top part of the Explain SQL display, you see the SQL statement with its variables. The lower
part of the display shows the access strategy of the SQL statement. The possible access strategies
will be explained later.
Double-click the table frame (see 1 in the Figure) to display a dialog box containing statistical
information on the table and information on all indexes of the table. Double-click an index (see 2) to
display statistical information on it.
Use the Analyze button (see 3) to refresh the statistical information on a table and its indexes. To
enable the cost-based optimizer to function effectively, the statistical information it uses must be
updated after each change to a table or its indexes. Use the Index Statistics button (see 4) to display
an overview of the statistical information across all indexes.
Use the Explain with hint button (see 5) to display the execution path of an SQL statement in
conjunction with hints. Hints are used to force the database to choose a particular execution path.
The available hints are explained later.
To

(C) SAP AG BC490 2-17


SAP AG 2001

SQL Performance Trace: ABAP Display

Transaction = PID = 9551 Ptype = DIA Client = 100 User


Duration Objectname Oper Rec RC Statement
41 VVBAP REOPEN 0 0 SELECT WHERE "MANDT" = '100' AND "VBEL
805 VVBAP FETCH 5 1403
41 VVBAP REOPEN 0 0 SELECT WHERE "MANDT" = '100' AND "VBEL
785 VVBAP FETCH 5 1403
41 VVBAP REOPEN 0 0 SELECT WHERE "MANDT" = '100' AND "VBEL
788 VVBAP FETCH 5 1403
40 VVBAK REOPEN 0 0 SELECT WHERE "MANDT" = '100' AND "VBEL
1.061 VVBAK FETCH 10 1403
1.327 VVBAP PREPARE 0 0 SELECT WHERE "MANDT" = :A0 AND "VBELN"
85 VVBAP OPEN 0 0 SELECT WHERE "MANDT" = '100' AND "VBEL
6.919 VVBAP FETCH 49 1403
826 VBAK_VBAP PREPARE 0 0 SELECT WHERE "MANDT" = :A0 AND "VBELN"
41 VBAK_VBAP OPEN 0 0 SELECT WHERE "MANDT" = '100' AND "VBEL
5.924 VBAK_VBAP FETCH 49 1403
800 VVBAK PREPARE 0 0 SELECT WHERE ( T_01 . "MANDT" = :A0 A
46 VVBAK OPEN 0 0 SELECT WHERE ( T_01 . "MANDT" = '100'
5.704 VVBAK FETCH 49 1403
217 VVBAK REOPEN 0 0 SELECT WHERE "MANDT" = '100' AND "VBEL
DDIC info Explain SQL ABAP display Extended list Replace var. Sort
Trace Edit Goto System Help
Basic SQL list - sorted by PID
119 SELECT vbeln auart FROM vvbak
120 INTO CORRESPONDING FIELDS OF TABLE g_itab_vvbak
121 WHERE vbeln IN g_vbeln.
122
123 IF sy-subrc NE 0. EXIT. ENDIF. " Necessary for the WHERE
124
125 SELECT vbeln posnr matnr FROM vvbap
126 INTO CORRESPONDING FIELDS OF TABLE g_itab_vvbap
127 FOR ALL ENTRIES IN g_itab_vvbak
128 WHERE vbeln = g_itab_vvbak-vbeln.
Aktiv Zeile 119
Pattern Pretty printer
ABAP Editor: Display Program SAPBC490D_SQL_LOGICAL_VIEWS

To

access the ABAP code that triggered the issue of the SQL statement, from the trace list screen,
use the ABAP Display button or choose Trace ABAP Display from the menu. The ABAP coding
is displayed for the SQL statement on which your cursor is currently positioned in the trace list.
Explain SQL is only possible for the database operations PREPARE, OPEN, and REOPEN.
The SQL statement in the ABAP code, which is normally formulated in OPEN SQL, may differ
considerably from the SQL statement processed by the database. The following list indicates how the
R/3 database interface converts certain SQL terms:
A WHERE clause is used for each SQL statement that accesses a client-dependent table (except
for SELECT CLIENT SPECIFIED)
SELECT FOR ALL ENTRIES => Several SELECT statements with corresponding OR clauses
(details later)
MODIFY => INSERT or UPDATE
Accessing pooled and cluster tables
EXPORT/IMPORT TO/FROM DATABASE => INSERT/SELECT on INDX-like tables
OPEN CURSOR/FETCH NEXT => No equivalent in the SQL trace or/ equivalent SELECT
(details later)
(C) SAP AG BC490 2-18
SAP AG 2001

SQL Performance Trace: Summary


Summarize
SQL Trace Edit Goto System Help
SQL Trace: Select Data for Compression
PID Type Time Tcode/Prog Table SQL op Recs time
365 DIA 12:52:59.053 SEU_ VVBAK SEL 276 93.875
365 DIA 12:52:59.079 SEU_ VVBAP SEL 1 1.905

365
365
365
365
365
365
365

DIA
DIA
DIA
DIA
DIA
DIA
DIA

12:52:59.091
12:52:59.088
12:52:59.097
12:52:59.099
12:52:59.084
12:52:59.103
12:52:59.100

SEU_
SEU_
SEU_
SEU_
SEU_
SEU_
SEU_

VVBEP
KKNA1
VVBAP
MMARC
MMARC
VVBEP
KKNA1

SEL
SEL
SEL
SEL
SEL
SEL
SEL

4
2
1
1
1
1
1

1.554
631
3.553
1.493
1.716
1.428
610

Loop
construct

the trace list, choose Goto Summary to display a summarized form of the list. The list shows
the SQL operations, the number of affected data records, and the processing time required.
The summarized list is particularly useful for identifying loop constructs. The list can be compressed
even further to show the most frequently accessed tables by using the Summarize button.
In

(C) SAP AG BC490 2-19


SAP AG 2001

SQL Performance Trace: Statement Summary


10.802
Executions Identical Duration Records ... SQL Statement
833 92 1.103.464 0 SELECT WHERE "MANDT" = '200'
832 96 5
832 0 0 SELECT WHERE "MANDT" = '200'
1 0 5 SELECT WHERE "MANDT" = '200'
DDIC info Explain SQL ABAP display Extended list Replace var. Sort
Statement summary Edit Goto System Help
Summary identical statements sorted by duration
833.668 SELECT WHERE "MANDT" = '200'
790.194
Object
MMARC
KKNA1
VVBEP
VVBAK

Executions Number of identical executions


Identical Percentage of value-identical executions
Duration Total execution time for identical executions in microseconds
Table type For example: TRANSP, VIEW, POOL, CLUSTER
Object Object name

the trace list, choose Goto Statement Summary to find out how many structure-identical SQL
statements there are, and which tables or views they access (a structure-identical strategy is an
identical access strategy with different variables). The displayed list is sorted by the time taken with
time indicated in microseconds.
The list also indicates the percentage of value-identical accesses (identical SELECTs) and the total
number of returned data records. You should avoid all value-identical accesses.
In

(C) SAP AG BC490 2-20


SAP AG 2001

SQL Performance Trace: Identical selects


Executions
4
2
2
2
2
2
2
2
2
2
2
2
Object

VVBAK
VVBAP
VVBAP
VVBAP
VVBAP
VVBAP
VVBAP
VVBAP
VVBAP
VVBAP
VVBAP
VVBAP
WHERE clause
"MANDT" = '100'
"MANDT" = '100'
"MANDT" = '100'
"MANDT" = '100'
"MANDT" = '100'
"MANDT" = '100'
"MANDT" = '100'
"MANDT" = '100'
"MANDT" = '100'
"MANDT" = '100'
"MANDT" = '100'
"MANDT" = '100'
Continue Cancel...
System Help S
Identical Selects

AND
AND
AND
AND
AND
AND
AND
AND
AND
AND
AND
AND

"VBELN"
"VBELN"
"VBELN"
"VBELN"
"VBELN"
"VBELN"
"VBELN"
"VBELN"
"VBELN"
"VBELN"
"VBELN"
"VBELN"

BETWEEN '000000000
= '0000000001'
= '0000000002'
= '0000000003'
= '0000000004'
= '0000000005'
= '0000000006'
= '0000000007'
= '0000000008'
= '0000000009'
= '0000000010'
= '0000000001' OR

choose Goto Identical Selects to see an overview of the value-identical SQL


statements in a trace (a value identical statement has the same access strategy and the same
variables).
Identical SELECTS deliver an identical quantity of data records. Therefore, it makes sense to buffer
the results in, for example, an internal table of the calling ABAP program.
From the number of executions of SQL statements that are similar in value, you can determine the
optimization potential. For example, if there are 4 value-similar executions on table VVBAK,
buffering the resulting data in an internal table makes 3 executions unnecessary. This represents an
optimization potential for this SQL statement of between 60% and 75%.
From the trace list,

S-ar putea să vă placă și