我的编程空间,编程开发者的网络收藏夹
学习永远不晚

PostgreSQL中Review PG的Optimizer机制如何优化函数

短信预约 -IT技能 免费直播动态提醒
省份

北京

  • 北京
  • 上海
  • 天津
  • 重庆
  • 河北
  • 山东
  • 辽宁
  • 黑龙江
  • 吉林
  • 甘肃
  • 青海
  • 河南
  • 江苏
  • 湖北
  • 湖南
  • 江西
  • 浙江
  • 广东
  • 云南
  • 福建
  • 海南
  • 山西
  • 四川
  • 陕西
  • 贵州
  • 安徽
  • 广西
  • 内蒙
  • 西藏
  • 新疆
  • 宁夏
  • 兵团
手机号立即预约

请填写图片验证码后获取短信验证码

看不清楚,换张图片

免费获取短信验证码

PostgreSQL中Review PG的Optimizer机制如何优化函数

小编给大家分享一下PostgreSQL中Review PG的Optimizer机制如何优化函数,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

一、Optimizer Functions

Optimizer Functions-查询优化函数

The primary entry point is planner().
planner() //主入口
set up for recursive handling of subqueries
-subquery_planner()//planner->subquery_planner
pull up sublinks and subqueries from rangetable, if possible
canonicalize qual
Attempt to simplify WHERE clause to the most useful form; this includes
flattening nested AND/ORs and detecting clauses that are duplicated in
different branches of an OR.
simplify constant expressions
process sublinks
convert Vars of outer query levels into Params
--grouping_planner()//planner->subquery_planner->grouping_planner
preprocess target list for non-SELECT queries
handle UNION/INTERSECT/EXCEPT, GROUP BY, HAVING, aggregates,
ORDER BY, DISTINCT, LIMIT
---query_planner()//subquery_planner->grouping_planner->query_planner
make list of base relations used in query
split up the qual into restrictions (a=1) and joins (b=c)
find qual clauses that enable merge and hash joins
----make_one_rel()//...grouping_planner->query_planner->make_one_rel
set_base_rel_pathlists() //为每一个RelOptInfo生成访问路径
find seqscan and all index paths for each base relation
find selectivity of columns used in joins
make_rel_from_joinlist() //使用遗传算法或动态规划算法构造连接路径
hand off join subproblems to a plugin, GEQO, or standard_join_search()
-----standard_join_search()//这是动态规划算法
call join_search_one_level() for each level of join tree needed
join_search_one_level():
For each joinrel of the prior level, do make_rels_by_clause_joins()
if it has join clauses, or make_rels_by_clauseless_joins() if not.
Also generate "bushy plan" joins between joinrels of lower levels.
Back at standard_join_search(), generate gather paths if needed for
each newly constructed joinrel, then apply set_cheapest() to extract
the cheapest path for it.
Loop back if this wasn't the top join level.
Back at grouping_planner:
do grouping (GROUP BY) and aggregation//在最高层处理分组/聚集/唯一过滤/排序/控制输出元组数目等
do window functions
make unique (DISTINCT)
do sorting (ORDER BY)
do limit (LIMIT/OFFSET)
Back at planner():
convert finished Path tree into a Plan tree
do final cleanup after planning

二、Optimizer Data Structures

Optimizer Data Structures
数据结构

PlannerGlobal   - global information for a single planner invocation
PlannerInfo     - information for planning a particular Query (we make
a separate PlannerInfo node for each sub-Query)
RelOptInfo      - a relation or joined relations
RestrictInfo   - WHERE clauses, like "x = 3" or "y = z"
(note the same structure is used for restriction and
join clauses)
Path           - every way to generate a RelOptInfo(sequential,index,joins)
SeqScan       - represents a sequential scan plan //顺序扫描
IndexPath     - index scan //索引扫描
BitmapHeapPath - top of a bitmapped index scan //位图索引扫描
TidPath       - scan by CTID //CTID扫描
SubqueryScanPath - scan a subquery-in-FROM //FROM子句中的子查询扫描
ForeignPath   - scan a foreign table, foreign join or foreign upper-relation //FDW
CustomPath    - for custom scan providers //定制化扫描
AppendPath    - append multiple subpaths together //多个子路径APPEND,常见于集合操作
MergeAppendPath - merge multiple subpaths, preserving their common sort order //保持顺序的APPEND
ResultPath    - a childless Result plan node (used for FROM-less SELECT)//结果路径(如SELECT 2+2)
MaterialPath  - a Material plan node //物化路径
UniquePath    - remove duplicate rows (either by hashing or sorting) //去除重复行路径
GatherPath    - collect the results of parallel workers //并行
GatherMergePath - collect parallel results, preserving their common sort order //并行,保持顺序
ProjectionPath - a Result plan node with child (used for projection) //投影
ProjectSetPath - a ProjectSet plan node applied to some sub-path //投影(应用于子路径上)
SortPath      - a Sort plan node applied to some sub-path //排序
GroupPath     - a Group plan node applied to some sub-path //分组
UpperUniquePath - a Unique plan node applied to some sub-path //应用于子路径的Unique Plan
AggPath       - an Agg plan node applied to some sub-path //应用于子路径的聚集
GroupingSetsPath - an Agg plan node used to implement GROUPING SETS //分组集合
MinMaxAggPath - a Result plan node with subplans performing MIN/MAX //最大最小
WindowAggPath - a WindowAgg plan node applied to some sub-path //应用于子路径的窗口函数
SetOpPath     - a SetOp plan node applied to some sub-path //应用于子路径的集合操作
RecursiveUnionPath - a RecursiveUnion plan node applied to two sub-paths //递归UNION
LockRowsPath  - a LockRows plan node applied to some sub-path //应用于子路径的的LockRows
ModifyTablePath - a ModifyTable plan node applied to some sub-path(s) //应用于子路径的数据表更新(如INSERT/UPDATE操作等)
LimitPath     - a Limit plan node applied to some sub-path//应用于子路径的LIMIT
NestPath      - nested-loop joins//嵌套循环连接
MergePath     - merge joins//Merge Join
HashPath      - hash joins//Hash Join
EquivalenceClass - a data structure representing a set of values known equal
PathKey        - a data structure representing the sort ordering of a path

