• Greenplum-表的分布策略


    Greenplum中所有的表都是必须分布存放的,这样可以充分利用MPP的并发特性。
    在创建表时可以指定不同的分布策略,包括三种分布策略:HASH分布、随机分布和复制表。

    HASH分布

    概念:选择一个列或多个列作为数据表的分布键,通过hash计算,将插入的数据路由到特定的segment上。
    HASH分布是默认的分布策略。也可通过指定DISTRIBUTED BY语法来指定使用HASH分布。
    注:当建表时未定义分布键时,如果表有主键,使用主键字段作为默认的分布键;如果表上没有主键,默认按照第一个字段来分布。

    示例:

    =# create table dist1(a int, b text);
    NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Database data distribution key for this table.
    HINT:  The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
    CREATE TABLE
    =# \d dist1
    Table "public.dist1"
    Column |  Type   | Modifiers
    --------+---------+-----------
    a      | integer |
    b      | text    |
    Distributed by: (a)
    =# create table dist1(a int, b text, primary key (b));
    CREATE TABLE
    =# \d dist1
    Table "public.dist1"
    Column |  Type   | Modifiers
    --------+---------+-----------
    a      | integer |
    b      | text    | not null
    Indexes:
    "dist1_pkey" PRIMARY KEY, btree (b)
    Distributed by: (b)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22

    随机分布

    概念:数据随机分散在每一个节点中,可以保证数据平均分布,但是在执行 SQL 的过程中,关联等操作都需要将数据重分布,性能较差。
    通过指定DISTRIBUTED RANDOMLY语法来指定使用随机分布。
    注:如果表上有主键,不能创建为随机分布表。
    示例:

    =# create table dist1(a int, b text, primary key (a)) distributed randomly;
    ERROR:  PRIMARY KEY and DISTRIBUTED RANDOMLY are incompatible
    =# create table dist1(a int, b text) distributed randomly;
    CREATE TABLE
    =# \d dist1
    Table "public.dist1"
    Column |  Type   | Modifiers
    --------+---------+-----------
    a      | integer |
    b      | text    |
    Distributed randomly
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    注:如果想将默认的分布策略设置为随机分布,我们可以通过设置gp_create_table_random_default_distribution值为on来实现,默认值为off。
    gpconfig --show gp_create_table_random_default_distribution

    Values on all segments are consistent
    GUC          : gp_create_table_random_default_distribution
    Master  value: off
    Segment value: off
    
    • 1
    • 2
    • 3
    • 4

    复制表

    概念:每一条记录都会分布到整个集群的所有Instance上,仅用于小表。
    通过指定DISTRIBUTED REPLICATED语法来指定使用复制表。

    示例:

    =# create table dist1(a int, b text, primary key (a)) distributed replicated;
    CREATE TABLE
    qianbase=# \d dist1
    Table "public.dist1"
    Column |  Type   | Modifiers
    --------+---------+-----------
    a      | integer | not null
    b      | text    |
    Indexes:
    "dist1_pkey" PRIMARY KEY, btree (a)
    Distributed Replicated
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
  • 相关阅读:
    LiveGBS流媒体平台GB/T28181功能-服务器日志文件过大时如何关闭信令服务日志和流媒体服务相关日志如何配置
    【个人网站搭建】hexo框架Next主题下利用不蒜子统计网站访问次数
    ubuntu 根目录空间扩容
    迅为龙芯2K1000开发板虚拟机ubuntu启动root用户
    qt历史数据管理模块(模块化程序)功能块复制直接使用不冲突
    状态管理 Pinia
    ASP.NET Core 3.1系列(15)——Entity Framework Core之DB First
    统计学习第一章
    Hadoop生态系统官网、下载地址、文档
    【web前端】CSS高级技巧(精灵图,字体图标,CSS三角,CSS用户界面样式,文字与图片垂直对齐,溢出的文字省略号显示,常见布局技巧,CSS初始化)
  • 原文地址:https://blog.csdn.net/Post_Yuan/article/details/126868191