PostgreSQL 11 preview - 优化器 增强 汇总

PostgreSQL 11 对优化器进行了多项改进,包括优化了高频词选择性的计算方式,改善了某些条件下的选择性估计,重写了部分表达式以提高评估准确性,并增强了 EXIST 和 NOT EXISTS 的行数评估。

标签

PostgreSQL , 优化器 , 增强 , 11


背景

PostgreSQL 11 优化器增强。

E.1.3.1.4. Optimizer

  • Improve the selection of the optimizer statistics' most-common-values (Jeff Janes, Dean Rasheed)

    高频词的选择性计算更好。

    postgres=# \d pg_stats  
                         View "pg_catalog.pg_stats"  
             Column         |   Type   | Collation | Nullable | Default   
    ------------------------+----------+-----------+----------+---------  
     schemaname             | name     |           |          |   
     tablename              | name     |           |          |   
     attname                | name     |           |          |   
     inherited              | boolean  |           |          |   
     null_frac              | real     |           |          |   
     avg_width              | integer  |           |          |   
     n_distinct             | real     |           |          |   
     most_common_vals       | anyarray |           |          |   
     most_common_freqs      | real[]   |           |          |   
     histogram_bounds       | anyarray |           |          |   
     correlation            | real     |           |          |   
     most_common_elems      | anyarray |           |          |   
     most_common_elem_freqs | real[]   |           |          |   
     elem_count_histogram   | real[]   |           |          |   
    

    Previously most-common-values (MCV) were chosen based on their significance compared to all column values. Now, MCV are chosen based on their significance compared to the non-MCV values. This improves the statistics for uniform (fewer) and non-uniform (more) distributions.

  • Improve selectivity estimates for >= and <= when the constants are not common values (Tom Lane)

    Previously such cases used the same selectivity as > and <, respectively. This change is particularly useful for BETWEEN with small ranges.

    大于等于、小于等于某常量时,如果这个常量是一个非高频词(不在most_common_vals中),使用更优的选择算法。

  • Optimize var = var to var IS NOT NULL where equivalent (Tom Lane)

    重写var=var这样的表达式,改成var is not null,从而提高选择性评估的准确性。

    This leads to better selectivity estimates.

    PostgreSQL 11:

    postgres=# explain select * from aaa where id=id and info='abc';  
                            QUERY PLAN                           
    -----------------------------------------------------------  
     Seq Scan on aaa  (cost=0.00..379776.80 rows=16 width=368)  
       Filter: ((id IS NOT NULL) AND (info = 'abc'::text))  
    (2 rows)  
    

    PostgreSQL 10:

    postgres=# explain select * from aaa where id=id and info='abc';  
                                   QUERY PLAN                                  
    -------------------------------------------------------------------------  
     Seq Scan on aaa  (cost=10000000000.00..10000990476.50 rows=1 width=368)  
       Filter: ((id = id) AND (info = 'abc'::text))  
    (2 rows)  
    
  • Improve row count optimizer estimates for EXISTS and NOT EXISTS queries (Tom Lane)

    增强exists, not exists的行数评估。

  • Add optimizer selectivity costs for HAVING clauses (Tom Lane)

    增加having子句的选择性(返回多少行)成本估算(以前不对这部分进行估算)。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值