1.1.1 选择率的计算
PostgreSQL通过(等频)直方图、最频值(MCV)和空值率等统计信息来进行选择率的计算。根据操作符的不同,在pg_operator系统表中登记了每个操作符对应的选择率估算函数。
PostgreSQL对于选择率(Selectivity)的计算,是靠内部函数实现的。PostgreSQL提供最基本的两个函数,用以完成选择率的计算,分别是:
1. 连接选择率,join_selectivity:对连接条件进行选择率的计算;
2. 限制选择率,restriction_selectivity:对限制条件进行选择率的计算。
在这两类选择率基础上,提供了“子句选择率(clause_selectivity)”、“子句列表选择率(clauselist_selectivity)”,对子句表达式进行了包装。
每类选择率,都包括一些操作符,如连接选择率支持连接类型中的等值连接、不等连接、大于连接、小于连接等,这些连接,在PostgreSQL内部,都用函数实现。当需要为某个操作符计算某类操作的选择率的时候,PostgreSQL通过调用函数管理器,执行存储在过程函数系统表(pg_proc.h)中登记的选择率计算函数。
选择率实现函数与操作符对应表
|
功能 |
接口函数名称 |
内部函数名称 |
对应操作符 |
|
连接选择率:连接操作符子句的选择率 |
join_selectivity |
eqjoinsel |
= |
|
|
neqjoinsel |
<> | |
|
|
scalarltjoinsel |
< | |
|
|
scalargtjoinsel |
> | |
|
|
areajoinsel |
区域比较 | |
|
|
arraycontjoinsel |
数组包含 | |
|
|
positionjoinsel |
位置比较 | |
|
|
contjoinsel |
包含比较 | |
|
|
iclikejoinsel |
ILIKE | |
|
|
icnlikejoinsel |
NOT ILIKE | |
|
|
likejoinsel |
LIKE | |
|
|
Nlikejoinsel |
NOT LIKE | |
|
|
regexeqjoinsel |
正则表达式匹配 | |
|
|
icregexeqjoinsel |
大小写敏感的正则匹配 | |
|
|
regexnejoinsel |
正则不匹配 | |
|
|
icregexnejoinsel |
大小写敏感的正则不匹配 | |
|
|
tsmatchjoinsel |
全文检索 | |
|
限制选择率:限制操作符子句的选择率 |
restriction_selectivity |
eqsel |
= |
|
|
neqsel |
<> | |
|
|
scalarltsel |
< | |
|
|
scalargtsel |
> | |
|
|
areasel |
区域比较 | |
|
|
arraycontsel |
数组包含 | |
|
|
positionsel |
位置比较 | |
|
|
contsel |
包含比较 | |
|
|
iclikesel |
ILIKE | |
|
|
icnlikesel |
NOT ILIKE | |
|
|
likesel |
LIKE | |
|
|
nlikesel |
NOT LIKE | |
|
|
regexeqsel |
正则表达式匹配 | |
|
|
icregexeqsel |
大小写敏感的正则匹配 | |
|
|
regexnesel |
正则不匹配 | |
|
|
icregexnesel |
大小写敏感的正则不匹配 | |
|
|
tsmatchsel |
全文检索 |
PostgreSQL选择率计算
696

被折叠的 条评论
为什么被折叠?



