iis服务器助手广告广告
返回顶部
首页 > 资讯 > 数据库 >PostgreSQL11有哪些新特性
  • 336
分享到

PostgreSQL11有哪些新特性

2024-04-02 19:04:59 336人浏览 独家记忆
摘要

这篇文章主要介绍“postgresql11有哪些新特性”,在日常操作中,相信很多人在Postgresql11有哪些新特性问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”Post

这篇文章主要介绍“postgresql11有哪些新特性”,在日常操作中,相信很多人在Postgresql11有哪些新特性问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”PostgreSQL11有哪些新特性”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

一、并行查询

Parallel Hash
Hash Join执行时,在构造Hash表和进行Hash连接时,PG 11可使用并行的方式执行。
测试脚本:

testdb=# create table t1 (c1 int,c2 varchar(40),c3 varchar(40));
CREATE TABLE
testdb=# 
testdb=# insert into t1 select generate_series(1,5000000),'TEST'||generate_series(1,1000000),generate_series(1,1000000)||'TEST';
INSERT 0 5000000

testdb=# drop table if exists t2;
DROP TABLE
testdb=# create table t2 (c1 int,c2 varchar(40),c3 varchar(40));
CREATE TABLE
testdb=# 
testdb=# insert into t2 select generate_series(1,1000000),'T2'||generate_series(1,1000000),generate_series(1,1000000)||'T2';
INSERT 0 1000000

testdb=# explain verbose
testdb-# select t1.c1,t2.c1 
testdb-# from t1 inner join t2 on t1.c1 = t2.c1;
                                         QUERY PLAN                                          
---------------------------------------------------------------------------------------------
 Gather  (cost=18372.00..107975.86 rows=101100 width=8)
   Output: t1.c1, t2.c1
   Workers Planned: 2 -- 2 Workers
   ->  Parallel Hash Join  (cost=17372.00..96865.86 rows=42125 width=8) -- Parallel Hash Join
         Output: t1.c1, t2.c1
         Hash Cond: (t1.c1 = t2.c1)
         ->  Parallel Seq Scan on public.t1  (cost=0.00..45787.33 rows=2083333 width=4)
               Output: t1.c1
         ->  Parallel Hash  (cost=10535.67..10535.67 rows=416667 width=4) -- Parallel Hash
               Output: t2.c1
               ->  Parallel Seq Scan on public.t2  (cost=0.00..10535.67 rows=416667 width=4)
                     Output: t2.c1

除了Parallel Hash外,PG 11在执行Parallel Append(执行UNION ALL等集合操作)/CREATE TABLE AS SELECT/CREATE MATERIALIZED VIEW/SELECT INTO/CREATE INDEX等操作时以并行的方式执行.

二、数据表分区

Hash Partition
PG 在11.x引入了Hash分区,关于Hash分区,官方文档有如下说明:

The table is partitioned by specifying a modulus and a remainder for each partition. Each partition will hold the rows for which the hash value of the partition key divided by the specified modulus will produce the specified remainder.

每个Hash分区需指定"模"(modulus)和"余"(remainder),数据在哪个分区(partition index)的计算公式:
partition index = abs(hashfunc(key)) % modulus

drop table if exists t_hash2;
create table t_hash2 (c1 int,c2  varchar(40),c3 varchar(40)) partition by hash(c1);
create table t_hash2_1 partition of t_hash2 for values with (modulus 6,remainder 0);
create table t_hash2_2 partition of t_hash2 for values with (modulus 6,remainder 1);
create table t_hash2_3 partition of t_hash2 for values with (modulus 6,remainder 2);
create table t_hash2_4 partition of t_hash2 for values with (modulus 6,remainder 3);
create table t_hash2_5 partition of t_hash2 for values with (modulus 6,remainder 4);
create table t_hash2_6 partition of t_hash2 for values with (modulus 6,remainder 5);

testdb=# insert into t_hash2 
testdb-# select generate_series(1,1000000),'HASH'||generate_series(1,1000000),generate_series(1,1000000)||'HASH';
INSERT 0 1000000

数据在各分区上的分布大体均匀.
2018-9-19 注:由于插入数据时语句出错,昨天得出的结果有误(但数据在各个分区的分布上不太均匀,t_hash2_1分区行数明显的比其他分区的要多很多),请忽略

testdb=# select count(*) from only t_hash2;
; count 
-------
     0
