广告
返回顶部
首页 > 资讯 > 数据库 >PostgreSQL中Review PG的Optimizer机制如何优化函数
  • 539
分享到

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

2024-04-02 19:04:59 539人浏览 泡泡鱼
摘要

小编给大家分享一下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机制如何优化函数”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注编程网数据库频道!

您可能感兴趣的文档:

--结束END--

本文标题: PostgreSQL中Review PG的Optimizer机制如何优化函数

本文链接: https://www.lsjlt.com/news/64883.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

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

下载Word文档
猜你喜欢
  • PostgreSQL中Review PG的Optimizer机制如何优化函数
    小编给大家分享一下PostgreSQL中Review PG的Optimizer机制如何优化函数,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去...
    99+
    2022-10-19
  • 如何使用php函数来优化缓存机制?
    引言:在开发网站时,为了提高性能和访问速度,缓存机制是非常重要的。PHP内置了一些函数和扩展来帮助我们实现缓存功能。本文将介绍如何使用PHP函数来优化缓存机制,并提供具体的代码示例。一、了解缓存机制在开始优化缓存机制之前,首先需要了解缓存的...
    99+
    2023-10-21
    缓存 优化 PHP函数
  • 如何通过php函数来优化缓存更新机制?
    缓存是提高网站性能的重要一环。在PHP开发中,我们常常会使用缓存来减轻数据库和服务器的负载,提升网站的访问速度。但是,在缓存的过程中,我们也面临着缓存和数据的一致性问题,特别是当数据发生更新时。为了保持缓存和数据的一致性,我们可以通过优化缓...
    99+
    2023-10-21
    PHP函数 缓存更新 优化机制
  • Proxy如何优化vue的数据监听机制问题
    这篇文章主要介绍Proxy如何优化vue的数据监听机制问题,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!vue2.x中的实现其本质是new Watcher(data, key, ca...
    99+
    2022-10-19
  • 如何优化 Java 中的索引函数使用?
    Java中的索引函数是一种非常有用的工具,可以帮助开发人员更快速地访问和操作数据。但是,如果不正确使用索引函数,它可能会导致性能问题。在本文中,我们将探讨如何优化Java中的索引函数使用。 索引函数是什么? 在Java中,索引函数是一种...
    99+
    2023-09-02
    索引 函数 api
  • 如何浅谈Java性能优化中的函数
    如何浅谈Java性能优化中的函数,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。★finalize 函数的调用机制  俺经常啰嗦:“了解本质机制的重要性”。所以今...
    99+
    2023-06-02
  • 如何在 PHP Laravel 中优化 Spring 函数的性能?
    在 PHP Laravel 中使用 Spring 函数是一种非常常见的方式来提高应用程序的性能。然而,如果不使用正确的方法来优化 Spring 函数的性能,可能会导致应用程序变得缓慢,甚至崩溃。在本文中,我们将探讨如何在 PHP Larav...
    99+
    2023-07-20
    laravel 函数 spring
  • Python中的shell函数如何优化编程算法?
    Python作为一种高级编程语言,被广泛应用于各种领域。在Python中,shell函数是一种非常重要的编程工具,可以用来优化算法的效率。本文将介绍Python中shell函数的优化编程算法。 一、什么是shell函数? shell函数是一...
    99+
    2023-07-08
    shell 函数 编程算法
  • ASP 和 Laravel 中的数组函数 - 如何优化您的代码?
    在 ASP 和 Laravel 中,数组函数是非常重要的一部分。它们能够极大地简化代码,提高效率。在本文中,我们将探讨一些常用的数组函数,并介绍如何使用它们来优化您的代码。 ASP 中的数组函数 在 ASP 中,数组函数非常常见。下面是一些...
    99+
    2023-08-31
    laravel 数组 函数
  • 如何在 Django 项目中优化 Go 函数的性能?
    Django 是一个使用 Python 编写的 Web 框架,而 Go 是一种高性能的编程语言,两者可以很好地结合起来提高项目的性能。在 Django 项目中使用 Go 函数进行性能优化是一个不错的选择,本文将介绍如何在 Django 项目...
    99+
    2023-07-09
    函数 linux django
  • Go语言中的NumPy函数:如何优化您的代码?
    在进行科学计算时,NumPy是一个非常强大和常用的Python库。然而,对于需要高性能的计算任务,Python可能不是最佳选择。在这种情况下,Go语言就成为了一个非常好的替代品。Go语言是一种编译型语言,具有与Python相同的语法和功能...
    99+
    2023-09-26
    numy 函数 bash
  • 如何优化 Python 中的数组操作函数?面试攻略!
    Python 中的数组操作函数是非常常用的函数之一,无论是在数据处理、机器学习、深度学习、计算机视觉等领域,都要用到数组操作函数。然而,随着数据量的增加和算法的复杂性的提高,Python 中的数组操作函数也面临着性能瓶颈。本文将介绍如何优...
    99+
    2023-11-06
    函数 数组 面试
  • 如何分析Java性能优化中的垃圾回收机制
    这篇文章将为大家详细讲解有关如何分析Java性能优化中的垃圾回收机制,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。★JVM 的内存空间  在 Java 虚拟机规范中,提及了如下几种类型的内存...
    99+
    2023-06-02
  • 如何使用 Linux 中的 PHP 函数来优化 LeetCode 中的编程?
    随着计算机技术的不断发展,人们对编程的需求也越来越高。LeetCode 是一个很好的编程学习平台,它提供了大量的算法题目供我们练习。而在编程中,我们经常需要使用各种函数来实现各种操作。本文将介绍如何使用 Linux 中的 PHP 函数来优...
    99+
    2023-06-13
    函数 linux leetcode
  • 如何在IDE中优化PHP数据类型和函数的使用?
    在PHP开发中,数据类型和函数的使用对代码的性能和可读性有着重要的影响。在IDE中优化数据类型和函数的使用可以帮助我们提高代码的效率和可维护性。本文将介绍一些优化数据类型和函数使用的技巧。 一、使用正确的数据类型 PHP中有多种数据类型,...
    99+
    2023-10-22
    数据类型 函数 ide
  • Java开发者必看:如何优化数组加载过程中的缓存机制?
    在Java开发中,数组是一个非常常用的数据结构。当我们需要加载大量数据时,数组的缓存机制显得尤为重要。在本文中,我们将探讨如何优化数组加载过程中的缓存机制,以提高程序的性能和稳定性。 一、避免使用默认缓存大小 在Java中,当我们初始化一...
    99+
    2023-06-16
    数组 load 缓存
  • 如何使用Java函数中的关键字来优化NPM包?
    在开发NPM包时,优化代码是非常重要的,因为它可以提高代码的可读性、可维护性和性能。而Java函数中的关键字可以帮助我们更好地优化NPM包。下面,我们将介绍如何使用Java函数中的关键字来优化NPM包。 Final关键字 Final关键...
    99+
    2023-09-02
    函数 关键字 npm
  • 如何在ASP中使用缓存来优化您的Django函数?
    在Django中,缓存是一种非常重要的优化技术,可以有效地提高应用程序的性能和响应速度。在本文中,我们将介绍如何在ASP中使用缓存来优化您的Django函数。同时,我们将提供一些示例代码,以帮助您更好地理解这些概念。 缓存是一种将计算结果存...
    99+
    2023-06-15
    缓存 django 函数
  • ASP 文件中 numy 函数的秘密:如何优化您的代码?
    ASP 文件中 Numy 函数的秘密:如何优化您的代码? ASP 文件中的 Numy 函数是一种非常有用的函数,可以帮助您在代码中更有效地处理数值计算。在本文中,我们将深入探讨 Numy 函数的工作原理,并介绍如何使用它来优化您的 ASP ...
    99+
    2023-10-21
    文件 numy 函数
  • Django 中的编程算法:如何优化函数的执行效率?
    Django 是一款功能强大的 Web 框架,它使用 Python 语言编写。在 Django 中,编写高效的函数并不是一件容易的事情,特别是在处理大量数据时,函数的执行效率往往会成为一个瓶颈。本文将介绍一些优化 Django 函数执行效率...
    99+
    2023-10-09
    函数 django 编程算法
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作