PostgreSQL 13 Beta 1已经发布进行测试。
postgres=# show server_version_num; server_version_num -------------------- 130000 (1 row) |
PostgreSQL 13 新功能
与以前的版本相比, PostgreSQL 13 中已添加了 160 多个新功能。
我将比较 PostgreSQL 12 ( 12.3 )和 PostgreSQL 13 Beta 1 ( 13.0 )之间的主要区别。但是,在这里我不会描述所有功能,我将列出在 性能改进中起重要作用的功能 。
用于测试 PostgreSQL 13 新功能的硬件 / 软件。
§ 操作系统: RHEL 6
§ 磁盘: SSD
§ PostgreSQL 版本: v12.3 vs v13 Beta 1
新功能 1 :增量排序
PostgreSQL 13在其发行说明中强调了 增量排序是 PostgreSQL 13的主要新功能之一。
PostgreSQL 13 的增量排序,当已经对从查询的较早部分排序的数据进行排序时,可以加速对数据的排序。
例如,您在 c1 上有一个索引,并且需要按 c1 , c2 对数据集进行排序。然后,增量排序可以为您提供帮助,因为它不会对整个数据集进行排序,而是对具有相同 c1 值的单个组进行排序。当您具有 LIMIT 子句时,增量排序将非常有帮助。
让我们在 PostgreSQL 12 和 PostgreSQL 13 Beta 1 中运行以下查询。
从 pgbench_accounts 订单中选择 * ,按帮助,出价进行;
这里的援助有一个指标,而出价没有一个指标。
PostgreSQL 12.3
[postgres@dbapath06 ~]$ psql psql (12.3) Type "help" for help.
postgres=# SET work_mem TO '64kB'; SET postgres=# explain analyze select * from pgbench_accounts order by aid, bid; QUERY PLAN ----------------------------------------------------------------------------------
Gather Merge (cost=60150.23..99041.91 rows=333334 width=97) (actual time=494.075..707.664 rows=400000 loops=1) Workers Planned: 2 Workers Launched: 2 -> Sort (cost=59150.20..59566.87 rows=166667 width=97) (actual time=442.889..470.942 rows=133333 loops=3) Sort Key: aid, bid Sort Method: external merge Disk: 16592kB Worker 0: Sort Method: external merge Disk: 13432kB Worker 1: Sort Method: external merge Disk: 11936kB -> Parallel Seq Scan on pgbench_accounts (cost=0.00..8224.67 rows=166667 width=97) (actual time=0.030..37.491 rows=133333 loops=3) Planning Time: 0.052 ms Execution Time: 724.088 ms (11 rows)
|
PostgreSQL 13 Beta 1
[postgres@postgreshelp ~]$ psql psql (13beta1) Type "help" for help.
postgres=# SET work_mem TO '64kB'; SET postgres=# explain analyze select * from pgbench_accounts order by aid, bid; QUERY PLAN ---------------------------------------------------------------------- Incremental Sort (cost=0.47..34957.42 rows=400000 width=97) (actual time=0.208..219.769 rows=400000 loops=1) Sort Key: aid, bid Presorted Key: aid Full-sort Groups: 12500 Sort Method: quicksort Average Memory: 29kB Peak Memory: 29kB -> Index Scan using pgbench_accounts_pkey on pgbench_accounts (cost=0.42..16957.42 rows=400000 width=97) (actual time=0.055..146.3 56 rows=400000 loops=1) Planning Time: 0.810 ms Execution Time: 234.531 ms (7 rows) |
通过不一次对整个表进行排序,而是对块进行排序,这增加了排序后的块适合内存的机会,并且有可能使用快速排序代替较慢,要求更高的外部排序。
您可以使用以下参数启用或禁用查询计划程序对增量排序步骤的使用。默认值为 。 on
enable_incrementalsort ( boolean )