提交 5c43dbb6 编写于 作者: H Heikki Linnakangas

Move partition_ddl1 test from TINC.

Much of it was present in partition1 test already.
上级 0e864408
......@@ -1509,3 +1509,61 @@ drop table if exists s1;
drop table if exists s2;
-- end_ignore
create table mpp_2914A(id int, buyDate date, kind char(1))
DISTRIBUTED BY (id)
partition by list (kind)
subpartition by range(buyDate)
subpartition template
(
start (date '2001-01-01'),
start (date '2002-01-01'),
start (date '2003-01-01'),
start (date '2004-01-01'),
start (date '2005-01-01')
)
(
partition auction values('a','A'),
partition buyItNow values('b', 'B'),
default partition catchall
);
select count(*) from mpp_2914A;
\d mpp_2914a*
create table mpp_2914B(id int, buyDate date, kind char(1))
DISTRIBUTED BY (id)
partition by list (kind)
subpartition by range(buyDate)
(
partition auction values('a','A')
(
subpartition y2001 start (date '2001-01-01'),
subpartition y2002 start (date '2002-01-01'),
subpartition y2003 start (date '2003-01-01'),
subpartition y2004 start (date '2004-01-01'),
subpartition y2005 start (date '2005-01-01')
),
partition buyitnow values('b','B')
(
subpartition y2001 start (date '2001-01-01'),
subpartition y2002 start (date '2002-01-01'),
subpartition y2003 start (date '2003-01-01'),
subpartition y2004 start (date '2004-01-01'),
subpartition y2005 start (date '2005-01-01')
),
default partition catchAll
(
subpartition y2001 start (date '2001-01-01'),
subpartition y2002 start (date '2002-01-01'),
subpartition y2003 start (date '2003-01-01'),
subpartition y2004 start (date '2004-01-01'),
subpartition y2005 start (date '2005-01-01')
)
);
select count(*) from mpp_2914B;
\d mpp_2914b*
drop table mpp_2914a cascade;
drop table mpp_2914b cascade;
set client_min_messages = WARNING;
set gp_enable_hash_partitioned_tables = true;
DROP SCHEMA IF EXISTS partition_ddl1 CASCADE;
CREATE SCHEMA partition_ddl1;
SET search_path TO partition_ddl1;
-- disabled by default
create table ggg (a char(1), b char(2), d char(3))
distributed by (a)
partItion by hash(b)
partitions 3;
-- missing subpartition by
create table ggg (a char(1), b char(2), d char(3))
distributed by (a)
partition by hash (b)
(
partition aa (subpartition cc, subpartition dd),
partition bb (subpartition cc, subpartition dd)
);
-- missing subpartition spec
create table ggg (a char(1), b char(2), d char(3))
distributed by (a)
partition by hash (b)
subpartition by hash (d)
(
partition aa ,
partition bb
);
-- subpart spec conflict
create table ggg (a char(1), b char(2), d char(3))
distributed by (a)
partition by hash (b)
subpartition by hash (d) subpartition template (subpartition jjj)
(
partition aa (subpartition cc, subpartition dd),
partition bb (subpartition cc, subpartition dd)
);
-- missing subpartition by
create table ggg (a char(1), b char(2), d char(3))
distributed by (a)
partition by hash (b)
subpartition by hash (d)
(
partition aa (subpartition cc, subpartition dd (subpartition iii)),
partition bb (subpartition cc, subpartition dd)
);
-- missing subpartition spec
create table ggg (a char(1), b char(2), d char(3))
distributed by (a)
partition by hash (b)
subpartition by hash (d) ,
subpartition by hash (d)
(
partition aa (subpartition cc, subpartition dd),
partition bb (subpartition cc, subpartition dd)
);
drop table if exists ggg cascade;
-- should work
create table ggg (a char(1), b char(2), d char(3))
distributed by (a)
partition by hash (b)
subpartition by hash (d)
(
partition aa (subpartition cc, subpartition dd),
partition bb (subpartition cc, subpartition dd)
);
drop table ggg cascade;
-- should work
create table ggg (a char(1), b char(2), d char(3))
distributed by (a)
partition by hash (b)
subpartition by hash (d)
subpartition template (
subpartition cc,
subpartition dd
),
subpartition by hash (d)
subpartition template (
subpartition ee,
subpartition ff
)
(
partition aa,
partition bb
);
drop table ggg cascade;
-- should work
drop table if exists ggg cascade;
create table ggg (a char(1), b char(2), d char(3))
distributed by (a)
partition by hash (b)
subpartition by hash (d) ,
subpartition by hash (d)
subpartition template (
subpartition ee,
subpartition ff
)
(
partition aa (subpartition cc, subpartition dd),
partition bb (subpartition cc, subpartition dd)
);
drop table ggg cascade;
-- doesn't work because cannot have nested declaration in template
drop table if exists ggg;
create table ggg (a char(1), b char(2), d char(3))
distributed by (a)
partition by hash (b)
subpartition by hash (d)
subpartition template (
subpartition cc (subpartition ee, subpartition ff),
subpartition dd (subpartition ee, subpartition ff)
),
subpartition by hash (d)
(
partition aa,
partition bb
);
drop table ggg cascade;
--ERROR: Missing boundary specification in partition 'aa' of type LIST
create table fff (a char(1), b char(2), d char(3)) distributed by
(a) partition by list (b) (partition aa );
-- number 1 of type LIST
create table fff (a char(1), b char(2), d char(3)) distributed by (a)
partition by list (b) (start with ('a') );
-- should work
create table fff (a char(1), b char(2), d char(3)) distributed by (a)
partition by list (b) (partition aa values ('2'));
drop table fff cascade;
-- type HASH (at depth 2)
create table ggg (a char(1), b char(2), d char(3)) distributed by (a)
partition by hash (b) subpartition by hash (d) , subpartition by hash
(d) subpartition template ( subpartition ee, subpartition ff ) (
partition aa (subpartition cc, subpartition dd), partition bb
(subpartition cc start with ('a') , subpartition dd) );
-- generate 2 anonymous partitions
drop table if exists ggg;
create table ggg (a char(1), b date, d char(3))
distributed by (a)
partition by range (b)
(
partition aa start ('2007'), end ('2008'),
partition bb start ('2008'), end ('2009')
);
create table ggg (a char(1), b date, d char(3))
distributed by (a)
partition by range (b)
(
partition aa start (date '2007-01-01') end (date '2008-01-01'),
partition bb start (date '2008-01-01') end (date '2009-01-01')
);
drop table ggg cascade;
-- don't allow nonconstant expressions, even simple ones...
create table ggg (a char(1), b numeric, d numeric)
distributed by (a)
partition by range (b,d)
(
partition aa start (2007,1) end (2008,2+2),
partition bb start (2008,2) end (2009,3)
);
-- should work
create table ggg (a char(1), b numeric, d numeric)
distributed by (a)
partition by range (b,d)
(
partition aa start (2007,1) end (2008,2),
partition bb start (2008,2) end (2009,3)
);
drop table ggg cascade;
-- nested subpartitions
create table ggg
(a char(1), b date,
d char(3), e numeric,
f numeric, g numeric,
h numeric)
distributed by (a)
partition by hash(b)
partitions 2
subpartition by hash(d)
subpartitions 2,
subpartition by hash(e) subpartitions 2,
subpartition by hash(f) subpartitions 2,
subpartition by hash(g) subpartitions 2,
subpartition by hash(h) subpartitions 2;
drop table ggg cascade;
-- named, inline subpartitions
create table ggg (a char(1), b char(2), d char(3))
distributed by (a)
partition by hash (b)
subpartition by hash (d)
(
partition aa (subpartition cc, subpartition dd),
partition bb (subpartition cc, subpartition dd)
);
drop table ggg cascade;
-- subpartitions with templates
create table ggg (a char(1), b char(2), d char(3), e numeric)
distributed by (a)
partition by hash (b)
subpartition by hash (d)
subpartition template (
subpartition cc,
subpartition dd
),
subpartition by hash (e)
subpartition template (
subpartition ee,
subpartition ff
)
(
partition aa,
partition bb
);
drop table ggg cascade;
-- mixed inline subpartition declarations with templates
create table ggg (a char(1), b char(2), d char(3), e numeric)
distributed by (a)
partition by hash (b)
subpartition by hash (d) ,
subpartition by hash (e)
subpartition template (
subpartition ee,
subpartition ff
)
(
partition aa (subpartition cc, subpartition dd),
partition bb (subpartition cc, subpartition dd)
);
drop table ggg cascade;
-- basic list partition
create table ggg (a char(1), b char(2), d char(3))
distributed by (a)
partition by LIST (b)
(
partition aa values ('a', 'b', 'c', 'd'),
partition bb values ('e', 'f', 'g')
);
insert into ggg values ('x', 'a');
insert into ggg values ('x', 'b');
insert into ggg values ('x', 'c');
insert into ggg values ('x', 'd');
insert into ggg values ('x', 'e');
insert into ggg values ('x', 'f');
insert into ggg values ('x', 'g');
insert into ggg values ('x', 'a');
insert into ggg values ('x', 'b');
insert into ggg values ('x', 'c');
insert into ggg values ('x', 'd');
insert into ggg values ('x', 'e');
insert into ggg values ('x', 'f');
insert into ggg values ('x', 'g');
select * from ggg;
select * from ggg_1_prt_aa ;
select * from ggg_1_prt_bb ;
drop table ggg cascade;
-- documentation example - partition by list and range
CREATE TABLE rank (id int, rank int, year date, gender
char(1)) DISTRIBUTED BY (id, gender, year)
partition by list (gender)
subpartition by range (year)
subpartition template (
start (date '2001-01-01'),
start (date '2002-01-01'),
start (date '2003-01-01'),
start (date '2004-01-01'),
start (date '2005-01-01')
)
(
partition boys values ('M'),
partition girls values ('F')
);
insert into rank values (1, 1, date '2001-01-15', 'M');
insert into rank values (2, 1, date '2002-02-15', 'M');
insert into rank values (3, 1, date '2003-03-15', 'M');
insert into rank values (4, 1, date '2004-04-15', 'M');
insert into rank values (5, 1, date '2005-05-15', 'M');
insert into rank values (6, 1, date '2001-01-15', 'F');
insert into rank values (7, 1, date '2002-02-15', 'F');
insert into rank values (8, 1, date '2003-03-15', 'F');
insert into rank values (9, 1, date '2004-04-15', 'F');
insert into rank values (10, 1, date '2005-05-15', 'F');
select * from rank;
select * from rank_1_prt_boys;
select * from rank_1_prt_girls;
select * from rank_1_prt_girls_2_prt_1 ;
select * from rank_1_prt_girls_2_prt_2 ;
drop table rank cascade;
-- range list hash combo
create table ggg (a char(1), b date, d char(3), e numeric)
distributed by (a)
partition by range (b)
subpartition by list(d),
subpartition by hash(e) subpartitions 3
(
partition aa
start (date '2007-01-01')
end (date '2008-01-01')
(subpartition dd values (1,2,3), subpartition ee values (4,5,6)),
partition bb
start (date '2008-01-01')
end (date '2009-01-01')
(subpartition dd values (1,2,3), subpartition ee values (4,5,6))
);
drop table ggg cascade;
-- duplicate partition name
CREATE TABLE rank (id int, rank int, year date, gender
char(1)) DISTRIBUTED BY (id, gender, year)
partition by list (gender)
(
partition boys values ('M'),
partition girls values ('a'),
partition girls values ('b'),
partition girls values ('c'),
partition girls values ('d'),
partition girls values ('e'),
partition bob values ('M')
);
-- duplicate values
CREATE TABLE rank (id int, rank int, year date, gender
char(1)) DISTRIBUTED BY (id, gender, year)
partition by list (rank,gender)
(
values (1, 'M'),
values (2, 'M'),
values (3, 'M'),
values (1, 'F'),
partition ff values (4, 'M'),
partition bb values (1, 'M')
);
-- legal if end of aa not inclusive
create table ggg (a char(1), b date, d char(3))
distributed by (a)
partition by range (b)
(
partition aa start (date '2007-01-01') end (date '2008-01-01'),
partition bb start (date '2008-01-01') end (date '2009-01-01')
every (interval '10 days'));
drop table ggg cascade;
-- bad - legal if end of aa not inclusive
create table ggg (a char(1), b date, d char(3))
distributed by (a)
partition by range (b)
(
partition aa start (date '2007-01-01') end (date '2008-01-01') inclusive,
partition bb start (date '2008-01-01') end (date '2009-01-01')
every (interval '10 days'));
drop table ggg cascade;
-- legal because start of bb not inclusive
create table ggg (a char(1), b date, d char(3))
distributed by (a)
partition by range (b)
(
partition aa start (date '2007-01-01') end (date '2008-01-01') inclusive,
partition bb start (date '2008-01-01') exclusive end (date '2009-01-01')
every (interval '10 days'));
drop table ggg cascade;
-- legal if end of aa not inclusive
create table ggg (a char(1), b date, d char(3))
distributed by (a)
partition by range (b)
(
partition bb start (date '2008-01-01') end (date '2009-01-01'),
partition aa start (date '2007-01-01') end (date '2008-01-01')
);
drop table ggg cascade;
-- bad - legal if end of aa not inclusive
create table ggg (a char(1), b date, d char(3))
distributed by (a)
partition by range (b)
(
partition bb start (date '2008-01-01') end (date '2009-01-01'),
partition aa start (date '2007-01-01') end (date '2008-01-01') inclusive
);
drop table ggg cascade;
-- legal because start of bb not inclusive
create table ggg (a char(1), b date, d char(3))
distributed by (a)
partition by range (b)
(
partition bb start (date '2008-01-01') exclusive end (date '2009-01-01'),
partition aa start (date '2007-01-01') end (date '2008-01-01') inclusive
);
drop table ggg cascade;
-- validate aa - start greater than end
create table ggg (a char(1), b date, d char(3))
distributed by (a)
partition by range (b)
(
partition bb start (date '2008-01-01') end (date '2009-01-01'),
partition aa start (date '2007-01-01') end (date '2006-01-01')
);
drop table ggg cascade;
-- cannot set end of first partition because next is before
create table ggg (a char(1), b date, d char(3))
distributed by (a)
partition by range (b)
(
partition bb start (date '2008-01-01') ,
partition aa start (date '2007-01-01')
);
drop table ggg cascade;
-- the documentation example, rewritten with EVERY in a template
CREATE TABLE rank (id int,
rank int, year date, gender char(1))
DISTRIBUTED BY (id, gender, year)
partition by list (gender)
subpartition by range (year)
subpartition template (
start (date '2001-01-01')
end (date '2006-01-01') every (interval '1 year')) (
partition boys values ('M'),
partition girls values ('F')
);
insert into rank values (1, 1, date '2001-01-15', 'M');
insert into rank values (2, 1, date '2002-02-15', 'M');
insert into rank values (3, 1, date '2003-03-15', 'M');
insert into rank values (4, 1, date '2004-04-15', 'M');
insert into rank values (5, 1, date '2005-05-15', 'M');
insert into rank values (6, 1, date '2001-01-15', 'F');
insert into rank values (7, 1, date '2002-02-15', 'F');
insert into rank values (8, 1, date '2003-03-15', 'F');
insert into rank values (9, 1, date '2004-04-15', 'F');
insert into rank values (10, 1, date '2005-05-15', 'F');
select * from rank;
select * from rank_1_prt_boys;
select * from rank_1_prt_girls;
select * from rank_1_prt_boys_2_prt_1 ;
select * from rank_1_prt_boys_2_prt_2 ;
select * from rank_1_prt_girls_2_prt_1 ;
select * from rank_1_prt_girls_2_prt_2 ;
drop table rank cascade;
-- integer ranges work too
create table ggg (id integer, a integer)
distributed by (id)
partition by range (a)
(start (1) end (10) every (1));
insert into ggg values (1, 1);
insert into ggg values (2, 2);
insert into ggg values (3, 3);
insert into ggg values (4, 4);
insert into ggg values (5, 5);
insert into ggg values (6, 6);
insert into ggg values (7, 7);
insert into ggg values (8, 8);
insert into ggg values (9, 9);
insert into ggg values (10, 10);
select * from ggg;
select * from ggg_1_prt_1;
select * from ggg_1_prt_2;
select * from ggg_1_prt_3;
select * from ggg_1_prt_4;
drop table ggg cascade;
-- hash tests
create table ggg (a char(1), b varchar(2), d varchar(2))
distributed by (a)
partition by hash(b)
partitions 3;
insert into ggg values (1,1,1);
insert into ggg values (2,2,1);
insert into ggg values (1,3,1);
insert into ggg values (2,2,3);
insert into ggg values (1,4,5);
insert into ggg values (2,2,4);
insert into ggg values (1,5,6);
insert into ggg values (2,7,3);
insert into ggg values (1,'a','b');
insert into ggg values (2,'c','c');
select * from ggg;
select * from ggg_1_prt_1;
select * from ggg_1_prt_2;
select * from ggg_1_prt_3;
drop table ggg cascade;
-- use multiple cols
create table ggg (a char(1), b varchar(2), d varchar(2))
distributed by (a)
partition by hash(b,d)
partitions 3;
insert into ggg values (1,1,1);
insert into ggg values (2,2,1);
insert into ggg values (1,3,1);
insert into ggg values (2,2,3);
insert into ggg values (1,4,5);
insert into ggg values (2,2,4);
insert into ggg values (1,5,6);
insert into ggg values (2,7,3);
insert into ggg values (1,'a','b');
insert into ggg values (2,'c','c');
select * from ggg;
select * from ggg_1_prt_1;
select * from ggg_1_prt_2;
select * from ggg_1_prt_3;
drop table ggg cascade;
-- use multiple cols of different types
create table ggg (a char(1), b varchar(2), d integer, e date)
distributed by (a)
partition by hash(b,d,e)
partitions 3;
insert into ggg values (1,1,1,date '2001-01-15');
insert into ggg values (2,2,1,date '2001-01-15');
insert into ggg values (1,3,1,date '2001-01-15');
insert into ggg values (2,2,3,date '2001-01-15');
insert into ggg values (1,4,5,date '2001-01-15');
insert into ggg values (2,2,4,date '2001-01-15');
insert into ggg values (1,5,6,date '2001-01-15');
insert into ggg values (2,7,3,date '2001-01-15');
insert into ggg values (1,'a',33,date '2001-01-15');
insert into ggg values (2,'c',44,date '2001-01-15');
select * from ggg;
select * from ggg_1_prt_1;
select * from ggg_1_prt_2;
select * from ggg_1_prt_3;
drop table ggg cascade;
create table mpp_2914A(id int, buyDate date, kind char(1))
DISTRIBUTED BY (id)
partition by list (kind)
subpartition by range(buyDate)
subpartition template
(
start (date '2001-01-01'),
start (date '2002-01-01'),
start (date '2003-01-01'),
start (date '2004-01-01'),
start (date '2005-01-01')
)
(
partition auction values('a','A'),
partition buyItNow values('b', 'B'),
default partition catchall
);
\d mpp_2914a*
select count(*) from mpp_2914A;
create table mpp_2914B(id int, buyDate date, kind char(1))
DISTRIBUTED BY (id)
partition by list (kind)
subpartition by range(buyDate)
(
partition auction values('a','A')
(
subpartition y2001 start (date '2001-01-01'),
subpartition y2002 start (date '2002-01-01'),
subpartition y2003 start (date '2003-01-01'),
subpartition y2004 start (date '2004-01-01'),
subpartition y2005 start (date '2005-01-01')
),
partition buyitnow values('b','B')
(
subpartition y2001 start (date '2001-01-01'),
subpartition y2002 start (date '2002-01-01'),
subpartition y2003 start (date '2003-01-01'),
subpartition y2004 start (date '2004-01-01'),
subpartition y2005 start (date '2005-01-01')
),
default partition catchAll
(
subpartition y2001 start (date '2001-01-01'),
subpartition y2002 start (date '2002-01-01'),
subpartition y2003 start (date '2003-01-01'),
subpartition y2004 start (date '2004-01-01'),
subpartition y2005 start (date '2005-01-01')
)
);
\d mpp_2914b*
select count(*) from mpp_2914B;
drop table mpp_2914a cascade;
drop table mpp_2914b cascade;
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册