使用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”.
And 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:
A 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.
REPORT zorder_query.
PARAMETERS: descr TYPE crmd_orderadm_h-description OBLIGATORY DEFAULT 'Jerry',
conta TYPE char1 AS CHECKBOX DEFAULT abap_false,
ttype Type crmd_orderadm_h-process_type DEFAULT 'SRVO',
ctype type char1 AS CHECKBOX DEFAULT abap_false.
DATA: lt_selection_parameter TYPE genilt_selection_parameter_tab,
ls_query_parameters TYPE genilt_query_parameters,
ls_selection_parameter TYPE genilt_selection_parameter.
DATA(lo_core) = cl_crm_bol_core=>get_instance( ).
lo_core->load_component_set( 'ONEORDER' ).
IF conta = abap_true.
ls_selection_parameter = VALUE #( attr_name = 'DESCRIPTION' sign = 'I' option = 'CP'
low = |*{ descr }*| ).
ELSE.
ls_selection_parameter = VALUE #( attr_name = 'DESCRIPTION' sign = 'I' option = 'EQ'
low = descr ).
ENDIF.
APPEND ls_selection_parameter TO lt_selection_parameter.
IF ctype = abap_true.
ls_selection_parameter = VALUE #( attr_name = 'PROCESS_TYPE' sign = 'I' option = 'EQ' low = ttype ).
APPEND ls_selection_parameter TO lt_selection_parameter.
ENDIF.
ls_query_parameters-max_hits = 100.
cl_crm_order_timer_home=>start( ).
TRY.
DATA(lo_collection) = lo_core->dquery(
iv_query_name = 'BTQSrvOrd'
it_selection_parameters = lt_selection_parameter
is_query_parameters = ls_query_parameters ).
CATCH cx_root INTO DATA(cx_root).
WRITE:/ cx_root->get_text( ).
RETURN.
ENDTRY.
cl_crm_order_timer_home=>stop( 'Search by Description' ).
WRITE:/ |Number of Service Orders found: { lo_collection->size( ) }| COLOR COL_NEGATIVE.
This report uses CRM BOL API to delegate the query to database layer, which finally executes the following SQL statement.
This 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:
If 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.
Correct 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.
- H5直播避坑指南
- 龙门阵之 DevOps 门外汉须知
- 全面进阶 H5 直播(上)
- 这年头,不会斗图都毕不了业?
- 龙妈也会死?《权力的游戏》 AI 算法预测丹妮女王危在旦夕
- 腾讯云 GAME-TECH 沙龙干货回顾:海外网络拓展及质量把控
- 通过扩展让ASP.NET Web API支持W3C的CORS规范
- 腾讯云GAME-TECH沙龙干货回顾:腾讯游戏云全球化实践
- 腾讯云GAME-TECH沙龙干货回顾:猎豹游戏出海经验分享
- 腾讯云GAME-TECH沙龙干货回顾:绿洲全球化案例分享
- 基于云计算的 CV 移动交互应用研究(1):CV交互+云计算
- ARKit 进阶:物理世界
- HLS 视频点播初探
- 周杰伦读心术背后的技术实现
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- LeetCode 94 | 构造出所有二叉搜索树
- 每日一题 | 最大考试分数问题
- 计算广告——收入分解
- 浅谈mybatis中的占位符
- Python | 详解Python中的协程,为什么说它的底层是生成器?
- 初识Mybatis中的动态sql
- Raw use of parameterized class 'Future'
- javaweb遇到的报错问题以及解决方案(持续更新)
- Spark Java UDAF 输入struct嵌套结构
- 深入理解Java内存模型
- Mybatis高级查询(一):resultMap与resultType
- JDK错误用法—TimSort
- Mybatis高级查询(三):分页查询
- 以OpenResty搭建RTB竞价引擎接入层
- 优化Linux bootloader速度的究极之路:从GRUB到EFI Stub