暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

PolarDB-PG原理解读——ANALYZE 源码解读(三)

PolarDB农夫山泉 2023-08-29
132

PolarDB PostgreSQL版(以下简称 PolarDB-PG)是一款阿里云自主研发的企业级数据库产品,采用计算存储分离架构,兼容 PostgreSQL 与 Oracle。PolarDB-PG 的存储与计算能力均可横向扩展,具有高可靠、高可用、弹性扩展等企业级数据库特性。同时,PolarDB-PG 具有大规模并行计算能力,可以应对 OLTP 与 OLAP 混合负载;还具有时空、向量、搜索、图谱等多模创新特性,可以满足企业对数据处理日新月异的新需求。

Most Common Elements

/* * A "most common elements" slot is similar to a "most common values" slot, * except that it stores the most common non-null *elements* of the column * values. This is useful when the column datatype is an array or some other * type with identifiable elements (for instance, tsvector). staop contains * the equality operator appropriate to the element type, and stacoll * contains the collation to use with it. stavalues contains * the most common element values, and stanumbers their frequencies. Unlike * MCV slots, frequencies are measured as the fraction of non-null rows the * element value appears in, not the frequency of all rows. Also unlike * MCV slots, the values are sorted into the element type's default order * (to support binary search for a particular value). Since this puts the * minimum and maximum frequencies at unpredictable spots in stanumbers, * there are two extra members of stanumbers, holding copies of the minimum * and maximum frequencies. Optionally, there can be a third extra member, * which holds the frequency of null elements (expressed in the same terms: * the fraction of non-null rows that contain at least one null element). If * this member is omitted, the column is presumed to contain no null elements. * * Note: in current usage for tsvector columns, the stavalues elements are of * type text, even though their representation within tsvector is not * exactly text. */ #define STATISTIC_KIND_MCELEM 4
复制

与 MCV 类似,但是保存的是列中的 最常见元素,主要用于数组等类型。同样,在 staop 中保存了等值运算符用于判断元素出现的频率高低。但与 MCV 不同的是这里的频率计算的分母是非空的行,而不是所有的行。另外,所有的常见元素使用元素对应数据类型的默认顺序进行排序,以便二分查找。

Distinct Elements Count Histogram

/* * A "distinct elements count histogram" slot describes the distribution of * the number of distinct element values present in each row of an array-type * column. Only non-null rows are considered, and only non-null elements. * staop contains the equality operator appropriate to the element type, * and stacoll contains the collation to use with it. * stavalues is not used and should be NULL. The last member of stanumbers is * the average count of distinct element values over all non-null rows. The * preceding M (>=2) members form a histogram that divides the population of * distinct-elements counts into M-1 bins of approximately equal population. * The first of these is the minimum observed count, and the last the maximum. */ #define STATISTIC_KIND_DECHIST 5
复制

表示列中出现所有数值的频率分布直方图。stanumbers 数组的前 M 个元素是将列中所有唯一值的出现次数大致均分到 M - 1 个桶中的边界值。后续跟上一个所有唯一值的平均出现次数。这个统计信息应该会被用于计算 选择率

Length Histogram

/* * A "length histogram" slot describes the distribution of range lengths in * rows of a range-type column. stanumbers contains a single entry, the * fraction of empty ranges. stavalues is a histogram of non-empty lengths, in * a format similar to STATISTIC_KIND_HISTOGRAM: it contains M (>=2) range * values that divide the column data values into M-1 bins of approximately * equal population. The lengths are stored as float8s, as measured by the * range type's subdiff function. Only non-null rows are considered. */ #define STATISTIC_KIND_RANGE_LENGTH_HISTOGRAM 6
复制

长度直方图描述了一个范围类型的列的范围长度分布。同样也是一个长度为 M 的直方图,保存在 stanumbers 中。

Bounds Histogram

/* * A "bounds histogram" slot is similar to STATISTIC_KIND_HISTOGRAM, but for * a range-type column. stavalues contains M (>=2) range values that divide * the column data values into M-1 bins of approximately equal population. * Unlike a regular scalar histogram, this is actually two histograms combined * into a single array, with the lower bounds of each value forming a * histogram of lower bounds, and the upper bounds a histogram of upper * bounds. Only non-NULL, non-empty ranges are included. */ #define STATISTIC_KIND_BOUNDS_HISTOGRAM 7
复制

边界直方图同样也被用于范围类型,与数据分布直方图类似。stavalues 中保存了使该列数值大致均分到 M - 1 个桶中的 M 个范围边界值。只考虑非空行。

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

文章被以下合辑收录

评论