Enable_hint_table 使用
KingbaseES enable_hint_table 可以看成类似 oracle outline 工具,可以在不修改SQL 的情况下,通过hint 改变SQL 的执行计划。
一、启用enable_hint_table
1、设置shared_preload_libraries 参数,增加 sys_hint_plan , 重启数据库
2、修改参数 sys_hint_plan.enable_hint=on , select sys_reload_conf()
3、create extension sys_hint_plan ;创建后,会新建 hint_plan.hints 表。
4、设置 set sys_hint_plan.enable_hint_table = on
二、举例说明
1、没使用 hint_plan.hints 时的执行计划
test=# delete from hint_plan.hints;
DELETE 1
test=# explain analyze select * from t1 where t1.id1 = 1;
QUERY PLAN
---------------------------------------------------------------------------------------------------------------
Bitmap Heap Scan on t1 (cost=4.20..13.67 rows=6 width=44) (actual time=0.002..0.002 rows=0 loops=1)
Recheck Cond: (id1 = 1)
-> Bitmap Index Scan on ind_t1 (cost=0.00..4.20 rows=6 width=0) (actual time=0.001..0.001 rows=0 loops=1)
Index Cond: (id1 = 1)
Planning Time: 0.067 ms
Execution Time: 0.011 ms
(6 rows)
默认情况下,SQL 走索引扫描。
2、使用 hint_plan.hints
通过在 hint_plan.hints 插入一条记录,提示使用 SeqScan。
test=# insert into hint_plan.hints(norm_query_string, application_name, hints) VALUES ( 'Explain analyze select * from t1 where t1.id1 = ?;','','SeqScan(t1)');
INSERT 0 1
test=# Explain analyze select * from t1 where t1.id1 = 1;
QUERY PLAN
----------------------------------------------------------------------------------------------
Seq Scan on t1 (cost=0.00..24.12 rows=6 width=44) (actual time=0.004..0.004 rows=0 loops=1)
Filter: (id1 = 1)
Planning Time: 0.169 ms
Execution Time: 0.017 ms
(4 rows)
这里有两个地方需要注意:
1、SQL 后面必须有个 “;” ,否则会因为SQL 不匹配而不生效
2、application_name='' ,表示任意应用,注意中间没有空格,否则会因为应用不匹配而不生效
三、SQL 匹配
1、空格不匹配,无法使用hint_table
test=# explain analyze select * from t1 where t1.id1 =1;
QUERY PLAN
---------------------------------------------------------------------------------------------------------------
Bitmap Heap Scan on t1 (cost=4.20..13.67 rows=6 width=44) (actual time=0.002..0.002 rows=0 loops=1)
Recheck Cond: (id1 = 1)
-> Bitmap Index Scan on ind_t1 (cost=0.00..4.20 rows=6 width=0) (actual time=0.001..0.001 rows=0 loops=1)
Index Cond: (id1 = 1)
Planning Time: 0.069 ms
Execution Time: 0.011 ms
(6 rows)
2、别名不匹配,无法使用hint_table
test=# explain analyze select * from t1 a where a.id1 = 1;
QUERY PLAN
---------------------------------------------------------------------------------------------------------------
Bitmap Heap Scan on t1 a (cost=4.20..13.67 rows=6 width=44) (actual time=0.003..0.003 rows=0 loops=1)
Recheck Cond: (id1 = 1)
-> Bitmap Index Scan on ind_t1 (cost=0.00..4.20 rows=6 width=0) (actual time=0.002..0.002 rows=0 loops=1)
Index Cond: (id1 = 1)
Planning Time: 0.053 ms
Execution Time: 0.012 ms
(6 rows)
3、大小写不匹配,可以使用hint_table
test=# explain analyze select * from t1 WHERE t1.id1 = 1;
QUERY PLAN
----------------------------------------------------------------------------------------------
Seq Scan on t1 (cost=0.00..24.12 rows=6 width=44) (actual time=0.002..0.002 rows=0 loops=1)
Filter: (id1 = 1)
Planning Time: 0.080 ms
Execution Time: 0.008 ms
(4 rows) test=# explain analyze select * from T1 where t1.id1 = 1;
QUERY PLAN
----------------------------------------------------------------------------------------------
Seq Scan on t1 (cost=0.00..24.12 rows=6 width=44) (actual time=0.002..0.002 rows=0 loops=1)
Filter: (id1 = 1)
Planning Time: 0.076 ms
Execution Time: 0.008 ms
(4 rows)
Enable_hint_table 使用的更多相关文章
随机推荐
- SAP 定义客户端
SCC4 定义客户端 点击新建条目按钮 Client(客户端) R 200 Client Name(客户端名称) O City(城市) R Logical system(逻辑系统) R ...
- Django快速入门之项目配置
开始 环境 python:3.6.2 django:2.0.5 跑起来 用pycharm导入或新建一个Django项目,在目录中存在manage.py的文件,通过下列指令运行Django后台. pyt ...
- 来用python自己做一个闹钟吧
闹钟 是一种具有可以在预先设定的时间被激活以响铃的功能的时钟,用于唤醒打工人们. 使用Python中的DateTime模块来创建闹钟,并用Python中的playsound库来播放闹钟声音.~~~## ...
- svn提交报错Unexpected HTTP status 413 'Request Entity Too Large' on
问题原因:nginx的client_max_body_size设置过小,默认 1M,如果请求的正文数据大于client_max_body_size,HTTP协议会报错 413 Request Enti ...
- 程序分析与优化 - 9 附录 XLA的缓冲区指派
本章是系列文章的案例学习,不属于正篇,主要介绍了TensorFlow引入的XLA的优化算法.XLA也有很多局限性,XLA更多的是进行合并,但有时候如果参数特别多的场景下,也需要进行分割.XLA没有数据 ...
- leetcode教程系列——Binary Tree
tree是一种常用的数据结构用来模拟真实物理世界里树的层级结构.每个tree有一个根(root)节点和指向其他节点的叶子(leaf)节点.从graph的角度看,tree也可以看作是有N个节点和N-1个 ...
- 发评测赢好礼 | Serverless 函数计算征集令
随着云计算发展,云原生热度攀升,Serverless 架构崭露头角且发展势头迅猛.不仅被更多开发者所关注,市场占有率也逐年提高.阿里云函数计算(Function Compute)是一个事件驱动的全托管 ...
- 常用的Linux命令和Git的必要配置
常用的Linux命令平时一定要多使用这些基础的命令! 1.cd : 改变目录. 2.cd . . 回退到上一个目录,直接cd进入默认目录 3.pwd : 显示当前所在的目录路径. 4.ls(ll): ...
- BufferedWniter_字符缓冲输出流和BufferedReader_字符缓冲输入流
java.io.BufferedWriter extends Writer BufferedWriter:字符缓冲输出流 继承自父类的共性成员方法: -void write(int c)写入单个字符 ...
- 4-12 Spring Security + JWT
Spring Security + JWT 此前,在处理登录的业务中,当视为登录成功时,返回的字符串并不是JWT数据,则应该将此数据改为必要的JWT数据. @Service public class ...