IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    为什么说不要在pg 12前,用原生hash分区

    Jimmy He发表于 2020-11-20 06:46:32
    love 0

    pg在11之前,有原生的range分区和list分区,但是没有原生的hash分区。 hash分区是需要通过pg_pathman插件来实现。
    如果你从原来pg 10版本+pg_pathman实现hash分区,且分区数比较多,比如1024个分区,那么到你升级到pg 11之后,如果采用了原生分区,你会发现sql语句的planning time会变得比较长。

    我们进行了测试,来验证pg 11的原生分区的性能:

    分区数 pg 11.5 with native partition first time planning(ms) pg 11.5 with native partition second time planning(ms) pg 11.5 with pg_pathman partition first time planning(ms) pg 11.5 with pg_pathman partition second time planning(ms) pg 12.2 with native partition first time planning(ms) pg 12.2 with native partition second time planning(ms)
    4 1.89 1.24 1.38 1.22 1.41 0.62
    16 5.79 3.08 2.47 2.87 1.61 0.61
    64 56.59 15.49 2.93 2.76 1.14 0.67
    256 118.45 64.45 18.88 5.44 1.04 1.11
    1024 529.63 318.23 39.40 27.10 1.20 0.90
    4096 1807.08 1026.59 453.82 317.20 1.22 0.89
    16384 14528.33 10398.71 626.67 491.84 5.79 2.36
    65536 too many range table entries too many range table entries 2412.02 1722.45 11.06 3.62

    我们可以看到,pg 11的原生分区,在64个分区以上,基本上有可以感觉的影响的。如果分区数有64个以上,建议大家使用pg 12的版本。如果必须保留在pg 11的版本,那么也建议使用pg_pathman插件,来替代原生分区。

    附件:
    原生分区和pg_pathman对比测试的脚本:
    test_planing_time_with_pg_pathman
    test_planing_time_native_partition

    曲线图
    graph_of_planning_time



沪ICP备19023445号-2号
友情链接