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) */
测试用例
- 首先,根据 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'
会走索引。
- 正常用例
/*+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)
- 异常用例
-- 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 阅读(15) 评论(0) 编辑 收藏 举报
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 写一个简单的SQL生成工具
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)