GreenPlum笔记之一

浏览: 1991

数据分布均匀是保证GP高效并行处理能力的基础。因此定义表时,如果选用HASH分布策略,保证数据分布均匀是获取高性能的关键所在。

选择的依据遵从三大原则:

第一个就是首先保证前面提到的所有节点数据存放是均匀的。

第二,如果经常进行大表连接,那么尽量把连接键定义成数据分布键(如果多个列作为数据分布键,他们应该都出现在连接中,否则还是会造成无效广播),这样尽量减少无效的interconnect。

第三,尽量保证where条件产生的结果集的存储也尽量是均匀的。


常用语句:

1. 查看表使用空间
 SELECT      *  
FROM         PUBLIC.dba_segments  
WHERE         owner   LIKE   'owber_name'
 AND            table_name   LIKE   '%table_name%'
 ORDER   BY   table_name;
 
2. GP中查看分区:
 select   partitionname,partitionboundary   from   pg_partitions   where   tablename='table_name';  
select   partitionname,partitionboundary   from   pg_catalog.pg_partitions   where   tablename='table_name';
 
3.  查看正在运行的sql
   select   *   from   pg_stat_activity;
 
4. 修改表的owner语句
 Alter table table_name owner to owner_name;
 
5. 增加表分区
 ALTER TABLE table_name   ADD PARTITION P20091001  START (DATE '2009-10-01') INCLUSIVE END (DATE '2009-10-02')  EXCLUSIVE WITH(appendonly=true,compresslevel=5);
 
6. 修改列类型
 ALTER TABLE table_name  ALTER COLUMN a TYPE varchar(2048);
 
7. 修改distributed 列
 alter table table_name  set distributed by(column_1);

8.explain和explain analyze是有区别的。explain是基于统计,给出执行计划,他不会真正执行SQL,因此没有执行统计。explain analyze会真正执行SQL因此会提供执行过程中真实资源消耗统计,但是对在线系统可能影响会较大

9.查看对象大小(表、索引、数据库等)

select pg_size_pretty(pg_relation_size(’$schema.$table’));

10.查看用户(非系统)表和索引

select * from pg_stat_user_tables;

seect * from pg_stat_user_indexes;

11.查看表分区

select b.nspname||’.'||a.relname as tablename, d.parname as partname

from pg_class a, pg_namespace b, pg_partition c, pg_partition_rule d

where a.relnamespace = b.oid

and b.nspname = ‘$schema’

and a.relname = ‘$table’

and a.oid = c.parrelid

and c.oid = d.paroid

order by parname;

12.查看Distributed key

select  b.attname

from pg_class a, pg_attribute b, pg_type c, gp_distribution_policy  d, pg_namespace e

where d.localoid = a.oid

and a.relnamespace = e.oid

and e.nspname = ‘$schema’

and a.relname=’$table’

and a.oid = b.attrelid

and b.atttypid = c.oid

and b.attnum > 0

and b.attnum = any(d.attrnums)

order by attnum;

13.查看当前存活的查询

select procpid as pid, sess_id as session, usename as user, current_query as query, waiting,

date_trunc(’second’, query_start) as start_time, client_addr as useraddr

from pg_stat_activity

where datname =’$PGDATABASE’

and current_query not like ‘%from pg_stat_activity%where datname =%’

order by start_time;

14.表上被用作外键的字段名

select f.conname, pg_get_constraintdef(f.oid), t2.relname

from pg_class t, pg_class t2, pg_constraint f

where f.confrelid = t.oid

and f.conrelid = t2.oid

and f.contype = ‘f’

and t.relname = ‘$table’;

推荐 3
本文由 Bob 创作,采用 知识共享署名-相同方式共享 3.0 中国大陆许可协议 进行许可。
转载、引用前需联系作者,并署名作者且注明文章出处。
本站文章版权归原作者及原出处所有 。内容为作者个人观点, 并不代表本站赞同其观点和对其真实性负责。本站是一个个人学习交流的平台,并不用于任何商业目的,如果有任何问题,请及时联系我们,我们将根据著作权人的要求,立即更正或者删除有关内容。本站拥有对此声明的最终解释权。

1 个评论

赞。谢谢分享。

要回复文章请先登录注册