(1 row)

testdb=# select count(*) from only t_hash2_1;
 count  
--------
 166480
(1 row)

testdb=# select count(*) from only t_hash2_2;
 count  
--------
 166904
(1 row)

testdb=# select count(*) from only t_hash2_3;
 count  
--------
 166302
(1 row)

testdb=# select count(*) from only t_hash2_4;
 count  
--------
 166783
(1 row)

testdb=# select count(*) from only t_hash2_5;
 count  
--------
 166593
(1 row)

testdb=# select count(*) from only t_hash2_6;
 count  
--------
 166938
(1 row)

Hash分区键亦可以创建在字符型字段上

testdb=# drop table if exists t_hash4;
DROP TABLE
testdb=# create table t_hash4 (c1 int,c2  varchar(40),c3 varchar(40)) partition by hash(c2);
CREATE TABLE

-- 需创建相应的"Partition"用于存储相应的数据
testdb=# insert into t_hash4 
testdb-# select generate_series(1,100000),'HASH'||generate_series(1,1000000),generate_series(1,1000000)||'HASH';
ERROR:  no partition of relation "t_hash4" found for row
DETAIL:  Partition key of the failing row contains (c2) = (HASH1).

-- 6个分区,3个sub-table,插入数据会出错
testdb=# 
testdb=# create table t_hash4_1 partition of t_hash4 for values with (modulus 6,remainder 0);
CREATE TABLE
testdb=# create table t_hash4_2 partition of t_hash4 for values with (modulus 6,remainder 1);
CREATE TABLE
testdb=# create table t_hash4_3 partition of t_hash4 for values with (modulus 6,remainder 2);
CREATE TABLE
testdb=# insert into t_hash4 
testdb-# select generate_series(1,10000),'HASH'||generate_series(1,10000),generate_series(1,10000)||'HASH';
ERROR:  no partition of relation "t_hash4" found for row
DETAIL:  Partition key of the failing row contains (c2) = (HASH1).

-- 3个分区,3个sub-table,正常
testdb=# drop table if exists t_hash4;
DROP TABLE
testdb=# create table t_hash4 (c1 int,c2  varchar(40),c3 varchar(40)) partition by hash(c2);
CREATE TABLE
testdb=# create table t_hash4_1 partition of t_hash4 for values with (modulus 3,remainder 0);
CREATE TABLE
testdb=# create table t_hash4_2 partition of t_hash4 for values with (modulus 3,remainder 1);
CREATE TABLE
testdb=# create table t_hash4_3 partition of t_hash4 for values with (modulus 3,remainder 2);
CREATE TABLE
testdb=# insert into t_hash4 
testdb-# select generate_series(1,10000),'HASH'||generate_series(1,10000),generate_series(1,10000)||'HASH';
INSERT 0 10000

考察分区的数据分布,还比较均匀:

testdb=# 
testdb=# select count(*) from only t_hash4;
 count 
-------
     0
(1 row)

testdb=# select count(*) from only t_hash4_1;
 count 
-------
  3378
(1 row)

testdb=# select count(*) from only t_hash4_2;
 count 
-------
  3288
(1 row)

testdb=# select count(*) from only t_hash4_3;
 count 
-------
  3334
(1 row)

Default Partition
List和Range分区可指定Default Partition(Hash分区不支持).

Update partition key
PG 11可Update分区键,这会导致数据的"迁移".

Create unique constraint
PG 11在分区表上创建主键和唯一索引(注:oracle在很早的版本已支持此特性).
在普通字段上可以创建BTree索引.

testdb=# alter table t_hash2 add primary key(c1);
ALTER TABLE
testdb=# create index idx_t_hash2_c2 on t_hash2(c2);
CREATE INDEX

FOREIGN KEY support
PG 11支持在分区上创建外键.

除了上述几个新特性外,分区上面,PG 11在Automatic index creation/INSERT ON CONFLICT/Partition-Wise Join / Partition-Wise Aggregate/FOR EACH ROW trigger/Dynamic Partition Elimination/Control Partition Pruning上均有所增强.

到此,关于“PostgreSQL11有哪些新特性”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注编程网网站,小编会继续努力为大家带来更多实用的文章!

您可能感兴趣的文档:

--结束END--

本文标题: PostgreSQL11有哪些新特性

