Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Contents
ANALYZING INDIVIDUAL OBJECTS DATABASE ACCESSES
OBJECTIVE
To understand the performance issues in ABAP programming To monitor ABAP performance using SAP Tools To analyze ABAP performance problems To solve ABAP performance problems causing
High Database Load High CPU Load
1. 2.
Sending the user request to the application server. Placing the user request in the dispatcher queue if all R/3 work processes are occupied. Assigning the user request to an R/3 work process. Rolling the user context in to the R/3 work process. Attempting to satisfy the SQL statement from the R/3 buffer.
Dispatcher 2 3
3. 4.
Disp Que
Roll Buffer
13
4
User context
Application Server
5.
6.
7. 8.
12 Roll File
R/3 database interface
5 11
9. 10.
10
9
Database Process Database Buffer
11. 12.
Database Server
13.
Memory allocation:
R/3 work process R/3 table buffers Data buffers of database Database on disks 5 MB 120 MB 500 MB Several terabytes
Network
Wait time
Roll in
Load Time
Processing Time
N E T W O R K
Database Time
Response Time
Presentation Server
Application Server
Database Server
SQL Trace-Details
Application Server ABAP Program SELECT <field list> FROM vbak WHERE SQL Trace File
Database files
Database Process
Database buffer
Database interface
PREPARE in trace OPEN in trace FETCH in trace REOPEN in trace FETCH in trace
Data Records
Database Server DB SQL cache SELECT mandt FROM VBAK WHERE vbeln = :A1 DB cursor cache A1 Databuffer
Data Buffer
DB SQL Cache
R/3 work process
DB Work process
Data Base
Database files
Identical Selects:
Always avoid (instead, buffer in program, buffer beyond roll area limit)
SQL statements that are similar in structure have an identical access strategy with possibly different values for the placeholders. The latter are also called identical selects. To display an overview of the SQL statements within a trace that are similar in value, choose Goto>>Identical Selects. Identical SELECTS deliver an identical quantity of data records. Therefore it makes sense to buffer the results in 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 VBAK, buffering the resulting data in an internal table makes 3 executions unnecessary. This represents an optimization potential of 75% for this SQL statement
Initial situation: You need to analyze a performance-critical individual object that shows poor database performance
Compressed summary
Are there SQL statements that take longer than 200,000 ms?
Problem classification: Unsuitable Access path
Are there nested SQL statements with the same structure that, as a group, take longer
than 200,000 ms?
Identical SELECTs for individual objects Are there SQL statements with the same values?
Problem classification: Change in Design
Estimated Costs
SELECT STATEMENT
SELECT STATEMENT
Search range (area of table that needs to be searched for required records)
Index Introduction
Table block
ROW ID MANDT VBELN ERDAT ERZET ERNAM
Index B* tree
Root tree
62522 65873
001 002
Branch blocks
Root and branch blocks contain pointers to the next index level Leaf blocks
ROW ID 65332 65252 Index block 62522 62525 62390 95252 95452
Primary Index
The primary index contains the key fields of the table and a pointer to the nonkey fields of the table. The primary index is created automatically when the table is created in the database
Secondary Indexing
Secondary Indexes
Table SCOUNTER
SELECT * FROM SCOUNTER WHERE AIRPORT = LCY.
AIRPORT P MANDT CARRID COUNTNUM AIRPORT
Binary search
ACA ACE BER BER DEN FRA HAM LCY LCY LGW LHR LHR MUC RTM
1 2 3 6 7 8 14 4 9 10 5 11 12 13
001 001 001 001 001 001 001 001 001 001 001 001 001 001
LH BA UA LH BA LH AA LH BA LH LH BA LH LH
00000005 00000004 00000001 00000002 00000003 00000007 00000001 00000003 00000001 00000001 00000004 00000002 00000006 00000008
ACA ACE BER LCY LHR BER DEN FRA LCY LGW LHR MUC RTM HAM
Table blocks
ROW ID MANDT VBELN 62522 65873 001 002 ERDAT ERZET ERNAM
Unique index
(Primary index or Unique secondary index)
Branch
ROW ID MANDT VBELN ERDAT ERZET ERNAM 75892 001 0000163 04006149 055123 JIM 95883 002 0000646 03429737 310529 JOHN
Index blocks
65872 65873
001 002
MANDT 001 001 001 001 001 002 002 VBELN 0000121 0000123 0000123 0000123 0000124 0000126 0000127
POSNR ROW ID 0001 65332 0001 65252 0002 62522 0003 62525 0004 62390 0005 95252 0006 95452
4 MANDT VBELN POSNR ROW ID 001 0000121 0001 65332 001 0000122 0001 65252 Index search string: 0010000123%
Index
POSNR
MATNR
Index not used for full table scan Each table block is read once only Max. no. of logical read accesses per execution = no. of table blocks
ROW ID MANDT VBELN POSNR MATNR 75892 001 0000163 04006149 055123 95883 002 0000646 03429737 310529 ROW ID MANDT VBELN POSNR MATNR 75892 001 0000163 04006149 055123 95883 002 0000646 03429737 000815
to DB In
Concatenation
SELECT * FROM VBAP WHERE VBELN IN ( 0000123, 0000133, 0000143). ENDSELECT. ROW ID MANDT VBELN POSNR MATNR ..
MANDT 001 001 001 001 001 002 002 VBELN 0000121 0000122 0000123 0000124 0000125 0000126 0000127
POSNR ROW ID 0001 65332 0001 65252 0002 62522 0003 62525 0004 62390 0005 95252 0006 95452
ROW ID MANDT VBELN POSNR MATNR 75892 001 0000163 04006149 055123 95883 002 0000646 03429737 310529
MANDT VBELN POSNR ROW ID 001 0000121 0001 65332 001 0000122 0001 65252
Summary
Index Unique Scan: The index selected is unique (primary index or unique secondary index) and specified fully. One or no table record is returned. This type of access is very effective, because a maximum of four data blocks need to be read. Index Range Scan: The index selected is unique or non-unique. In the case of a unique index, not all index fields are specified in the WHERE clause. A range of the index is read and checked. An index range scan may not be as effective as a full table scan. The table records returned can range from none to all. Full Table Scan: The whole table is read sequentially. Each table block is read once. Since no index is used, no index blocks are read. The table records returned can range from none to all. Concatenation: An index is used more than once. Various areas of the index are read and checked. To ensure that the application reads each table record only once, the search results are concatenated, and duplicate entries are eliminated. The table records returned can range from none to all.
SELECT vbeln erdat erzet FROM v v b a k INTO TABLE g_itab_v v b a k WHERE vbeln BETWEEN 0000000001 AND 0000000005.
BETWEEN operator
SELECT vbeln erdat erzet FROM v v b a k INTO TABLE g_itab_v v b a k WHERE vbeln IN (0000000001, 0000000002, 0000000003, 0000000004, 0000000005).
IN operator
Replace WHERE field LIKE value with WHERE field = value
Omit WHERE field LIKE %
Sort in ABAP
Creating/Changing Index
General rules Disjunctive indexes only No unintentionally used indexes As few indexes as possible per table (as few as possible,but as many as necessary) Selection of index fields As few fields as possible in index As selective fields as possible in index Selective fields as near to the beginning as possible Do not change SAP standard indexes unless recommended by SAP
Database HINT
SELECT * from vvbap INTO TABLE g_itab_vvbap WHERE ABGRU IN (01,02,03,04,05) %_HINTS ORACLE index(VVBAP VVBAP~
INDEX (TableIndex) : Index range scan over one index FIRST_ROWS ALL_ROWS : Use the access path that returns the first records as fast as possible : Use the access path that returns all records a fast as possible
CLUSTER TABLES
CLUST_A
CLUST_B
PHYSICAL VIEW
DATABASE TABLES
Pooled and clustered tables group several logically defined tables from the ABAP dictionary
in a physical database table. In pooled tables, data is located in a table pool whereas in a clustered pool, data is located in a table cluster.
Cluster Table
Cluster table TABA TIMESTAMP
Table cluster
PAGELG
AA
TABAB
B B
0 1
C G
D H
E I
F J
F A B E
Key fields
SELECT bukrs belnr FROM bseg INTO TABLE g_itab_bsid WHERE kunnr = 0000000100. SELECT MANDT,BUKRS,.. FROM RFBLG
SELECT bukrs belnr FROM bsid INTO TABLE g_itab_bsid WHERE KUNNR = 0000000100 SELECT BURKS, MANDT, FROM BSID
Pooled table
Pooled table TABA DATALN Table pool TABAB A B C D
C F
D G H I
TABB
TABNAME
VARKEY
VARDATA
Key
SELECT kappl kschl vkorg vtweg matnr FROM aa005 INTO TABLE g_itab_aa005
WHERE kappl = CS and kschl = SAPZ AND vkorg = 0001 AND vtweg = 01 AND kunnr = 0000000009 AND matnr = 000000000000000027
The WHERE conditions in the SQL statement refer to key fields in table aa005. Therefore, all conditions are transferred to the database in field VARKEY. The database interface incorporates the ORDER BY clause for fields TABNAME and VARKEY which are key fields in the table pool.
Unselective access
AA005 fully buffered on application server Repeated database read is not necessary Remove AA05 from table pool KAPOL and create index for MATNR Efficient data read is possible
Selective access
Buffering Techniques
In a production system, the following tables rarely change
Small tables Tables that are mainly accessed for reading Control tables, Customizing tables, or 'small' master data tables
Buffering types
Full Buffering
Full Buffering
Database table SCOUNTER
MANDT CARRID COUNTNUM AIRPORT
Buffer contents
001 001 001 001 001 001 001 001 001 001 001 001 001 001 AA BA BA BA BA LH LH LH LH LH LH LH LH UA 00000001 00000001 00000002 00000003 00000004 00000001 00000002 00000003 00000004 00000005 00000006 00000007 00000008 00000001 ACA ACE BER LCY LHR BER DEN FRA LCY LGW LHR MUC RTM HAM
001 001 001 001 001 001 001 001 001 001 001 001 001 001
AA BA BA BA BA LH LH LH LH LH LH LH LH UA
00000001 00000001 00000002 00000003 00000004 00000001 00000002 00000003 00000004 00000005 00000006 00000007 00000008 00000001
ACA ACE BER LCY LHR BER DEN FRA LCY LGW LHR MUC RTM HAM
Application server SELECT * FROM SCOUNTER WHERE MANDT = 001 AND CARRID = LH AND COUNTNUM = '00000004'.
R
SAP AG
Generic Buffering
Generic Buffering
Database table SCOUNTER
MANDT CARRID COUNTNUM AIRPORT
Buffer contents
001 001 001 001 001 001 001 001 LH LH LH LH LH LH LH LH 00000001 00000002 00000003 00000004 00000005 00000006 00000007 00000008 BER DEN FRA LCY LGW LHR MUC RTM
001 001 001 001 001 001 001 001 001 001 001 001 001 001
AA BA BA BA BA LH LH LH LH LH LH LH LH UA
00000001 00000001 00000002 00000003 00000004 00000001 00000002 00000003 00000004 00000005 00000006 00000007 00000008 00000001
ACA ACE BER LCY LHR BER DEN FRA LCY LGW LHR MUC RTM HAM
Application server
Generic key
SAP AG
SELECT * FROM SCOUNTER WHERE MANDT = 001 AND CARRID = LH AND COUNTNUM = '00000004'.
R
Buffer contents
001 LH 00000004 LCY
001 001 001 001 001 001 001 001 001 001 001 001 001 001
AA BA BA BA BA LH LH LH LH LH LH LH LH UA
00000001 00000001 00000002 00000003 00000004 00000001 00000002 00000003 00000004 00000005 00000006 00000007 00000008 00000001
ACA ACE BER LCY LHR BER DEN FRA LCY LGW LHR MUC RTM HAM
Application server
SELECT SINGLE * FROM SCOUNTER WHERE MANDT = 001 AND CARRID = LH AND COUNTNUM = '00000004'.
R
SAP AG
Table Buffering
IMPORTANCE: Means of keeping the table data in the buffer of the application server after the first access. Buffering allows you to read the data from main memory next time it is accessed, thus saving a further database access. Using buffered tables improves the performance considerably. STATEMENTS BYPASSING BUFFER: SELECT DISTINCT ORDER BY / GROUP BY / HAVING CLAUSE ANY WHERE CLAUSE THAT CONTAINS A SUB QUERY OR IS NULL EXPRESSION. JOINS A SELECT . FOR UPDATE
ABAP runtime environment SET RUNTIME ANALYZER ON LOOP AT itab ENDLOOP SET RUNTIME ANALYZER OFF
Gross Net
Gross time is the total time required to execute the relevant functions.
Net time is the gross time minus the time taken by any modularization units and separate statements (which can be limited in the ABAP runtime initial screen using variants).
The net time is the time that is not otherwise accounted for. If the gross time is the same as the net time, these times are not indicated separately. You can display times either as a percentage or as absolute times in microseconds.
Initial situation: You need to analyze a performance-critical individual object that shows poor database performance
Limit analysis set to full aggregation with no other filter Obtaining the run data in the current user session Are there critical program parts ort statements that contribute more than 10% of the total runtime? Limit analysis to not aggregated or aggregated per calling position, and limit filter to critical
program parts or statements
Obtaining the run data in the current user session Are there problems during the use of internal tables? Internal table: Wrong Table Type or Wrong Access method