lightdb 忽略未知执行计划提示

lightdb 忽略未知执行计划提示

执行计划提示介绍见其他文章

背景

Oracle 中的执行计划提示(后文简称为 hint )种类繁多,lightdb 目前还没有做到全部兼容,因此需要忽视未实现的 hint, 继续执行其他支持的 hint. 比如:all_rows hint 不支持。这个新功能包含在 lightdb 版本 LightDB1.0.V202302.00.000.

lightdb 中 hint 之间以空格分隔或 '()' 分割,如下面的 hint 都是有效的:

  • /*+ semijoin SeqScan(sample) */
  • /*+ SeqScan(sample)Rows(sample 10) */

测试用例

  1. 首先,根据 pg_class 创建一张临时表,用于后续测试。
create temporary table sample (letter, junk) as
	select substr(relname, 1, 1), repeat('x', 250)
	from pg_class
	order by random();

create index i_sample on sample(letter);

analyze sample;

pg_class 中大多数表都是以 'p' 开头的,因此查询条件 where letter = 'p' 会直接走全表扫描,而查询条件 where letter = 'k' 会走索引。

  1. 正常用例
/*+SeqScan(sample)*/ explain select count(*) from sample where letter = 'k';

上面结果会输出:

                         QUERY PLAN
-------------------------------------------------------------
 Aggregate  (cost=32.00..32.01 rows=1 width=8)
   ->  Seq Scan on sample  (cost=0.00..32.00 rows=1 width=0)
         Filter: (letter = 'k'::text)    
  1. 异常用例
-- all_rows 在前面
/*+ all_rows SeqScan(sample)*/
explain select count(*) from sample where letter = 'k';

-- all_rows 在后面
/*+ SeqScan(sample) all_rows */
explain select count(*) from sample where letter = 'k';

-- all_rows 带括号
/*+ all_rows() SeqScan(sample)*/
explain select count(*) from sample where letter = 'k';

-- all_rows 只有一个左括号
/*+ all_rows( SeqScan(sample)*/
explain select count(*) from sample where letter = 'k';

-- all_rows 只有一个右括号
/*+ all_rows) SeqScan(sample)*/
explain select count(*) from sample where letter = 'k';

-- all_rows 有嵌套括号
/*+ all_rows((hello)) SeqScan(sample)*/
explain select count(*) from sample where letter = 'k';

-- all_rows 关键字和括号之间有空格
/*+ all_rows () SeqScan(sample)*/
explain select count(*) from sample where letter = 'k';

异常用例输出示例:

INFO:  lt_hint_plan: hint syntax error at or near "all_rows"
DETAIL:  Unrecognized hint keyword "all_rows", ignored
                         QUERY PLAN
-------------------------------------------------------------
 Aggregate  (cost=21.19..21.20 rows=1 width=8)
   ->  Seq Scan on sample  (cost=0.00..21.19 rows=1 width=0)
         Filter: (letter = 'k'::text)

posted on   winter-loo  阅读(15)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 写一个简单的SQL生成工具
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

点击右上角即可分享
微信分享提示