【我和openGauss的故事】openGauss价值特性(一)
openGauss是一款高性能、易运维的开源关系型数据库。openGauss提供了众多的价值特性,可以极大地帮助数据库开发和运维工程师方便地进行数据库管理和维护。本文将对openGauss所提供的plan hint、索引推荐、闪回恢复做一个简单的介绍**。**
Plan Hint调优
Plan Hint为用户提供了直接影响执行计划生成的手段,用户可以通过指定join顺序、join、scan方法、指定结果行数等多个手段来进行执行计划的调优,以提升查询的性能。
支持范围
当前版本Plan Hint支持的范围如下,后续版本会进行增强。
- 指定Join顺序的Hint - leading hint
- 指定Join方式的Hint,仅支持除semi/anti join、unique plan之外的常用hint。
- 指定结果集行数的Hint
- 指定Scan方式的Hint,仅支持常用的tablescan、indexscan和indexonlyscan的hint。
- 指定子链接块名的Hint
注意事项
- 不支持Agg、Sort、Setop和Subplan的hint。
- 仅指定join顺序,不指定内外表顺序。
- 语法: leading(t1 t2 t3)
- 仅指定join顺序,指定内外表顺序。
- 语法: leading((t1 t2 t3))
实践操作
1、预置数据如下:
table: employee 职员表 --============================================================== CREATE TABLE employee( empid int not null, --职员工号 empname text not null, --职员姓名 deptid int not null, --部门ID salary int not null, --工资 constraint pk_employee primary key (empid) ); --============================================================== -- table: department 部门表 --============================================================== CREATE TABLE department( deptid int not null, ---部门ID deptname text not null, ---部门名称 parentid int not null, --上级部门ID constraint pk_department primary key (deptid) );
复制
2、测试:语法: leading((t1 t2 ))
openGauss=# explain select /*+ leading((department employee)) */ * from department join employee on employee.deptid = department.deptid; QUERY PLAN ------------------------------------------------------------------------------- Hash Join (cost=69853.65..113081.05 rows=1462340 width=33) Hash Cond: (department.deptid = employee.deptid) -> Seq Scan on department (cost=0.00..164.00 rows=10000 width=17) -> Hash (cost=30153.40..30153.40 rows=1462340 width=16) -> Seq Scan on employee (cost=0.00..30153.40 rows=1462340 width=16) (5 rows) Time: 1.059 ms openGauss=# explain select /*+ leading((employee department)) */ * from department join employee on employee.deptid = department.deptid; QUERY PLAN ----------------------------------------------------------------------------- Hash Join (cost=289.00..50549.58 rows=1462340 width=33) Hash Cond: (employee.deptid = department.deptid) -> Seq Scan on employee (cost=0.00..30153.40 rows=1462340 width=16) -> Hash (cost=164.00..164.00 rows=10000 width=17) -> Seq Scan on department (cost=0.00..164.00 rows=10000 width=17) (5 rows) Time: 0.856 ms
复制
3、结果:改变内外表顺序,对SQL的执行还是由影响的
openGauss=# CREATE INDEX idx_empdepid on employee (deptid); openGauss=# explain select /*+ leading((department employee)) */ * from department join employee on employee.deptid = department.deptid; QUERY PLAN ------------------------------------------------------------------------------- Hash Join (cost=38030.00..52806.50 rows=1000000 width=33) Hash Cond: (department.deptid = employee.deptid) -> Seq Scan on department (cost=0.00..164.00 rows=10000 width=17) -> Hash (cost=25530.00..25530.00 rows=1000000 width=16) -> Seq Scan on employee (cost=0.00..25530.00 rows=1000000 width=16) (5 rows) Time: 0.833 ms
复制
结论
通过上述实践,在连接时,如果关联列没有索引,那么选择行数比较少的表做内表,可以提升查询效率;如果关联列有索引,选择建了索引的表做内表,可以提升查询效率。
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
评论
相关阅读
2025年3月国产数据库大事记
墨天轮编辑部
911次阅读
2025-04-03 15:21:16
MogDB 发布更新,解决 openGauss 数据库在长事务情况下Ustore表膨胀问题
MogDB
289次阅读
2025-04-17 10:41:41
openGauss 7.0.0-RC1 版本正式发布!
Gauss松鼠会
210次阅读
2025-04-01 12:27:03
MogDB 发布更新,解决 openGauss 数据库在长事务情况下Ustore表膨胀问题
云和恩墨
191次阅读
2025-04-16 09:52:02
openGauss 7.0.0-RC1 版本体验:一主一备快速安装指南
孙莹
187次阅读
2025-04-01 10:30:07
鲲鹏RAG一体机解决方案正式发布 openGauss DataVec向量数据库助力DeepSeek行业应用
Gauss松鼠会
126次阅读
2025-03-31 10:00:29
荣誉时刻!openGauss认证证书快递已发,快来看看谁榜上有名!
墨天轮小教习
116次阅读
2025-04-23 17:39:13
GitCode 成 openGauss 新归宿,国产开源数据库里程碑事件
严少安
99次阅读
2025-04-27 11:37:53
openGauss6.0.0适配操作系统自带的软件,不依赖三方库
来杯拿铁
79次阅读
2025-04-18 10:49:53
opengauss使用gs_probackup进行增量备份恢复
进击的CJR
70次阅读
2025-04-09 16:11:58