Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

SAP Knowledge Base Article

3322936 - How to find the SQL statement hash for a SQL statement string
Component: HAN-DB (SAP HANA > SAP HANA Database), Version: 5, Released On: 18.03.2024

Symptom
You need to do operation on a SQL statement, it need to know the statement hash, but you don't know the statement hash for
the SQL statement string.
The operation can be but not limited to:
Run SQL script HANA_SQL_StatementHash_DataCollector refer to 1969700 - SQL Statement Collection for SAP
HANA
Add hint to a SQL statement refer to 2400006 - FAQ: SAP HANA Statement Hints
Try to find PLAN_ID for a SQL statement and pin it refer to 2222321 - How-To: Pinning SAP HANA SQL Plans

Environment
SAP HANA, platform edition 1.0
SAP HANA, platform edition 2.0

Resolution
Find the statement hash from view M_SQL_PLAN_CACHE.

select STATEMENT_HASH,STATEMENT_STRING from M_SQL_PLAN_CACHE where STATEMENT_STRING like


'%<your_SQL_string>%';

-- If the SQL string is long, you can try <your_SQL_string> to use part of SQL string instead of the whole SQL. e.g. '%
<part A of your_SQL_string>%<part B of your_SQL_string>%'
-- If the SQL string is long and complex, it maybe not easy to find out the STATEMENT_HASH.

Find the statement hash from the SQL trace.

You can check KBA 2031647 for more details of how to create SQL trace. The sqltrace output looks like below:

# statement-hash: 79ccfaeafa43c957754c85e3a3038abc, statement-id: 1445696229845573


cursor_139949406031872_c36602.execute(''' SELECT "UNAM" , "UDAT" , "UTIME" , "DATALG" FROM "REPOTEXT"
WHERE "PROGNAME" = ? AND "R3STATE" = ? AND "LANGUAGE" = ? ''',
(u'''CL_DB6_CALENDAR_ACTION========CP''', u'''A''', u'''E'''))
(***this is only an example, not real output***)

Find the statement hash from the Expensive Statements Trace.

You can check KBA 2180165 for more details of how to create Expensive Statements Trace. Find the statement hash
from view M_EXPENSIVE_STATEMENTS.

select STATEMENT_HASH,STATEMENT_STRING from M_EXPENSIVE_STATEMENTS where


STATEMENT_STRING like '%<your_SQL_string>%';

You also can checked out the statement hash from expensive_statements trace file.

Find the statement hash in SAP GUI.

TRCODE: ST04 – – > Performance – – > SQL Plan Cache menu and find the SQL statement hash based on the SQL
statement string.
Find the statement hash with SQL Statement report.

e.g. use SQL: "HANA_SQL_SQLCache" or SQL: "HANA_SQL_ExpensiveStatements" and populate the SQL_PATTERN
input parameter with the statement text. The output will then provide – among others – the statement hash.

See Also
2031647 - How to enable SQL Trace in SAP HANA Studio
2180165 - FAQ: SAP HANA Expensive Statements Trace
2400006 - FAQ: SAP HANA Statement Hints
1969700 - SQL Statement Collection for SAP HANA

Keywords
M_SQL_PLAN_CACHE, SQL trace, sqltrace, SQL string, STATEMENT_HASH, STATEMENT HASH, hint, EXPENSIVE

Attributes
Key Value

Requires Action 0

Products
Products

SAP HANA 1.0, platform edition

SAP HANA, platform edition 2.0

This document refers to


SAP Note/KBA Component Title

2400006 HAN-DB-PERF FAQ: SAP HANA Statement Hints

2031647 HAN-DB-MON How to enable SQL Trace in SAP HANA Studio

1969700 HAN-DB SQL Statement Collection for SAP HANA

This document is referenced by


SAP Note/KBA Component Title

3444934 How to collect data collector result for a specific SQL

You might also like