diff --git a/src/gausskernel/runtime/opfusion/opfusion_util.cpp b/src/gausskernel/runtime/opfusion/opfusion_util.cpp index 24fa051423bbc5081997ad9d6cee7744d4699697..dad3c7374da0c7e1d54f9ed1879c1dbaf2073f5a 100644 --- a/src/gausskernel/runtime/opfusion/opfusion_util.cpp +++ b/src/gausskernel/runtime/opfusion/opfusion_util.cpp @@ -729,14 +729,36 @@ bool checkPartitionType(const Relation rel) return true; } } + +bool CheckIsRIConstraintTrigger(const TriggerDesc* trigdesc) +{ + if (trigdesc == NULL) { + return true; + } + for (int i = 0; i < trigdesc->numtriggers; i++) { + if (!(trigdesc->triggers[i].tgisinternal && + strncmp(trigdesc->triggers[i].tgname, "RI_ConstraintTrigger", RI_CONSTRAINT_TRIGGER_NAME_LEN) == 0)) { + return false; + } + } + return true; +} + bool checkDMLRelation(const Relation rel, const PlannedStmt *plannedstmt, bool isInsert, bool isPartTbl) { bool result = false; - if (rel->rd_rel->relkind != RELKIND_RELATION || rel->rd_rel->relhasrules || rel->rd_rel->relhastriggers || + if (rel->rd_rel->relkind != RELKIND_RELATION || rel->rd_rel->relhasrules || rel->rd_rel->relhasoids || rel->rd_rel->relhassubclass || RelationIsColStore(rel) || RelationIsTsStore(rel) || RelationInRedistribute(rel) || plannedstmt->hasReturning || RelationIsSubPartitioned(rel)) { result = true; } + if (rel->rd_rel->relhastriggers) { + if (DB_IS_CMPT(B_FORMAT) && !u_sess->attr.attr_common.foreign_key_checks) { + result = !CheckIsRIConstraintTrigger(rel->trigdesc); + } else { + result = true; + } + } if (isInsert) { return result; diff --git a/src/include/opfusion/opfusion_util.h b/src/include/opfusion/opfusion_util.h index 7246dc72048c03a686d28bde4817a4eed413d7a6..64d012e0446b452f9fc3ca9652c5277ad5ecb436 100644 --- a/src/include/opfusion/opfusion_util.h +++ b/src/include/opfusion/opfusion_util.h @@ -271,4 +271,6 @@ void InitPartitionRelationInFusion(Oid partOid, Relation parentRel, Partition *p void ExeceDoneInIndexFusionConstruct(bool isPartTbl, Relation *parentRel, Partition *part, Relation *index, Relation *rel); +#define RI_CONSTRAINT_TRIGGER_NAME_LEN 20 //trigger name must begin with RI_ConstraintTrigger + #endif /* SRC_INCLUDE_OPFUSION_OPFUSION_UTIL_H_ */