前言:KingbaseES V8R6C4 之前版本hint 使用方法是与Postgresql 相同的,通过 pg_hint_plan扩展,支持在SQL中使用hint。由于该版本的hint只能放置于SQL开始处,无法对子查询单独使用hint,实际使用非常不方便。由于无法对子查询单独使用hint,对于父查询与子查询使用相同表别名的情况就无法使用hint。从V8R6C4版本开始,KingbaseES 在hint 使用方法上与oracle进行了兼容,hint 只允许放在 select 后面,同时对于子查询,支持使用单独的hint。
一、启用hint支持
V8R6C4之前版本:设置 shared_preload_libraries=‘sys_hint_plan’,重启后,出现参数sys_hint_plan.enable_hint,设置该参数为 on。
V8R6C4:直接设置 enable_hint = on。该版本已直接将hint功能集成到内核中,不需要设置 shared_preload_libraries=‘sys_hint_plan’。
二、hint位置不同
1、V8R6C4之前版本
hint 可以放置于select 前后,甚至explain 之前。具体看以下例子。
没使用hint时的执行计划:
test=# explain analyze select * from t1 where id=123456;
QUERY PLAN
----------------------------------------------------------------------------------------------------------------
Index Scan using ind_t1_id on t1 (cost=0.42..8.44 rows=1 width=208) (actual time=0.021..0.022 rows=1 loops=1)
Index Cond: (id = 123456)
Planning Time: 0.124 ms
Execution Time: 0.038 ms
hint 位置很随意,可以支持以下3种方式:
test=# explain analyze /*+seqscan(t1)*/select * from t1 where id=123456;
QUERY PLAN
---------------------------------------------------------------------------------------------------
Seq Scan on t1 (cost=0.00..8383.00 rows=1 width=208) (actual time=15.768..24.416 rows=1 loops=1)
Filter: (id = 123456)
Rows Removed by Filter: 199999
Planning Time: 0.223 ms
Execution Time: 24.446 ms
(5 rows)
test=# explain analyze select/*+seqscan(t1)*/ * from t1 where id=123456;
QUER

本文介绍了KingbaseES数据库在V8R6C4版本前后,关于SQL提示(hint)的使用变化。V8R6C4之前,hint需放在SQL开始处,限制了对子查询的单独应用;而V8R6C4开始,hint支持放在select后,且子查询可以单独使用,增强了灵活性。同时提到了启用hint的方法及注意事项。
最低0.47元/天 解锁文章
1740

被折叠的 条评论
为什么被折叠?



