diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 848e30b402e7c6fc4014bf549f510ef1aadcc82c..d5c82becc3943d7ee31fb1a6b3cd3a1afe1de8b7 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -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 */ heap_truncate_check_FKs(relations, true); +#endif /* OK to do it */ foreach(cell, relations) diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 0c453a698bbec698cfd8ce2b5753a1a24520dabb..c4604ee6a20cbe929f65dbe75b9391250a7517c6 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -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 * unnecessary since we just pulled in all the references; but as a @@ -1228,6 +1234,7 @@ ExecuteTruncate(TruncateStmt *stmt) #else if (truncateStatement->behavior == DROP_RESTRICT) heap_truncate_check_FKs(rels, false); +#endif #endif /* diff --git a/src/test/regress/expected/temp.out b/src/test/regress/expected/temp.out index 1e35cb4b11ffde4256fa218973883b2d33a4e123..00a80904657b99672171e910edd93233133706ef 100755 --- a/src/test/regress/expected/temp.out +++ b/src/test/regress/expected/temp.out @@ -165,8 +165,6 @@ NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "temptest3_pkey" CREATE TEMP TABLE temptest4(col int REFERENCES temptest3); WARNING: Referential integrity (FOREIGN KEY) constraints are not supported in Greenplum Database, will not be enforced. 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 create table public.whereami (f1 text); insert into public.whereami values ('public'); diff --git a/src/test/regress/expected/truncate.out b/src/test/regress/expected/truncate.out index 718a7c263dc802c982c69113b88c6b70838b679e..805e254f6491eb18b87e2d5bf90335183f4c704b 100755 --- a/src/test/regress/expected/truncate.out +++ b/src/test/regress/expected/truncate.out @@ -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. 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 -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_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 -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 -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,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 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 NOTICE: truncate cascades to table "trunc_b" NOTICE: truncate cascades to table "trunc_e" @@ -91,21 +70,9 @@ INSERT INTO trunc_b VALUES (1); INSERT INTO trunc_d VALUES (1); INSERT INTO trunc_e VALUES (1,1); 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; -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; -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; -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; -- Verify that truncating did actually work SELECT * FROM truncate_a