Archive for the ‘postgresql and greenplum’ Category
星期三, 一月 14th, 2009
26,分析表
语法:
ORACLE :ANALYZE TABLE test COMPUTE STATISTICS;
GP :ANALYZE TEST;
27,表中增加字段
语法:
ORACLE :ALTER TABLE test ADD score NUMBER;
GP :ALTER TABLE test ADD score FLOAT;
28,表中删除字段
语法:
ORACLE :ALTER TABLE test DROP COLUMN score;
GP :ALTER TABLE test DROP COLUMN score;
29,集合操作
语法:
ORACLE :query1 UNION [ALL] query2 (合集)
query1 INTERSECT query2 (交集)
query1 MINUS query2 (差集)
GP :query1 UNION [ALL] query2 (合集)
query1 INTERSECT [ALL] ...
Posted in postgresql and greenplum | 1 Comment »
星期三, 一月 14th, 2009
为了帮助大家快速掌握在GP上的开发,整理了一份GP和ORACLE开发的对照手册。
具体如下:
1,连接数据库
语法:
ORACLE :sqlplus etl/etl
GP :psql -U etl
备注:
上面的操作为以etl用户的身份登陆数据库。
2,创建非分区表
语法:
ORACLE :CREATE TABLE test(id NUMBER,name VARCHAR2(40);
GP :CREATE TABLE test(id INT,name VARCHAR(40)) DISTRIBUTED BY (id);
备注:
ORACLE和GP中的数据类型有些不同,附录中会有具体的GP数据类型的列表。
另外的不同是GP中的建表语句最后会有distributed by (id),这个语句的含义是按照id的hash值将表test中的记录分布到GP的各个结点(segment)上。
GP的架构决定数据在各个结点分布得越平均,那么数据操作的性能就越好。所以我们选择distributed列的时候要特别注意,应该选择那些重复值多的,选择性高的列。
distributed列也可以是多个字段。如果不指定distributed列,那么系统会选择主键列或者表的第一个列。
3,创建分区表
语法:
ORACLE :CREATE TABLE test(id NUMBER,name VARCHAR2(40),birth_day DATE)
PARTITION BY RANGE(birth_day)
(PARTITION p20090101 VALUES LESS THAN (TO_DATE('20090102','yyyymmdd')),
PARTITION p20090102 VALUES LESS THAN (TO_DATE('20090103','yyyymmdd')),
PARTITION p20090103 VALUES LESS THAN (TO_DATE('20090104','yyyymmdd')));
GP :CREATE TABLE test(id INT,name VARCHAR(40),birth_day DATE)
DISTRIBUTED ...
Posted in postgresql and greenplum | Comments Off
星期四, 十二月 4th, 2008
原来介绍过postgresql上分区表的实现方法,比较麻烦。
在greenplum 3.2中,已经增加对分区表的支持。
使我们能更加方便的使用分区表来提高系统的性能。
目前没有测试环境,就从文档上找下例子。
1,系统规划分区
CREATE TABLE sales (id int, date date, amt decimal(10,2))
DISTRIBUTED BY (id)
PARTITION BY RANGE (date)
( START (date '2008-01-01') INCLUSIVE
END (date '2009-01-01') EXCLUSIVE
EVERY (INTERVAL '1 day') );
2,手工规划分区
CREATE TABLE sales (id int, date date, amt decimal(10,2))
DISTRIBUTED BY (id)
PARTITION BY RANGE (date)
( PARTITION Jan08 START (date '2008-01-01') INCLUSIVE ,
PARTITION Feb08 START ...
Posted in postgresql and greenplum | No Comments »
星期一, 九月 22nd, 2008
对于postgresql来说,''和null是不相同的。''代表ascii为0的字符,而null则表示不存在。
postgresql中插入''
sunwg=# create table sunwg_postgresql
sunwg-# (id varchar(10));
CREATE TABLE
sunwg=# insert into sunwg_postgresql values ('');
INSERT 0 1
sunwg=# select * from sunwg_postgresql where id = '';
id
----
(1 row)
sunwg=# select * from sunwg_postgresql where id is null;
id
----
(0 rows)
postgresql中插入null
sunwg=# truncate table sunwg_postgresql;
TRUNCATE TABLE
sunwg=# insert into sunwg_postgresql values (null);
INSERT 0 1
sunwg=# select * from sunwg_postgresql where id is ...
Posted in postgresql and greenplum | No Comments »
星期三, 九月 17th, 2008
下面通过个典型的SQL来分析下GREENPLUM分布式数据库中ORDER BY的执行过程。
EXPLAIN SELECT COUNT(*) FROM
(SELECT * FROM sunwg.TEST1
ORDER BY COL1) AS aa;
Aggregate (cost=2887251.85..2887251.86 rows=1 width=0)
-> Gather Motion 8:1 (slice1) (cost=2887251.80..2887251.83 rows=1 width=0)
-> Aggregate (cost=2887251.80..2887251.81 rows=1 width=0)
-> Subquery Scan aa (cost=2885334.66..2887251.80 rows=1 width=0)
-> Sort (cost=2885334.66..2887251.79 rows=766850 width=2250)
Sort Key: COL1
-> Seq Scan on test1 (cost=0.00..62443.50 rows=766850 ...
Posted in postgresql and greenplum | No Comments »