天天看点

PostgreSQL 9.6 内核优化 - sort 性能增强

digoal

2016-10-09

postgresql , sort , 内核优化

postgresql 9.6在排序这块做了一些性能增强,前面一篇主要讲了排序算法的变更。

<a href="https://github.com/digoal/blog/blob/master/201610/20161008_02.md">《postgresql 9.6 内核优化 - sort性能增强(batch化quicksort代替replacement selection when work_mem small)》</a>

本文针对另外几个sort增强的点再简单介绍一下。

1. 文本排序性能增强,当相同的文本多次出现时,性能有所增强。

speed up text sorts where the same string occurs multiple times (peter geoghegan)

<a href="https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=0e57b4d8bd9674adaf5747421b3255b85e385534">https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=0e57b4d8bd9674adaf5747421b3255b85e385534</a>

2. 对uuid,bytea,char(n)的排序性能增强,使用abb keys, 整型比较算法取代memcmp。

speed up sorting of uuid, bytea, and char(n) fields by using "abbreviated" keys (peter geoghegan)

support for abbreviated keys has also been added to the non-default operator classes text_pattern_ops, varchar_pattern_ops, and bpchar_pattern_ops.

processing of ordered-set aggregates can also now exploit abbreviated keys.

<a href="https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=a76ef15d9fc9207a0758e8d6f6700dc8c931a934">https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=a76ef15d9fc9207a0758e8d6f6700dc8c931a934</a>

<a href="https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=bfb54ff15a447fb22e9deae096e0d45b3e4bd56f">https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=bfb54ff15a447fb22e9deae096e0d45b3e4bd56f</a>

3. 并行创建索引(非堵塞式)的性能增强

speed up create index concurrently by treating tids as 64-bit integers during sorting (peter geoghegan)

<a href="https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=b648b70342fbe712383e8cd76dc8f7feaba9aaa3">https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=b648b70342fbe712383e8cd76dc8f7feaba9aaa3</a>

1. 高度重复文本排序

1000万记录

1.1 postgresql 9.5

排序耗时7.9秒

1.2 postgresql 9.6

排序耗时6.9秒

2. 离散文本排序

2.1 postgresql 9.5

排序耗时19.9秒

2.2 postgresql 9.6

排序耗时15秒

3. char(n)排序

3.1 postgresql 9.5

排序耗时27.8秒

3.2 postgresql 9.6

排序耗时16.2秒

4. 非堵塞式创建索引

5000万随机数据

4.1 postgresql 9.5

4.2 postgresql 9.6

5. 堵塞式创建索引

5.1 postgresql 9.5

5.2 postgresql 9.6

1. 高度重复文本排序(1000万记录)

postgresql 9.5 排序耗时7.9秒

postgresql 9.6 排序耗时6.9秒

2. 离散文本排序(1000万记录),quicksort的优化

postgresql 9.5 排序耗时19.9秒

postgresql 9.6 排序耗时15秒

3. char(n)排序(1000万记录)

postgresql 9.5 排序耗时27.8秒

postgresql 9.6 排序耗时16.2秒

4. 非堵塞式创建索引(5000万记录)

postgresql 9.5 排序耗时92.6秒

postgresql 9.6 排序耗时56.5秒

5. 堵塞式创建索引(5000万记录)

postgresql 9.5 排序耗时40.7秒

postgresql 9.6 排序耗时40.7秒

<a href="http://info.flagcounter.com/h9v1">count</a>