1.1 HINT机制
在SQL执行过程中,有时系统自动优化的方式并不是最优的,需要手工添加hint来提高查询效率。
具体语法如下:
{ select|… } /*+ [local] var_name1(value1),var_name2(value2) */ from ...
OR
{ select|… } /*+ [local] var_name1(value1) */ /*+ var_name2(value2) */ from ...
语法说明:
1) select等是标识一个语句块开始的关键字,包含提示的注释只能出现在这些关键字的后面,否则提示无效。
目前GBase 8s中支持hint的关键字如下:select、replace、initnodedatamap、refreshnodedatamap、rebalance、create table、create consumer group 组名(组的注释)、create resource pool 资源池名、create resource plan 计划名、create resource directive 指令名、create database、alter table、alter database、rename table、drop table、drop database、insert、merge(into)、update、delete、truncate(table)、show、flush、refresh、load、set、release。hint要添加在这些关键字后面,括号中的关键字是可以省略的。其中set、show 不支持hint统一机制,只支持以关键字方式使用的hint。
create table as select 和insert select由于使用一个select_lex结构,因此hint写在create table 后面或insert后面和写在 select 后面是等价的。
2) “+”号表示该注释是一个hint,该加号必须立即跟在”/*”的后面,中间不能有空格。
3) 如果包含多个提示,则每个提示之间需要用一个逗号隔开或者使用多个hint结构。
4) var_name只能是可修改的session变量, global变量或只读变量在hint中不生效。
5) value值只能是常量,不支持表达式。
注:
1) 进入客户端的命令要添加–c参数,否则hint不起作用。GBase client默认是跳过提示,对提示不解析,加上-c参数,client将提示发送给GBase server进行解析。
2) local关键字是可选参数,表示hint只属于当前的select级,不会往后面的select级传递。




