未验证 提交 b50c134b 编写于 作者: W Weinan WANG 提交者: GitHub

Skip FK check when do relation truncate

GPDB does not support FK, but keep FK grammar in DDL, since it
reduce DB migration manual workload from others.
Hence, we do not need FK check for truncate command, rid of it.
上级 f3c05b2b
...@@ -3305,8 +3305,15 @@ heap_truncate(List *relids) ...@@ -3305,8 +3305,15 @@ heap_truncate(List *relids)
} }
} }
/* GPDB does not support all FK feature but keeps FK grammar recognition,
* which reduces migration manual workload from other databases.
* We do not want to reject relation truncate if the relation contains FK
* satisfied tuple, so skip heap_truncate_check_FKs function call.
*/
#if 0
/* Don't allow truncate on tables that are referenced by foreign keys */ /* Don't allow truncate on tables that are referenced by foreign keys */
heap_truncate_check_FKs(relations, true); heap_truncate_check_FKs(relations, true);
#endif
/* OK to do it */ /* OK to do it */
foreach(cell, relations) foreach(cell, relations)
......
...@@ -1218,6 +1218,12 @@ ExecuteTruncate(TruncateStmt *stmt) ...@@ -1218,6 +1218,12 @@ ExecuteTruncate(TruncateStmt *stmt)
} }
} }
/* GPDB does not support all FK feature but keeps FK grammar recognition,
* which reduces migration manual workload from other databases.
* We do not want to reject relation truncate if the relation contains FK
* satisfied tuple, so skip heap_truncate_check_FKs function call.
*/
#if 0
/* /*
* Check foreign key references. In CASCADE mode, this should be * Check foreign key references. In CASCADE mode, this should be
* unnecessary since we just pulled in all the references; but as a * unnecessary since we just pulled in all the references; but as a
...@@ -1228,6 +1234,7 @@ ExecuteTruncate(TruncateStmt *stmt) ...@@ -1228,6 +1234,7 @@ ExecuteTruncate(TruncateStmt *stmt)
#else #else
if (truncateStatement->behavior == DROP_RESTRICT) if (truncateStatement->behavior == DROP_RESTRICT)
heap_truncate_check_FKs(rels, false); heap_truncate_check_FKs(rels, false);
#endif
#endif #endif
/* /*
......
...@@ -165,8 +165,6 @@ NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "temptest3_pkey" ...@@ -165,8 +165,6 @@ NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "temptest3_pkey"
CREATE TEMP TABLE temptest4(col int REFERENCES temptest3); CREATE TEMP TABLE temptest4(col int REFERENCES temptest3);
WARNING: Referential integrity (FOREIGN KEY) constraints are not supported in Greenplum Database, will not be enforced. WARNING: Referential integrity (FOREIGN KEY) constraints are not supported in Greenplum Database, will not be enforced.
COMMIT; COMMIT;
ERROR: unsupported ON COMMIT and foreign key combination
DETAIL: Table "temptest4" references "temptest3", but they do not have the same ON COMMIT setting.
-- Test manipulation of temp schema's placement in search path -- Test manipulation of temp schema's placement in search path
create table public.whereami (f1 text); create table public.whereami (f1 text);
insert into public.whereami values ('public'); insert into public.whereami values ('public');
......
...@@ -48,36 +48,15 @@ HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sur ...@@ -48,36 +48,15 @@ HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sur
WARNING: Referential integrity (FOREIGN KEY) constraints are not supported in Greenplum Database, will not be enforced. WARNING: Referential integrity (FOREIGN KEY) constraints are not supported in Greenplum Database, will not be enforced.
WARNING: Referential integrity (FOREIGN KEY) constraints are not supported in Greenplum Database, will not be enforced. WARNING: Referential integrity (FOREIGN KEY) constraints are not supported in Greenplum Database, will not be enforced.
TRUNCATE TABLE truncate_a; -- fail TRUNCATE TABLE truncate_a; -- fail
ERROR: cannot truncate a table referenced in a foreign key constraint
DETAIL: Table "trunc_b" references "truncate_a".
HINT: Truncate table "trunc_b" at the same time, or use TRUNCATE ... CASCADE.
TRUNCATE TABLE truncate_a,trunc_b; -- fail TRUNCATE TABLE truncate_a,trunc_b; -- fail
ERROR: cannot truncate a table referenced in a foreign key constraint
DETAIL: Table "trunc_e" references "truncate_a".
HINT: Truncate table "trunc_e" at the same time, or use TRUNCATE ... CASCADE.
TRUNCATE TABLE truncate_a,trunc_b,trunc_e; -- ok TRUNCATE TABLE truncate_a,trunc_b,trunc_e; -- ok
TRUNCATE TABLE truncate_a,trunc_e; -- fail TRUNCATE TABLE truncate_a,trunc_e; -- fail
ERROR: cannot truncate a table referenced in a foreign key constraint
DETAIL: Table "trunc_b" references "truncate_a".
HINT: Truncate table "trunc_b" at the same time, or use TRUNCATE ... CASCADE.
TRUNCATE TABLE trunc_c; -- fail TRUNCATE TABLE trunc_c; -- fail
ERROR: cannot truncate a table referenced in a foreign key constraint
DETAIL: Table "trunc_d" references "trunc_c".
HINT: Truncate table "trunc_d" at the same time, or use TRUNCATE ... CASCADE.
TRUNCATE TABLE trunc_c,trunc_d; -- fail TRUNCATE TABLE trunc_c,trunc_d; -- fail
ERROR: cannot truncate a table referenced in a foreign key constraint
DETAIL: Table "trunc_e" references "trunc_c".
HINT: Truncate table "trunc_e" at the same time, or use TRUNCATE ... CASCADE.
TRUNCATE TABLE trunc_c,trunc_d,trunc_e; -- ok TRUNCATE TABLE trunc_c,trunc_d,trunc_e; -- ok
TRUNCATE TABLE trunc_c,trunc_d,trunc_e,truncate_a; -- fail TRUNCATE TABLE trunc_c,trunc_d,trunc_e,truncate_a; -- fail
ERROR: cannot truncate a table referenced in a foreign key constraint
DETAIL: Table "trunc_b" references "truncate_a".
HINT: Truncate table "trunc_b" at the same time, or use TRUNCATE ... CASCADE.
TRUNCATE TABLE trunc_c,trunc_d,trunc_e,truncate_a,trunc_b; -- ok TRUNCATE TABLE trunc_c,trunc_d,trunc_e,truncate_a,trunc_b; -- ok
TRUNCATE TABLE truncate_a RESTRICT; -- fail TRUNCATE TABLE truncate_a RESTRICT; -- fail
ERROR: cannot truncate a table referenced in a foreign key constraint
DETAIL: Table "trunc_b" references "truncate_a".
HINT: Truncate table "trunc_b" at the same time, or use TRUNCATE ... CASCADE.
TRUNCATE TABLE truncate_a CASCADE; -- ok TRUNCATE TABLE truncate_a CASCADE; -- ok
NOTICE: truncate cascades to table "trunc_b" NOTICE: truncate cascades to table "trunc_b"
NOTICE: truncate cascades to table "trunc_e" NOTICE: truncate cascades to table "trunc_e"
...@@ -91,21 +70,9 @@ INSERT INTO trunc_b VALUES (1); ...@@ -91,21 +70,9 @@ INSERT INTO trunc_b VALUES (1);
INSERT INTO trunc_d VALUES (1); INSERT INTO trunc_d VALUES (1);
INSERT INTO trunc_e VALUES (1,1); INSERT INTO trunc_e VALUES (1,1);
TRUNCATE TABLE trunc_c; TRUNCATE TABLE trunc_c;
ERROR: cannot truncate a table referenced in a foreign key constraint
DETAIL: Table "truncate_a" references "trunc_c".
HINT: Truncate table "truncate_a" at the same time, or use TRUNCATE ... CASCADE.
TRUNCATE TABLE trunc_c,truncate_a; TRUNCATE TABLE trunc_c,truncate_a;
ERROR: cannot truncate a table referenced in a foreign key constraint
DETAIL: Table "trunc_d" references "trunc_c".
HINT: Truncate table "trunc_d" at the same time, or use TRUNCATE ... CASCADE.
TRUNCATE TABLE trunc_c,truncate_a,trunc_d; TRUNCATE TABLE trunc_c,truncate_a,trunc_d;
ERROR: cannot truncate a table referenced in a foreign key constraint
DETAIL: Table "trunc_e" references "trunc_c".
HINT: Truncate table "trunc_e" at the same time, or use TRUNCATE ... CASCADE.
TRUNCATE TABLE trunc_c,truncate_a,trunc_d,trunc_e; TRUNCATE TABLE trunc_c,truncate_a,trunc_d,trunc_e;
ERROR: cannot truncate a table referenced in a foreign key constraint
DETAIL: Table "trunc_b" references "truncate_a".
HINT: Truncate table "trunc_b" at the same time, or use TRUNCATE ... CASCADE.
TRUNCATE TABLE trunc_c,truncate_a,trunc_d,trunc_e,trunc_b; TRUNCATE TABLE trunc_c,truncate_a,trunc_d,trunc_e,trunc_b;
-- Verify that truncating did actually work -- Verify that truncating did actually work
SELECT * FROM truncate_a SELECT * FROM truncate_a
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册