LightDB-opt_param hint支持

文章介绍了LightDB从23.4版本开始支持的opt_paramhint,用于设置针对SQL的优化器参数,与Oracle的opt_param类似,但参数需符合LightDB规范。文中通过示例展示了正确和错误的使用方法以及不同参数设置对查询计划的影响。
摘要由CSDN通过智能技术生成

LightDB 从23.4 版本开始支持opt_param hint, 用来设置优化器相关的guc参数,用法和oracle的opt_param 相同。

  • 设置的参数需要是 LightDB的参数(不是oracle的参数)。
  • 参数名用单引号括起来
  • 字符串型的参数值也需要用单引号括起来
  • 作用于整条SQL

具体用法参考如下示例:

示例

表结构

create table test_opt_param1(key1 int, key2 int, primary key(key1));
create table test_opt_param2(key1 int, key2 int, primary key(key1));
create table test_opt_param3(key1 int, key2 int, primary key(key1));

基本用法

EXPLAIN (COSTS false) select * from test_opt_param1 a join test_opt_param2 b on a.key1=b.key1;
                QUERY PLAN                 
-------------------------------------------
 Hash Join
   Hash Cond: (a.key1 = b.key1)
   ->  Seq Scan on test_opt_param1 a
   ->  Hash
         ->  Seq Scan on test_opt_param2 b
(5 rows)

EXPLAIN (COSTS false) select/*+opt_param('enable_hashjoin', 'off')*/ * from test_opt_param1 a join test_opt_param2 b on a.key1=b.key1;
LOG:  lt_hint_plan:
used hint:
opt_param('enable_hashjoin' 'off')
not used hint:
duplication hint:
error hint:

                                QUERY PLAN                                
--------------------------------------------------------------------------
 Merge Join
   Merge Cond: (a.key1 = b.key1)
   ->  Index Scan using test_opt_param1_pkey on test_opt_param1 a @"lt#0"
   ->  Index Scan using test_opt_param2_pkey on test_opt_param2 b @"lt#0"
(4 rows)

EXPLAIN (COSTS false) select/*+opt_param('enable_hashjoin', 'false')*/ * from test_opt_param1 a join test_opt_param2 b on a.key1=b.key1;
LOG:  lt_hint_plan:
used hint:
opt_param('enable_hashjoin' 'false')
not used hint:
duplication hint:
error hint:

                                QUERY PLAN                                
--------------------------------------------------------------------------
 Merge Join
   Merge Cond: (a.key1 = b.key1)
   ->  Index Scan using test_opt_param1_pkey on test_opt_param1 a @"lt#0"
   ->  Index Scan using test_opt_param2_pkey on test_opt_param2 b @"lt#0"
(4 rows)

EXPLAIN (COSTS false) select/*+opt_param('enable_hashjoin', 0)*/ * from test_opt_param1 a join test_opt_param2 b on a.key1=b.key1;
LOG:  lt_hint_plan:
used hint:
opt_param('enable_hashjoin' 0)
not used hint:
duplication hint:
error hint:

                                QUERY PLAN                                
--------------------------------------------------------------------------
 Merge Join
   Merge Cond: (a.key1 = b.key1)
   ->  Index Scan using test_opt_param1_pkey on test_opt_param1 a @"lt#0"
   ->  Index Scan using test_opt_param2_pkey on test_opt_param2 b @"lt#0"
(4 rows)

EXPLAIN (COSTS false) select/*+opt_param('enable_hashjoin', 1)*/ * from test_opt_param1 a join test_opt_param2 b on a.key1=b.key1;
LOG:  lt_hint_plan:
used hint:
opt_param('enable_hashjoin' 1)
not used hint:
duplication hint:
error hint:

                    QUERY PLAN                     
---------------------------------------------------
 Hash Join
   Hash Cond: (a.key1 = b.key1)
   ->  Seq Scan on test_opt_param1 a @"lt#0"
   ->  Hash
         ->  Seq Scan on test_opt_param2 b @"lt#0"
(5 rows)

错误用法

EXPLAIN (COSTS false) select/*+opt_param(enable_hashjoin, 'off')*/ * from test_opt_param1 a join test_opt_param2 b on a.key1=b.key1;
INFO:  lt_hint_plan: hint syntax error at or near "opt_param(enable_hashjoin, 'off')"
DETAIL:  opt_param hint requires parameter name to be enclosed in single quotation marks.
LOG:  lt_hint_plan:
used hint:
not used hint:
duplication hint:
error hint:
opt_param(enable_hashjoin 'off')

                    QUERY PLAN                     
---------------------------------------------------
 Hash Join
   Hash Cond: (a.key1 = b.key1)
   ->  Seq Scan on test_opt_param1 a @"lt#0"
   ->  Hash
         ->  Seq Scan on test_opt_param2 b @"lt#0"
(5 rows)

EXPLAIN (COSTS false) select/*+opt_param('enable_hashjoin', off)*/ * from test_opt_param1 a join test_opt_param2 b on a.key1=b.key1;
INFO:  lt_hint_plan: hint syntax error at or near "opt_param('enable_hashjoin', off)"
DETAIL:  opt_param hint requires parameter values that are strings to be enclosed in single quotation mark.
LOG:  lt_hint_plan:
used hint:
not used hint:
duplication hint:
error hint:
opt_param('enable_hashjoin' off)

                    QUERY PLAN                     
---------------------------------------------------
 Hash Join
   Hash Cond: (a.key1 = b.key1)
   ->  Seq Scan on test_opt_param1 a @"lt#0"
   ->  Hash
         ->  Seq Scan on test_opt_param2 b @"lt#0"
(5 rows)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

紫无之紫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值