使用literal或者绑定变量执行SAP HANA SQL语句

简介: 使用literal或者绑定变量执行SAP HANA SQL语句

There are two variants of SQL statement execution defined in SAP note 2000002 – FAQ: SAP HANA SQL Optimization. The difference is how the where condition is specified in SQL Statement.

Sometimes I prefer to call “Literals” as “Hard code”.image.pngAnd for Bind variables, it means the where condition is unknown in compile time, but bound to a variable filled by application logic in the runtime. A typical example:image.pngA caution in SAP note:

It can make a significant difference in terms of execution plan, performance and resource consumption if a SQL statement is executed with explicit literals or with bind variables. Therefore it is recommended that you analyze an expensive SQL statement that uses bind variables in the same way, i.e. also with bind variables.


See a real case to understand it.

I wrote the following report to search all Service Orders whose header “description” field contains specified key word.

image.pngThis report uses CRM BOL API to delegate the query to database layer, which finally executes the following SQL statement.image.pngThis execution belongs to “Bind variables” variant.


As a result, if we would like to paste the SQL statement from ABAP to HANA Studio, we should ensure we have pasted the “correct style” of SQL statement.


Wrong approach

Find statement from Edit->Display Execution Plan->For Recorded Statement:image.pngIf you simply paste the following SQL statement into HANA Studio and execute it there, you actually failed to 100% simulate the ABAP SQL statement’s execution detail in HANA Studio.


The reason is: the SQL statement in ABAP has “Bind variables” variant, and the statement you paste below has “Literals” variant instead: pay attention to the area highlighted in blue below.image.pngCorrect approach

You can use this menu instead to get the appropriate SQL statement to be pasted:


Check the where condition which now has “Bind variables” variant. The variables here have been marked using “?” as placeholder.


Execute it in HANA Studio and there is a new tab “Prepared SQL” displayed. You should fill the actual value for each variable now. Choose “Add Parameter Values” from context menu:


and paste the following string into input field in popup dialog:

504,BUS2000116,BUS2000116,BUS2000140,BUS2000105,BUS2000137,BUS2000131,BUS2000146,BUS2000159,BUS2000153,BUS2000199,Y,%2017-12-21%,SRVO,100


Now each parameter has been automatically filled with corresponding value:


Execute SQL statement in HANA Studio. In this way, it has the same performance result as executed in SAPGUI.


相关文章
|
2月前
|
开发者 数据处理 数据管理
SAP HANA 的不同类型
SAP HANA 的不同类型
SAP HANA 的不同类型
|
2月前
|
SQL 数据库 索引
关于 SAP ABAP REPOSRC 数据库表在 HANA 中的 DDL Definition
关于 SAP ABAP REPOSRC 数据库表在 HANA 中的 DDL Definition
关于 SAP ABAP REPOSRC 数据库表在 HANA 中的 DDL Definition
|
2月前
|
SQL 存储 Oracle
Oracle的PL/SQL定义变量和常量:数据的稳定与灵动
【4月更文挑战第19天】在Oracle PL/SQL中,变量和常量扮演着数据存储的关键角色。变量是可变的“魔术盒”,用于存储程序运行时的动态数据,通过`DECLARE`定义,可在循环和条件判断中体现其灵活性。常量则是不可变的“固定牌”,一旦设定值便保持不变,用`CONSTANT`声明,提供程序稳定性和易维护性。通过 `%TYPE`、`NOT NULL`等特性,可以更高效地管理和控制变量与常量,提升代码质量。善用两者,能优化PL/SQL程序的结构和性能。
|
2月前
|
Linux 开发工具 开发者
关于 SAP HANA 开发那些事
关于 SAP HANA 开发那些事
|
2月前
|
SQL 存储 数据可视化
SAP HANA 内存数据库不同类型的视图的应用场景介绍
SAP HANA 内存数据库不同类型的视图的应用场景介绍
|
2月前
|
数据库 存储 监控
什么是 SAP HANA 内存数据库 的 Delta Storage
什么是 SAP HANA 内存数据库 的 Delta Storage
什么是 SAP HANA 内存数据库 的 Delta Storage
|
14天前
|
SQL 存储 分布式计算
MaxCompute产品使用问题之odps sql如何定义变量
MaxCompute作为一款全面的大数据处理平台,广泛应用于各类大数据分析、数据挖掘、BI及机器学习场景。掌握其核心功能、熟练操作流程、遵循最佳实践,可以帮助用户高效、安全地管理和利用海量数据。以下是一个关于MaxCompute产品使用的合集,涵盖了其核心功能、应用场景、操作流程以及最佳实践等内容。
|
17天前
|
SQL 缓存 Oracle
SQL调优之绑定变量用法简介
SQL调优之绑定变量用法简介
|
2月前
|
SQL 负载均衡 监控
SAP ABAP DBSQL_SQL_ERROR 错误
SAP ABAP DBSQL_SQL_ERROR 错误
|
2月前
|
数据库
什么是 SAP S/4HANA 的 Brown Field 迁移和 Green Field 迁移
什么是 SAP S/4HANA 的 Brown Field 迁移和 Green Field 迁移