本文链接: https://www.lsjlt.com/news/64955.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • PostgreSQL11有哪些新特性
    这篇文章主要介绍“PostgreSQL11有哪些新特性”,在日常操作中,相信很多人在PostgreSQL11有哪些新特性问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”Post...
    99+
    2024-04-02
  • JDK1.5有哪些新特性
    本篇内容主要讲解“JDK1.5有哪些新特性”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“JDK1.5有哪些新特性”吧!  1.泛型(Generic)  C++通过模板技术可以指定集合的元素类型,...
    99+
    2023-06-03
  • css3新特性有哪些
    这篇文章将为大家详细讲解有关css3新特性有哪些,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。   CSS3的新特征有:1、圆角效果;2、图形化边界;3、块阴影与文字阴...
    99+
    2024-04-02
  • CSS3有哪些新特性
    这篇文章主要介绍“CSS3有哪些新特性”,在日常操作中,相信很多人在CSS3有哪些新特性问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”CSS3有哪些新特性”的疑惑有所帮助!接...
    99+
    2024-04-02
  • Flex4新特性有哪些
    这篇文章将为大家详细讲解有关Flex4新特性有哪些,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。Flex4新特性先来看看Flex4的一些消息吧:Flex4.0的代码编号为Spark,其有新的组件和皮肤架构...
    99+
    2023-06-17
  • ECMAScript新特性有哪些
    本篇内容介绍了“ECMAScript新特性有哪些”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!1. Top-level Await在ES20...
    99+
    2023-07-02
  • Kubernetes1.5有哪些新特性
    这篇“Kubernetes1.5有哪些新特性”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“Kubernetes1.5有哪些新...
    99+
    2023-06-28
  • Hibernate3有哪些新特性
    小编给大家分享一下Hibernate3有哪些新特性,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!Hibernate3新特性Hibernate3在产品的应用性上有了...
    99+
    2023-06-17
  • kubernetes1.4有哪些新特性
    这篇文章主要介绍“kubernetes1.4有哪些新特性”,在日常操作中,相信很多人在kubernetes1.4有哪些新特性问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”kubernetes1.4有哪些新特性...
    99+
    2023-06-27
  • PHP8.1新特性有哪些
    这篇文章主要为大家展示了“PHP8.1新特性有哪些”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“PHP8.1新特性有哪些”这篇文章吧。当大多数人的 Linux ...
    99+
    2024-04-02
  • Swagger3.0有哪些新特性
    这篇文章主要讲解了“Swagger3.0有哪些新特性”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Swagger3.0有哪些新特性”吧!支持 OpenAPI...
    99+
    2024-04-02
  • JavaScript新特性有哪些
    这篇文章主要介绍“JavaScript新特性有哪些”,在日常操作中,相信很多人在JavaScript新特性有哪些问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”JavaScri...
    99+
    2024-04-02
  • jQuery1.6.4有哪些新特性
    本篇内容介绍了“jQuery1.6.4有哪些新特性”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!Data:...
    99+
    2024-04-02
  • Vue3.2有哪些新特性
    本篇内容介绍了“Vue3.2有哪些新特性”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!第一个:<script setup> 正式...
    99+
    2023-06-26
  • Laravel10有哪些新特性
    今天小编给大家分享一下Laravel10有哪些新特性的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。Laravel 10 发布...
    99+
    2023-07-04
  • PHP8.2有哪些新特性
    这篇“PHP8.2有哪些新特性”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“PHP8.2有哪些新特性”文章吧。null和fa...
    99+
    2023-07-02
  • Android3.1新特性有哪些
    Android 3.1(Honeycomb)是Android操作系统的一个版本,主要用于平板电脑。以下是Android 3.1的主要...
    99+
    2023-09-13
    Android
  • html5有哪些新特性
    本教程操作环境:windows7系统、HTML5版、Dell G3电脑。HTML5的十大新特性 为了更好地处理今天的互联网应用,HTML5添加了很多新元素及功能,比如: 图形的绘制,多媒体内容,更好的页面结构,更好的形式 处理,和几个api...
    99+
    2023-05-14
    html5
  • oracle18c新特性有哪些
    oracle18c新特性有哪些,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。Oracle宣布Database...
    99+
    2024-04-02
  • Python3.9新特性有哪些
    本篇内容介绍了“Python3.9新特性有哪些”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!使用 Python 进行相对导包的时候,__im...
    99+
    2023-06-02
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作