This is an automated email from the ASF dual-hosted git repository.

yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git

commit 30d1950a93d17a0d8f60fb95ecc7328cf11ef828
Author: Huansong Fu <[email protected]>
AuthorDate: Tue Nov 28 15:25:19 2023 -0800

    Do not throw error for INSERT into a table w/ foreign key constraint
    
    Foreign key constraint is not supported in GPDB. However, the expected 
behavior
    is that we should ignore the constraint and there shouldn't be errors.
    
    But before this commit we would encounter an ERROR when performing INSERT 
on an
    AOCO table that has foreign key constraint:
    
    CREATE TABLE a(id int primary key);
    CREATE TABLE b(id int references a) WITH (appendonly=true, 
orientation=column);
    WARNING:  referential integrity (FOREIGN KEY) constraints are not supported 
in Greenplum Database, will not be enforced
    
    INSERT INTO b VALUES (1);
    ERROR:  Trigger is not supported on AOCS yet (trigger.c:2714)  (seg4 
#######:16004 pid=3948271) (trigger.c:2714)
    
    The error message, which was for the purpose of disabling row trigger for 
AO/CO
    tables, got in the way of ignoring foreign key constraint. Further 
investigation
    in the code history reveals that the error message was an outdated one 
which is
    no longer needed due to other errors that disable row trigger for AO/CO 
tables.
    Delete the error message now and add test cases.
    
    Fix #16770.
---
 src/backend/commands/trigger.c               |  3 ---
 src/test/regress/expected/foreign_key_gp.out | 12 ++++++++++++
 src/test/regress/expected/triggers_gp.out    | 11 +++++++++++
 src/test/regress/greenplum_schedule          |  1 +
 src/test/regress/parallel_schedule           |  1 +
 src/test/regress/sql/foreign_key_gp.sql      | 13 +++++++++++++
 src/test/regress/sql/triggers_gp.sql         |  9 +++++++++
 7 files changed, 47 insertions(+), 3 deletions(-)

diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c
index 2ba6c066ca..8c9e3cdef9 100644
--- a/src/backend/commands/trigger.c
+++ b/src/backend/commands/trigger.c
@@ -2417,9 +2417,6 @@ ExecARInsertTriggers(EState *estate, ResultRelInfo 
*relinfo,
        if ((trigdesc && trigdesc->trig_insert_after_row) ||
                (transition_capture && 
transition_capture->tcs_insert_new_table))
        {
-               if(RelationIsAoCols(relinfo->ri_RelationDesc))
-                       elog(ERROR, "Trigger is not supported on AOCS yet");
-
                AfterTriggerSaveEvent(estate, relinfo, TRIGGER_EVENT_INSERT,
                                                          true, NULL, slot,
                                                          recheckIndexes, NULL,
diff --git a/src/test/regress/expected/foreign_key_gp.out 
b/src/test/regress/expected/foreign_key_gp.out
new file mode 100644
index 0000000000..71b6ac2d08
--- /dev/null
+++ b/src/test/regress/expected/foreign_key_gp.out
@@ -0,0 +1,12 @@
+--
+-- GPDB currently does not support foreign key constraints: table can be 
created
+-- with the constraints, but they won't be enforced. Tables operations will 
ignore
+-- the constraints. We should not see errors.
+--
+CREATE TABLE fk_ref(id int primary key);
+CREATE TABLE fk_heap(id int references fk_ref);
+CREATE TABLE fk_ao(id int references fk_ref) USING ao_row;
+CREATE TABLE fk_co(id int references fk_ref) USING ao_column;
+INSERT INTO fk_heap VALUES (1);
+INSERT INTO fk_ao VALUES (1);
+INSERT INTO fk_co VALUES (1);
diff --git a/src/test/regress/expected/triggers_gp.out 
b/src/test/regress/expected/triggers_gp.out
index 3191971aee..5899327ea3 100644
--- a/src/test/regress/expected/triggers_gp.out
+++ b/src/test/regress/expected/triggers_gp.out
@@ -124,3 +124,14 @@ END;';
 CREATE TRIGGER before_ins_stmt_trig_gp BEFORE INSERT ON main_table_gp
 FOR EACH STATEMENT EXECUTE PROCEDURE trigger_func_gp('before_ins_stmt');
 SET gp_enable_statement_trigger = off;
+-- Triggers on AO/CO table.
+-- Currently disabled.
+--
+create table trigtest_ao(a int) using ao_row;
+create table trigtest_co(a int) using ao_column;
+create trigger trig_ao after insert on trigtest_ao for each row execute 
function insert_notice_trig();
+create trigger trig_co after insert on trigtest_co for each row execute 
function insert_notice_trig();
+insert into trigtest_ao values(1);
+ERROR:  feature not supported on appendoptimized relations
+insert into trigtest_co values(1);
+ERROR:  feature not supported on appendoptimized relations
diff --git a/src/test/regress/greenplum_schedule 
b/src/test/regress/greenplum_schedule
index a4dad75ab8..d177705d7c 100755
--- a/src/test/regress/greenplum_schedule
+++ b/src/test/regress/greenplum_schedule
@@ -38,6 +38,7 @@ test: instr_in_shmem
 
 test: createdb
 test: gp_aggregates gp_aggregates_costs gp_metadata variadic_parameters 
default_parameters function_extensions spi gp_xml shared_scan update_gp 
triggers_gp returning_gp resource_queue_with_rule gp_types gp_index cluster_gp 
combocid_gp gp_sort gp_prepared_xacts gp_backend_info
+test: foreign_key_gp
 test: spi_processed64bit
 test: gp_tablespace_with_faults
 # below test(s) inject faults so each of them need to be in a separate group
diff --git a/src/test/regress/parallel_schedule 
b/src/test/regress/parallel_schedule
index 7fd9bea920..97274fdf8b 100644
--- a/src/test/regress/parallel_schedule
+++ b/src/test/regress/parallel_schedule
@@ -145,6 +145,7 @@ test: select_views portals_p2 cluster dependency guc 
bitmapops combocid tsearch
 
 # 'foreign_key' test is disabled, because it contains several tables with
 # multiple UNIQUE constraints, which is not supported in GPDB.
+# See the foreign_key_gp test in greenplum_schedule for the GPDB-specific 
behavior.
 #test: foreign_key
 
 # ----------
diff --git a/src/test/regress/sql/foreign_key_gp.sql 
b/src/test/regress/sql/foreign_key_gp.sql
new file mode 100644
index 0000000000..574455aa31
--- /dev/null
+++ b/src/test/regress/sql/foreign_key_gp.sql
@@ -0,0 +1,13 @@
+--
+-- GPDB currently does not support foreign key constraints: table can be 
created
+-- with the constraints, but they won't be enforced. Tables operations will 
ignore
+-- the constraints. We should not see errors.
+--
+CREATE TABLE fk_ref(id int primary key);
+CREATE TABLE fk_heap(id int references fk_ref);
+CREATE TABLE fk_ao(id int references fk_ref) USING ao_row;
+CREATE TABLE fk_co(id int references fk_ref) USING ao_column;
+INSERT INTO fk_heap VALUES (1);
+INSERT INTO fk_ao VALUES (1);
+INSERT INTO fk_co VALUES (1);
+
diff --git a/src/test/regress/sql/triggers_gp.sql 
b/src/test/regress/sql/triggers_gp.sql
index 72c50858ca..f9761e632f 100644
--- a/src/test/regress/sql/triggers_gp.sql
+++ b/src/test/regress/sql/triggers_gp.sql
@@ -127,3 +127,12 @@ CREATE TRIGGER before_ins_stmt_trig_gp BEFORE INSERT ON 
main_table_gp
 FOR EACH STATEMENT EXECUTE PROCEDURE trigger_func_gp('before_ins_stmt');
 
 SET gp_enable_statement_trigger = off;
+-- Triggers on AO/CO table.
+-- Currently disabled.
+--
+create table trigtest_ao(a int) using ao_row;
+create table trigtest_co(a int) using ao_column;
+create trigger trig_ao after insert on trigtest_ao for each row execute 
function insert_notice_trig();
+create trigger trig_co after insert on trigtest_co for each row execute 
function insert_notice_trig();
+insert into trigtest_ao values(1);
+insert into trigtest_co values(1);


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to