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.attname, a.localoid::regclass as localoid from gp_distribution_policy a, (select generate_series(1,10) as generate_series) i(i), pg_attribute b where a.attrnums[i.i] is not null and a.localoid = b.attrelid and a.attrnums[i.i] = b.attnum) t on c.column_name = t.attname and ((c.schema_name::text || ‘.‘::text) || a.table_name::text)::regclass::oid = t.localoid::oid order by c.schema_name, c.table_name, c.column_name ;
时间: 2024-11-09 03:22:49