提交 62449ea4 编写于 作者: T Taylor Vesely 提交者: David Krieger

Fix altconname related tests

This commit is part of Add Partitioned Indexes #7047.

Constraint names must now match their index. Fix ICW tests where this
assumption no longer holds.
Co-authored-by: NKalen Krempely <kkrempely@pivotal.io>
上级 ac12504d
......@@ -212,7 +212,7 @@ alter table stud_emp rename to pg_toast_stud_emp;
alter table pg_toast_stud_emp rename to stud_emp;
-- renaming index should rename constraint as well
ALTER TABLE onek ADD CONSTRAINT onek_unique1_constraint UNIQUE (unique1);
ALTER INDEX onek_unique1_key RENAME TO onek_unique1_constraint_foo;
ALTER INDEX onek_unique1_constraint RENAME TO onek_unique1_constraint_foo;
ALTER TABLE onek DROP CONSTRAINT onek_unique1_constraint_foo;
-- renaming constraint
ALTER TABLE onek ADD CONSTRAINT onek_check_constraint CHECK (unique1 >= 0);
......@@ -220,8 +220,8 @@ ALTER TABLE onek RENAME CONSTRAINT onek_check_constraint TO onek_check_constrain
ALTER TABLE onek DROP CONSTRAINT onek_check_constraint_foo;
-- renaming constraint should rename index as well
ALTER TABLE onek ADD CONSTRAINT onek_unique1_constraint UNIQUE (unique1);
DROP INDEX onek_unique1_key; -- to see whether it's there
ERROR: cannot drop index onek_unique1_key because constraint onek_unique1_constraint on table onek requires it
DROP INDEX onek_unique1_constraint; -- to see whether it's there
ERROR: cannot drop index onek_unique1_constraint because constraint onek_unique1_constraint on table onek requires it
HINT: You can drop constraint onek_unique1_constraint on table onek instead.
ALTER TABLE onek RENAME CONSTRAINT onek_unique1_constraint TO onek_unique1_constraint_foo;
DROP INDEX onek_unique1_constraint_foo; -- to see whether it's there
......@@ -820,7 +820,7 @@ alter table atacc1 add constraint atacc_test1 unique (test);
insert into atacc1 (test) values (2);
-- should fail
insert into atacc1 (test) values (2);
ERROR: duplicate key value violates unique constraint "atacc1_test_key"
ERROR: duplicate key value violates unique constraint "atacc_test1"
DETAIL: Key (test)=(2) already exists.
-- should succeed
-- In GPDB, we must insert enough values so as to cause duplicates to
......@@ -834,7 +834,7 @@ ERROR: cannot create unique index on system column
-- this errors out in Greenplum for a different reason: we don't support
-- SET DATA TYPE on an indexed column yet
alter table atacc1 alter column test type integer using 0;
ERROR: relation "atacc1_test_key" already exists (seg2 127.0.1.1:25434 pid=8596)
ERROR: relation "atacc_test1" already exists (seg2 127.0.1.1:25434 pid=8596)
drop table atacc1;
-- let's do one where the unique constraint fails when added
create table atacc1 ( test int ) distributed by (test);
......@@ -843,7 +843,7 @@ insert into atacc1 (test) values (2);
insert into atacc1 (test) values (2);
-- add a unique constraint (fails)
alter table atacc1 add constraint atacc_test1 unique (test);
ERROR: could not create unique index "atacc1_test_key"
ERROR: could not create unique index "atacc_test1"
DETAIL: Key (test)=(2) is duplicated.
insert into atacc1 (test) values (3);
drop table atacc1;
......@@ -862,7 +862,7 @@ alter table atacc1 add constraint atacc_test1 unique (test, test2);
insert into atacc1 (test,test2) values (4,4);
-- should fail
insert into atacc1 (test,test2) values (4,4);
ERROR: duplicate key value violates unique constraint "atacc1_test_test2_key"
ERROR: duplicate key value violates unique constraint "atacc_test1"
DETAIL: Key (test, test2)=(4, 4) already exists.
-- should all succeed
insert into atacc1 (test,test2) values (4,5);
......@@ -889,7 +889,7 @@ alter table atacc1 add constraint atacc_test1 primary key (test);
insert into atacc1 (test) values (2);
-- should fail
insert into atacc1 (test) values (2);
ERROR: duplicate key value violates unique constraint "atacc1_pkey"
ERROR: duplicate key value violates unique constraint "atacc_test1"
DETAIL: Key (test)=(2) already exists.
-- should succeed
insert into atacc1 (test) values (4);
......@@ -913,7 +913,7 @@ insert into atacc1 (test) values (2);
insert into atacc1 (test) values (2);
-- add a primary key (fails)
alter table atacc1 add constraint atacc_test1 primary key (test);
ERROR: could not create unique index "atacc1_pkey"
ERROR: could not create unique index "atacc_test1"
DETAIL: Key (test)=(2) is duplicated.
insert into atacc1 (test) values (3);
drop table atacc1;
......@@ -955,7 +955,7 @@ ERROR: multiple primary keys for table "atacc1" are not allowed
insert into atacc1 (test,test2) values (4,4);
-- should fail
insert into atacc1 (test,test2) values (4,4);
ERROR: duplicate key value violates unique constraint "atacc1_pkey"
ERROR: duplicate key value violates unique constraint "atacc_test1"
DETAIL: Key (test, test2)=(4, 4) already exists.
insert into atacc1 (test,test2) values (NULL,3);
ERROR: null value in column "test" violates not-null constraint
......@@ -2873,7 +2873,7 @@ ALTER TABLE IF EXISTS tt8 SET SCHEMA alter2;
a | integer |
f1 | integer | not null default 0
Indexes:
"tt8_pkey" PRIMARY KEY, btree (f1)
"xxx" PRIMARY KEY, btree (f1)
Check constraints:
"tt8_f_check" CHECK (f1 >= 0 AND f1 <= 10)
Distributed by: (f1)
......
set optimizer_enable_master_only_queries = on;
--
-- Catalog Changes for function properties (original error when optimizer set to on: could not find tuple for constraint 88611)
--
select
tableid,
tableconname,
contype,
condef,
numexpected,
numactual
from
(
select
c.tableid,
c.tableconname,
c.contype,
c.condef,
i.tableparts + 1,
count(c.partid),
count(distinct c.partconname)
from
(
select
u.tableid,
u.conname,
u.contype,
u.condef,
p.partid,
p.conid,
coalesce(p.conname)
from
(
select
p.tableid,
c.conname,
c.contype,
pg_get_constraintdef(c.oid) as condef
from
(
select
parrelid::regclass,
max(parlevel)+1
from
pg_partition
group by parrelid
) as p(tableid, tabledepth) ,
pg_constraint c
where
p.tableid = c.conrelid
) as u(tableid, conname, contype, condef)
join
(
select
x.tableid::regclass as tableid,
c.conrelid::regclass as partid,
c.oid as conid,
c.conname,
c.contype,
pg_get_constraintdef(c.oid) as condef
from
pg_constraint c,
(
select
tableid,
tabledepth,
tableid::regclass partid,
0 as partdepth,
0 as partordinal,
'r'::char as partstatus
from
(
select
parrelid::regclass,
max(parlevel)+1
from
pg_partition
group by parrelid
) as ptable(tableid, tabledepth)
union all
select
parrelid::regclass as tableid,
t.tabledepth as tabledepth,
r.parchildrelid::regclass partid,
p.parlevel + 1 as partdepth,
r.parruleord as partordinal,
case
when t.tabledepth = p.parlevel + 1 then 'l'::char
else 'i'::char
end as partstatus
from
pg_partition p,
pg_partition_rule r,
(
select
parrelid::regclass,
max(parlevel)+1
from
pg_partition
group by parrelid
) as t(tableid, tabledepth)
where
p.oid = r.paroid
and not p.paristemplate
and p.parrelid = t.tableid
) as x(tableid, tabledepth, partid, partdepth, partordinal, partstatus)
where
x.partid = c.conrelid
) as p(tableid, partid, conid, conname, contype, condef)
on (
u.tableid = p.tableid and
u.contype = p.contype and
u.condef = p.condef
)
) as c(tableid, tableconname, contype, condef, partid, partconid, partconname) ,
(
select
t.tableid,
t.tabledepth,
n.nparts as tableparts,
r.nspname,
r.relname
from
(
select
parrelid::regclass,
max(parlevel)+1
from
pg_partition
group by parrelid
) as t(tableid, tabledepth) ,
(
select
c.oid::regclass as relid,
n.nspname,
c.relname,
c.relkind
from
pg_class c,
pg_namespace n
where
c.relnamespace = n.oid
) as r(relid, nspname, relname, relkind) ,
(
select tableid, count(*)
from (
select
t.tableid::regclass,
p.parchildrelid::regclass as partid
from
(
select pg_partition.parrelid, pg_partition.oid
from pg_partition
where not pg_partition.paristemplate
) t(tableid, partid),
pg_partition_rule p
where p.paroid = t.partid
) as contains_part(tableid, partid)
group by tableid
) n(tableid, nparts)
where
t.tableid = r.relid and
t.tableid = n.tableid
) as i(tableid, tabledepth, tableparts, nspname, relname)
where
c.tableid = i.tableid
group by
c.tableid,
c.tableconname,
c.contype,
c.condef,
i.tableparts
) as ptable_user_con_info(tableid, tableconname, contype, condef, numexpected, numactual, numnames)
where
contype != 'f' and -- no FK consistency in Rio
numexpected != numactual;
tableid | tableconname | contype | condef | numexpected | numactual
---------+--------------+---------+--------+-------------+-----------
(0 rows)
--
--
--
select count(*)/1000 from
(select
(select ressetting from pg_resqueue_attributes b
......
--MPP-22020: Dis-allow duplicate constraint names for the same table.
create table dupconstr (
i int,
j int constraint test CHECK (j > 10),
CONSTRAINT test UNIQUE (i,j))
j int constraint same_name CHECK (j > 10),
CONSTRAINT same_name UNIQUE (i,j))
distributed by (i);
ERROR: constraint "test" for relation "dupconstr" already exists
ERROR: constraint "same_name" for relation "dupconstr" already exists
-- MPP-2764: distributed randomly is not compatible with primary key or unique
-- constraints
create table distrand(i int, j int, primary key (i)) distributed randomly;
......@@ -18,13 +18,13 @@ ERROR: UNIQUE and DISTRIBUTED RANDOMLY are incompatible
create table distrand(i int, j int, constraint "test" primary key (i))
distributed randomly;
ERROR: PRIMARY KEY and DISTRIBUTED RANDOMLY are incompatible
create table distrand(i int, j int, constraint "test" unique (i))
create table distrand(i int, j int, constraint "distrand_unique" unique (i))
distributed randomly;
ERROR: UNIQUE and DISTRIBUTED RANDOMLY are incompatible
-- this should work though
create table distrand(i int, j int, constraint "test" unique (i, j))
create table notdistrand(i int, j int, constraint "notdistrand_unique" unique (i, j))
distributed by(i, j);
drop table distrand;
drop table notdistrand;
create table distrand(i int, j int) distributed randomly;
create unique index distrand_idx on distrand(i);
ERROR: UNIQUE and DISTRIBUTED RANDOMLY are incompatible
......
......@@ -4238,7 +4238,7 @@ alter table it add constraint it_unique_i unique (i);
select schemaname, tablename, indexname from pg_indexes where schemaname = 'public' and tablename like 'it%';
schemaname | tablename | indexname
------------+------------+------------------
public | it | it_i_key
public | it | it_unique_i
public | it_1_prt_1 | it_1_prt_1_i_key
public | it_1_prt_2 | it_1_prt_2_i_key
(3 rows)
......@@ -8164,18 +8164,19 @@ select gp_segment_id, relname from gp_dist_random('pg_class') where relkind = 'r
alter table sales drop column tax;
create table newpart(like sales);
alter table newpart add constraint partable_pkey primary key(pkid, option3);
NOTICE: table doesn't have 'DISTRIBUTED BY' clause, defaulting to distribution columns from LIKE table
alter table newpart add constraint newpart_pkey primary key(pkid, option3);
alter table sales split partition for(1) at (50) into (partition aa1, partition aa2);
NOTICE: dropped partition "aa" for relation "sales"
select table_schema, table_name, constraint_name, constraint_type
from information_schema.table_constraints
where table_name in ('sales', 'newpart')
and constraint_name = 'partable_pkey'
and constraint_name in ('partable_pkey', 'newpart_pkey')
order by table_name desc;
table_schema | table_name | constraint_name | constraint_type
--------------+------------+-----------------+-----------------
public | newpart | partable_pkey | PRIMARY KEY
public | sales | partable_pkey | PRIMARY KEY
public | newpart | newpart_pkey | PRIMARY KEY
(2 rows)
alter table sales exchange partition for (101) with table newpart;
......
......@@ -4241,7 +4241,7 @@ alter table it add constraint it_unique_i unique (i);
select schemaname, tablename, indexname from pg_indexes where schemaname = 'public' and tablename like 'it%';
schemaname | tablename | indexname
------------+------------+------------------
public | it | it_i_key
public | it | it_unique_i
public | it_1_prt_1 | it_1_prt_1_i_key
public | it_1_prt_2 | it_1_prt_2_i_key
(3 rows)
......@@ -8162,18 +8162,18 @@ select gp_segment_id, relname from gp_dist_random('pg_class') where relkind = 'r
alter table sales drop column tax;
create table newpart(like sales);
alter table newpart add constraint partable_pkey primary key(pkid, option3);
alter table newpart add constraint newpart_pkey primary key(pkid, option3);
alter table sales split partition for(1) at (50) into (partition aa1, partition aa2);
NOTICE: dropped partition "aa" for relation "sales"
select table_schema, table_name, constraint_name, constraint_type
from information_schema.table_constraints
where table_name in ('sales', 'newpart')
and constraint_name = 'partable_pkey'
and constraint_name in ('partable_pkey', 'newpart_pkey')
order by table_name desc;
table_schema | table_name | constraint_name | constraint_type
--------------+------------+-----------------+-----------------
public | newpart | partable_pkey | PRIMARY KEY
public | sales | partable_pkey | PRIMARY KEY
public | newpart | newpart_pkey | PRIMARY KEY
(2 rows)
alter table sales exchange partition for (101) with table newpart;
......
......@@ -662,18 +662,18 @@ CREATE TABLE deferred_excl (
INSERT INTO deferred_excl VALUES(1);
INSERT INTO deferred_excl VALUES(2);
INSERT INTO deferred_excl VALUES(1); -- fail
ERROR: conflicting key value violates exclusion constraint "deferred_excl_f1_excl"
ERROR: conflicting key value violates exclusion constraint "deferred_excl_con"
DETAIL: Key (f1)=(1) conflicts with existing key (f1)=(1).
BEGIN;
INSERT INTO deferred_excl VALUES(2); -- no fail here
COMMIT; -- should fail here
ERROR: conflicting key value violates exclusion constraint "deferred_excl_f1_excl"
ERROR: conflicting key value violates exclusion constraint "deferred_excl_con"
DETAIL: Key (f1)=(2) conflicts with existing key (f1)=(2).
BEGIN;
INSERT INTO deferred_excl VALUES(3);
INSERT INTO deferred_excl VALUES(3); -- no fail here
COMMIT; -- should fail here
ERROR: conflicting key value violates exclusion constraint "deferred_excl_f1_excl"
ERROR: conflicting key value violates exclusion constraint "deferred_excl_con"
DETAIL: Key (f1)=(3) conflicts with existing key (f1)=(3).
-- bug #13148: deferred constraint versus HOT update
BEGIN;
......
......@@ -213,7 +213,7 @@ alter table pg_toast_stud_emp rename to stud_emp;
-- renaming index should rename constraint as well
ALTER TABLE onek ADD CONSTRAINT onek_unique1_constraint UNIQUE (unique1);
ALTER INDEX onek_unique1_key RENAME TO onek_unique1_constraint_foo;
ALTER INDEX onek_unique1_constraint RENAME TO onek_unique1_constraint_foo;
ALTER TABLE onek DROP CONSTRAINT onek_unique1_constraint_foo;
-- renaming constraint
......@@ -223,7 +223,7 @@ ALTER TABLE onek DROP CONSTRAINT onek_check_constraint_foo;
-- renaming constraint should rename index as well
ALTER TABLE onek ADD CONSTRAINT onek_unique1_constraint UNIQUE (unique1);
DROP INDEX onek_unique1_key; -- to see whether it's there
DROP INDEX onek_unique1_constraint; -- to see whether it's there
ALTER TABLE onek RENAME CONSTRAINT onek_unique1_constraint TO onek_unique1_constraint_foo;
DROP INDEX onek_unique1_constraint_foo; -- to see whether it's there
ALTER TABLE onek DROP CONSTRAINT onek_unique1_constraint_foo;
......
set optimizer_enable_master_only_queries = on;
--
-- Catalog Changes for function properties (original error when optimizer set to on: could not find tuple for constraint 88611)
--
select
tableid,
tableconname,
contype,
condef,
numexpected,
numactual
from
(
select
c.tableid,
c.tableconname,
c.contype,
c.condef,
i.tableparts + 1,
count(c.partid),
count(distinct c.partconname)
from
(
select
u.tableid,
u.conname,
u.contype,
u.condef,
p.partid,
p.conid,
coalesce(p.conname)
from
(
select
p.tableid,
c.conname,
c.contype,
pg_get_constraintdef(c.oid) as condef
from
(
select
parrelid::regclass,
max(parlevel)+1
from
pg_partition
group by parrelid
) as p(tableid, tabledepth) ,
pg_constraint c
where
p.tableid = c.conrelid
) as u(tableid, conname, contype, condef)
join
(
select
x.tableid::regclass as tableid,
c.conrelid::regclass as partid,
c.oid as conid,
c.conname,
c.contype,
pg_get_constraintdef(c.oid) as condef
from
pg_constraint c,
(
select
tableid,
tabledepth,
tableid::regclass partid,
0 as partdepth,
0 as partordinal,
'r'::char as partstatus
from
(
select
parrelid::regclass,
max(parlevel)+1
from
pg_partition
group by parrelid
) as ptable(tableid, tabledepth)
union all
select
parrelid::regclass as tableid,
t.tabledepth as tabledepth,
r.parchildrelid::regclass partid,
p.parlevel + 1 as partdepth,
r.parruleord as partordinal,
case
when t.tabledepth = p.parlevel + 1 then 'l'::char
else 'i'::char
end as partstatus
from
pg_partition p,
pg_partition_rule r,
(
select
parrelid::regclass,
max(parlevel)+1
from
pg_partition
group by parrelid
) as t(tableid, tabledepth)
where
p.oid = r.paroid
and not p.paristemplate
and p.parrelid = t.tableid
) as x(tableid, tabledepth, partid, partdepth, partordinal, partstatus)
where
x.partid = c.conrelid
) as p(tableid, partid, conid, conname, contype, condef)
on (
u.tableid = p.tableid and
u.contype = p.contype and
u.condef = p.condef
)
) as c(tableid, tableconname, contype, condef, partid, partconid, partconname) ,
(
select
t.tableid,
t.tabledepth,
n.nparts as tableparts,
r.nspname,
r.relname
from
(
select
parrelid::regclass,
max(parlevel)+1
from
pg_partition
group by parrelid
) as t(tableid, tabledepth) ,
(
select
c.oid::regclass as relid,
n.nspname,
c.relname,
c.relkind
from
pg_class c,
pg_namespace n
where
c.relnamespace = n.oid
) as r(relid, nspname, relname, relkind) ,
(
select tableid, count(*)
from (
select
t.tableid::regclass,
p.parchildrelid::regclass as partid
from
(
select pg_partition.parrelid, pg_partition.oid
from pg_partition
where not pg_partition.paristemplate
) t(tableid, partid),
pg_partition_rule p
where p.paroid = t.partid
) as contains_part(tableid, partid)
group by tableid
) n(tableid, nparts)
where
t.tableid = r.relid and
t.tableid = n.tableid
) as i(tableid, tabledepth, tableparts, nspname, relname)
where
c.tableid = i.tableid
group by
c.tableid,
c.tableconname,
c.contype,
c.condef,
i.tableparts
) as ptable_user_con_info(tableid, tableconname, contype, condef, numexpected, numactual, numnames)
where
contype != 'f' and -- no FK consistency in Rio
numexpected != numactual;
--
--
--
select count(*)/1000 from
(select
(select ressetting from pg_resqueue_attributes b
......
......@@ -2,8 +2,8 @@
--MPP-22020: Dis-allow duplicate constraint names for the same table.
create table dupconstr (
i int,
j int constraint test CHECK (j > 10),
CONSTRAINT test UNIQUE (i,j))
j int constraint same_name CHECK (j > 10),
CONSTRAINT same_name UNIQUE (i,j))
distributed by (i);
-- MPP-2764: distributed randomly is not compatible with primary key or unique
......@@ -14,12 +14,12 @@ create table distrand(i int, j int, primary key (i, j)) distributed randomly;
create table distrand(i int, j int, unique (i, j)) distributed randomly;
create table distrand(i int, j int, constraint "test" primary key (i))
distributed randomly;
create table distrand(i int, j int, constraint "test" unique (i))
create table distrand(i int, j int, constraint "distrand_unique" unique (i))
distributed randomly;
-- this should work though
create table distrand(i int, j int, constraint "test" unique (i, j))
create table notdistrand(i int, j int, constraint "notdistrand_unique" unique (i, j))
distributed by(i, j);
drop table distrand;
drop table notdistrand;
create table distrand(i int, j int) distributed randomly;
create unique index distrand_idx on distrand(i);
drop table distrand;
......
......@@ -3902,13 +3902,13 @@ select gp_segment_id, relname from gp_dist_random('pg_class') where relkind = 'r
alter table sales drop column tax;
create table newpart(like sales);
alter table newpart add constraint partable_pkey primary key(pkid, option3);
alter table newpart add constraint newpart_pkey primary key(pkid, option3);
alter table sales split partition for(1) at (50) into (partition aa1, partition aa2);
select table_schema, table_name, constraint_name, constraint_type
from information_schema.table_constraints
where table_name in ('sales', 'newpart')
and constraint_name = 'partable_pkey'
and constraint_name in ('partable_pkey', 'newpart_pkey')
order by table_name desc;
alter table sales exchange partition for (101) with table newpart;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册