GP数据库中的表一般都会设置分布键,如果没有设置的话,它一般默认是第一个字段,所以一般会建议使用一个记录会分布均匀的字段作为分布键使用,使表中的记录均匀的分布到每一个segment中。
GP数据库分布键查询方法:
select c.schema_name,
c.table_name,
c.table_comment as "中文表明",
c.column_name as "分布键",
from ( select d.nspname as schema_name,
c.relname as table_name,
obj_description(c.oid) as table_comment,
a.attname as column_name
from pg_class c
left join pg_attribute a
on a.attrelid = c.oid
join pg_namespace d
on d.oid = c.relnamespace
left join pg_inherits f
on c.oid = f.inhrelid
where a.attnum > 0
and f.inhrelid is null)c
join (select a.attrnums[i.i] as a.attrnums,
b.a