lightdb21.3-支持语句级hint
Posted 紫无之紫
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了lightdb21.3-支持语句级hint相关的知识,希望对你有一定的参考价值。
lightdb21.3-新增支持语句级hint及支持qb_name
之前版本,优化器提示作用于整条SQL,从21.3版本开始,lightdb支持优化器提示只作用于当前查询块。
规则如下:
-
定义在SQL开头的优化器提示仍作用于整条SQL
chuhx@postgres=# explain(costs false) select * from t2 ,(select * from t2) x where t2.id=x.id; QUERY PLAN --------------------------------- Hash Join Hash Cond: (t2.id = t2_1.id) -> Seq Scan on t2 -> Hash -> Seq Scan on t2 t2_1 (5 rows) chuhx@postgres=# /*+index(t2)*/explain(costs false) select * from t2 ,(select * from t2) x where t2.id=x.id; QUERY PLAN ------------------------------------------- Merge Join Merge Cond: (t2.id = t2_1.id) -> Index Scan using t2_pkey on t2 -> Index Scan using t2_pkey on t2 t2_1 (4 rows) chuhx@postgres=#
-
定义在select,delete,update,insert 后的优化器提示只作用于当前sql
chuhx@postgres=# explain(costs false) select/*+index(t2)*/ * from t2 ,(select * from t2) x where t2.id=x.id; QUERY PLAN ---------------------------------------------- Hash Join Hash Cond: (t2.id = t2_1.id) -> Index Scan using t2_pkey on t2 @"lt#0" -> Hash -> Seq Scan on t2 t2_1 (5 rows) chuhx@postgres=# explain(costs false) select * from t2 ,(select /*+index(t2)*/* from t2) x where t2.id=x.id; QUERY PLAN --------------------------------------------------- Hash Join Hash Cond: (t2_1.id = t2.id) -> Index Scan using t2_pkey on t2 t2_1 @"lt#0" -> Hash -> Seq Scan on t2 @"lt#1" (5 rows) chuhx@postgres=#
跨查询块使用需要结合qb_name
qb_name
新增支持qb_name 来对其他查询块的对象使用优化器提示。在查询块中使用qb_name(xxx)
表示当前查询块的块名为xxx, 然后可以在其他查询块中引用以对此查询块中的对象生效。
引用方式有两种:
hashjoin(t1 t2@qb)
跟在表名后面。hashjoin(@qb t1 t2)
相当于hashjoin(t1@qb t2@qb)
下面是具体的用例:
chuhx@postgres=# explain(costs false) select /*+nestloop(t2 t2@qb)*/* from t2 ,(select/*+qb_name(qb)*/ * from t2) x where t2.id=x.id;
QUERY PLAN
-----------------------------------------------
Nested Loop
-> Seq Scan on t2 @"lt#0"
-> Index Scan using t2_pkey on t2 t2_1 @qb
Index Cond: (id = t2.id)
(4 rows)
chuhx@postgres=#
chuhx@postgres=# explain(costs false) select /*+nestloop(@qb t2 t3)*/* from t3 ,(select/*+no_merge qb_name(qb)*/ t2.id from t2,t3 where t2.id=t3.id) x where t3.id=x.id;
LOG: pg_hint_plan:
used hint:
NestLoop(@qb t2@qb t3@qb)
no_merge
not used hint:
duplication hint:
error hint:
QUERY PLAN
----------------------------------------------------------
Hash Join
Hash Cond: (t2.id = t3.id)
-> Nested Loop
-> Seq Scan on t2 @qb
-> Index Only Scan using t3_pkey on t3 t3_1 @qb
Index Cond: (id = t2.id)
-> Hash
-> Seq Scan on t3 @"lt#0"
(8 rows)
参考文档
CSDN 社区图书馆,开张营业! 深读计划,写书评领图书福利~以上是关于lightdb21.3-支持语句级hint的主要内容,如果未能解决你的问题,请参考以下文章