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 2023-06-06 21:07  winter-loo  阅读(14)  评论(0编辑  收藏  举报

导航