• 左连接  不能将左表广播
  • 右连接  不能将右表广播
 
关联表尽量使用相同的分布键,可以直接进行数据关联,不用进行重分布
 

内连接

 
情况1:select * from test_table_5000 as t1, test_table_10000 as t2  where t1.id=t2.id关联键是分布键,不涉及重分布 

情况2:select * from test_table_5000 as t1, test_table_10000 as t2  where t1.id=t2.id2 
方式1:将t1表广播到每一个segment上,数据量是N*6(segment数量) 
方式2:将t2表根据id2重分布数据,数据量是M

情况3:select * from test_table_5000 as t1, test_table_10000 as t2 where t1.id2=t2.id2

 
 
 
根据代价选择方式:
  • 方式1将两个表都按照id2重分布,数据量: M+N 
  • 方式2将小表进行广播,数据量:N*(segment数量)
 
  • 左分布键 关联 右非分布键
greenplum 关于联表的特性
  • 无分布键进行关联:
greenplum 关于联表的特性
 

左连接

左连接时,左表不允许广播 
  • 情况1:select * from test_table_5000 as t1 left join test_table_10000 as t2 on t1.id=t2.id 两个表都是分布键,不涉及广播与重分布 
  • 情况2:select * from test_table_5000 as t1 left join test_table_10000 as t2 on t1.id=t2.id2 将t2表进行重分布,数据量 M
  • 情况3:select * from test_table_5000 as t1 left join test_table_10000 as t2 on t1.id2=t2.id 
  • 方式1:将左表按照id2重分布,数据量N 
  • 方式2:将右表广播,数据量为M*6 
  • 情况4:select * from test_table_5000 as t1 left join test_table_10000 as t2 on t1.id2=t2.id2 
  • 方式1:将两表按照id2重分布,数据量N+M 
  • 方式2:将右表广播,数据量为M*6
 

全连接

全连接时,两表不允许广播 
  • 情况一:select * from test_table_5000 as t1 full outer join test_table_10000 as t2 on t1.id=t2.id; 两表关联键都是分布键,不涉及重分布与广播 
  • 情况二:select * from test_table_5000 as t1 full outer join test_table_10000 as t2 on t1.id=t2.id2 无论t2表数据量有多大,都是只能重分布t2
  • 情况三:select * from test_table_5000 as t1 full outer join test_table_10000 as t2 on t1.id2=t2.id2 对两个表进行重分布
 
 
 
普通分库分表没有办法直接进行关联数据,A表关联B表,在节点1上能取到1-100的数据,但是节点2关联就无法获取B表的101-1000的数据。
 
greenplum 关于联表的特性
gp基于分布键关联:
greenplum 关于联表的特性

相关文章: