Professional Documents
Culture Documents
By the end of this week, you will Using the Optimizer for SQLScript Programming in SAP HANA
understand the following features
Week 1
and functionality
Understanding SAP HANA SQLScript Optimizer
▪ SQL Trace
▪ SQLScript Plan Profiler
▪ M_ACTIVE_PROCEDURES
Week 2
▪ Explain Plan for CALL SAP HANA SQLScript Supportability Features
▪ Plan Visualizer for SQLScript
Week 3
Investigating SQLScript Performance Caused by SQL
Final Exam
SQLScript Debugger
Type and Length Check for Table Parameters
Query Export
SQLScript Debugger
Type and Length Check for Table Parameters
Query Export
SQLScript Engine
SQLScript Optimizer SQLScript Executor
Procedure definition Execution plan
SQL Statement Constant propagation
Control-Flow Control-Flow SQL Statement
Statement Procedure flattening
Statement
CALL Proc SQL Statement Table variable
Inlining
for the result-set
SQL Statement
Control flow simplification
SQL Engine
SQL Optimizer SQL Executor
For an execution plan: Explain Plan for CALL, SQLScript Plan Profiler, Plan Visualizer for SQLScript
SQLScript Engine
SQLScript Optimizer SQLScript Executor
Procedure definition Execution plan
SQL Statement Constant propagation
Control-Flow Control-Flow SQL Statement
Statement Procedure flattening
Statement
CALL Proc SQL Statement Table variable
Inlining
for the result-set
SQL Statement
Control flow simplification
SQL Engine
SQL Optimizer SQL Executor
For execution of control-flow statements: SQLScript Plan Profiler, Plan Visualizer for SQLScript
SQLScript Engine
SQLScript Optimizer SQLScript Executor
Procedure definition Execution plan
SQL Statement Constant propagation
Control-Flow Control-flow SQL Statement
Statement Procedure flattening
Statement
CALL Proc SQL Statement Table variable
Inlining
for the result-set
SQL Statement
Control flow simplification
SQL Engine
SQL Optimizer SQL Executor
For execution of SQL statements: SQL Trace, Plan Profiler, M_ACTIVE_PROCEDURES, Plan Visualizer for SQLScript
SQLScript Engine
SQLScript Optimizer SQLScript Executor
Procedure definition Execution plan
SQL Statement Constant propagation
Control-Flow Control-Flow SQL Statement
Statement Procedure flattening
Statement
CALL Proc SQL Statement Table variable
Inlining
for the result-set
SQL Statement
Control flow simplification
SQL Engine
SQL Optimizer SQL Executor
SQL Trace O
M_ACTIVE_PROCEDURES O
SQLScript Debugger
▪ Mainly for investigating functional issues
▪ A non-optimal execution plan is generated
during debugging
open@sap.com
Follow all of SAP
www.sap.com/contactsap
SQL Trace
▪ Trace information to show the executed SQL
statements and their related information
▪ Show all executed inner statements during
execution of the SQLScript procedure, when
parameter ‘internal’ = ‘true’ in [sqltrace] section is
configured
Recommended for
▪ Checking inner SQL statements reshaped by the
SQLScript optimizer.
▪ Finding out which of the inner SQL statements
consume higher memory or run slowly.
▪ Checking each query plan of the executed inner
SQL statements and their results.
CALL statement
Preparation of inner
SQL statement
COMPILE: 96
Execution of inner
SQL statement
SELECT: 76
Case 1) Literal Values – Inlined SQL statement based on literal value in the call statement
/* procedure: "OPENSAP"."MY_PROC_01" line: 14 col: 5 (at pos 239), procedure: "OPENSAP"."MY_PROC_01" variable: T_RESULT line: 8 col: 9 (at
pos 154) */ WITH "_SYS_T_RESULT_2" AS (SELECT CAST(2 AS INT) + 1 A FROM TAB1) SELECT * FROM "_SYS_T_RESULT_2" "T_RESULT"
Case 2) Parameter Values – 2 separate SQL statements where table resultset stored as local temp table
/* procedure: "OPENSAP"."MY_PROC_01" variable: T_RESULT line: 8 col: 9 (at pos 154) */ SELECT __typed_Integer__($1) + 1 A FROM TAB1
SELECT * FROM "SYS"."_SYS_SS2_TMP_TABLE_166940_T_RESULT_3_92D420B34A160D4FAA1290181F6AEBD0_2" "T_RESULT"
▪ Naming rule for Local temp table for persisted table variable
_SYS_SS_TMP_TABLE_{OID}_{VARIABLE_NAME}_{GUID}_{VOLUME_ID}
SQL Trace shows information about the executed inner SQL statements during execution of
the SQLScript procedure, once parameter ‘internal’ = ‘true’ in [sqltrace] section is configured.
It is important to know the actual SQL statements executed compared to their definition code,
because the SQLScript optimizer reshapes the inner SQL statements.
SQL Trace O
open@sap.com
Follow all of SAP
www.sap.com/contactsap
Recommended for
▪ Understanding how the entire SQLScript procedure
(imperative programming constructs and inner SQL
statements) is executed.
▪ Finding out which part of the code consumes
higher memory or is running slowly.
© 2023 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 2
SQLScript supportability – Plan Profiler
Demo – Collect SQLScript Plan Profiler
Different parameter values let the SQLScript optimizer generate different execution plans
CALL P1('TB’) vs. CALL P1('TA')
Name Description
START_TIME Start time of the operation
END_TIME End time of the operation
DURATION Clock time in microseconds between START_TIME and END_TIME
ACTIVE_TIME_SELF Clock time in microseconds spent in the operation itself, excluding its children
ACTIVE_TIME_CUMULATIVE Total clock time in microseconds spent in the operation itself and its children
CPU_TIME_SELF CPU time in microseconds spent in the operation itself, excluding its children
CPU_TIME_CUMULATIVE Total CPU time in microseconds spent in the operation itself and its children
USED_MEMORY_SIZE_SELF Memory used in the operation itself, excluding its children (in bytes)
USED_MEMORY_SIZE_CUMULATIVE Total memory used in the operation itself and its children (in bytes)
Name Description
START_TIME Start time of the operation
END_TIME End time of the operation
DURATION Clock time in microseconds between START_TIME and END_TIME
ACTIVE_TIME_SELF Clock time in microseconds spent in the operation itself, excluding its children
ACTIVE_TIME_CUMULATIVE Total clock time in microseconds spent in the operation itself and its children
CPU_TIME_SELF CPU time in microseconds spent in the operation itself, excluding its children
CPU_TIME_CUMULATIVE Total CPU time in microseconds spent in the operation itself and its children
USED_MEMORY_SIZE_SELF Memory used in the operation itself, excluding its children (in bytes)
USED_MEMORY_SIZE_CUMULATIVE Total memory used in the operation itself and its children (in bytes)
SQLScript Plan Profiler is a performance analysis tool to show how a procedure actually runs, and
its results are shown in the M_SQLSCRIPT_PLAN_PROFILER_RESULTS monitoring view
open@sap.com
Follow all of SAP
www.sap.com/contactsap
M_ACTIVE_PROCEDURES
▪ A monitoring view to show all internally executed inner
SQL statements starting from the top procedure call
▪ Doesn’t show information about execution of imperative
programming constructs
▪ When a procedure finishes execution, its content in
M_ACTIVE_PROCEDURES is gone by default.
Recommended for
▪ Monitoring SQL procedures execution on the fly
▪ Finding out which inner SQL statements consume higher
memory or run slowly.
M_ACTIVE_PROCEDURES shows information about all the executed inner SQL statements of a
actively running procedure on the fly.
Monitoring can be done with no prerequisites, so it can be done during the middle of a SQLScript
procedure execution that runs unexpectedly slower than normal.
M_ACTIVE_PROCEDURES O
open@sap.com
Follow all of SAP
www.sap.com/contactsap
Recommended for
▪ Checking the execution plan of a SQLScript procedure
without actual execution
CALL P1('TA’)
CALL P1(?)
The Explain Plan for CALL statement shows an execution plan that is the output of SQLScript
optimization without executing the SQLScript procedure.
It doesn’t show the query plan (Explain Plan) of the inner SQL statements
open@sap.com
Follow all of SAP
www.sap.com/contactsap
Plan Visualizer
▪ Shows execution plan and the information about its
actual execution in a visual graph format
▪ Shows statement statistics for all inner SQL
statements
Features
▪ All features of SAP HANA Studio – PlanViz perspective
▪ Load multiple PLV files and keep history of analysis
▪ Visualize query plans in PLV as plan graph
▪ Quick analysis support
▪ Critical path visualization
▪ Bookmark and sharing
▪ Recommendations
▪ SQL Plan Execution Monitor for real-time analysis
▪ Advanced UX for improved usability
OVERVIEW page
▪ Execution summary
▪ Dominant plan operators
▪ Data usage
▪ Distribution
▪ Context
▪ System information
COMPILATION SUMMARY
▪ Shows detail information about the compilation of an
inner SQL statement if it was newly compiled during
PlanViz generation
SQL page
▪ SQL statement
▪ Session variables
▪ Parameter values
TIMELINE property
▪ Display a complete overview of the execution plan based on the visualization of sequential time stamps
▪ Show which operators run in parallel
Plan Visualizer visualizes an execution plan and its execution in a graph format. It contains the
imperative programming constructs and query operation nodes of each SQL statement.
The SQL analyzer tool is the successor to SAP HANA Studio – PlanViz perspective
open@sap.com
Follow all of SAP
www.sap.com/contactsap