The optimizer spends a good deal of its time worrying about the ordering
of the tuples returned by a path.  The reason this is useful is that by
knowing the sort ordering of a path, we may be able to use that path as
the left or right input of a mergejoin and avoid an explicit sort step.
Nestloops and hash joins don't really care what the order of their inputs
is, but mergejoin needs suitably ordered inputs.  Therefore, all paths
generated during the optimization process are marked with their sort order
(to the extent that it is known) for possible use by a higher-level merge.

优化器在元组的排序上面花费了不少时间,原因是为了在Merge Join时避免专门的排序步骤.

It is also possible to avoid an explicit sort step to implement a user's
ORDER BY clause if the final path has the right ordering already, so the
sort ordering is of interest even at the top level.  grouping_planner() will
look for the cheapest path with a sort order matching the desired order,
then compare its cost to the cost of using the cheapest-overall path and
doing an explicit sort on that.
When we are generating paths for a particular RelOptInfo, we discard a path
if it is more expensive than another known path that has the same or better
sort order.  We will never discard a path that is the only known way to
achieve a given sort order (without an explicit sort, that is).  In this
way, the next level up will have the maximum freedom to build mergejoins
without sorting, since it can pick from any of the paths retained for its
inputs.

以上是“PostgreSQL中Review PG的Optimizer机制如何优化函数”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

PostgreSQL中Review PG的Optimizer机制如何优化函数

下载Word文档到电脑,方便收藏和打印~

下载Word文档

猜你喜欢

如何使用php函数来优化缓存机制?

引言:在开发网站时,为了提高性能和访问速度,缓存机制是非常重要的。PHP内置了一些函数和扩展来帮助我们实现缓存功能。本文将介绍如何使用PHP函数来优化缓存机制,并提供具体的代码示例。一、了解缓存机制在开始优化缓存机制之前,首先需要了解缓存的
2023-10-21

如何通过php函数来优化缓存更新机制?

缓存是提高网站性能的重要一环。在PHP开发中,我们常常会使用缓存来减轻数据库和服务器的负载,提升网站的访问速度。但是,在缓存的过程中,我们也面临着缓存和数据的一致性问题,特别是当数据发生更新时。为了保持缓存和数据的一致性,我们可以通过优化缓
2023-10-21

如何浅谈Java性能优化中的函数

如何浅谈Java性能优化中的函数,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。★finalize 函数的调用机制  俺经常啰嗦:“了解本质机制的重要性”。所以今
2023-06-02

如何优化 PHP 函数中数据库查询的性能?

回答:优化 php 函数中的数据库查询性能至关重要。原因:不必要的重叠查询无效的索引无效的查询语法优化技巧:使用缓存优化索引使用适当的查询类型限制结果集利用 explain使用 prepared statements优化 PHP 函数中数据
如何优化 PHP 函数中数据库查询的性能?
2024-04-24

如何优化 PHP 函数中异常处理的性能?

优化 php 函数中异常处理的性能至关重要,具体优化技术包括:减少异常生成:通过输入验证和类型检查来避免无效数据引发异常。使用自定义异常类:创建特定领域异常类,降低检测异常类型的开销。使用异常缓存:利用 php 8.0 及更高版本的异常缓存
如何优化 PHP 函数中异常处理的性能?
2024-04-25

如何分析Java性能优化中的垃圾回收机制

这篇文章将为大家详细讲解有关如何分析Java性能优化中的垃圾回收机制,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。★JVM 的内存空间  在 Java 虚拟机规范中,提及了如下几种类型的内存
2023-06-02

STL 函数对象在性能优化中的作用如何?

stl函数对象通过存储状态提升了性能优化,具体通过以下方式实现:避免昂贵的复制操作、减少函数调用开销、利用并行性。实战案例中,使用std::bind优化了图像处理算法,避免了复制图像,从而提高了性能。STL 函数对象在性能优化中的作用在
STL 函数对象在性能优化中的作用如何?
2024-04-26

编程热搜

目录