【我和openGauss的故事】openGauss价值特性(一)
  lYE0sTgD5uUi 2023年11月02日 38 0

【我和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

结论

通过上述实践,在连接时,如果关联列没有索引,那么选择行数比较少的表做内表,可以提升查询效率;如果关联列有索引,选择建了索引的表做内表,可以提升查询效率。

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
lYE0sTgD5uUi