diff --git a/src/common/backend/utils/adt/ruleutils.cpp b/src/common/backend/utils/adt/ruleutils.cpp index 13f59e100..e7855768c 100644 --- a/src/common/backend/utils/adt/ruleutils.cpp +++ b/src/common/backend/utils/adt/ruleutils.cpp @@ -1664,10 +1664,10 @@ static int get_table_attribute( isDefault = true; } Datum onUpdateExpr = fastgetattr(tup, Anum_pg_attrdef_adsrc_on_update, attrdefDesc->rd_att, &isnull); - if (onUpdateExpr && pg_strcasecmp(TextDatumGetCString(onUpdateExpr), "") == 0) { - isOnUpdate = false; - } else { + if (onUpdateExpr && pg_strcasecmp(TextDatumGetCString(onUpdateExpr), "") != 0) { isOnUpdate = true; + } else { + isOnUpdate = false; } if (attrdef->adnum == att_tup->attnum) { diff --git a/src/common/backend/utils/cache/relcache.cpp b/src/common/backend/utils/cache/relcache.cpp index a473457cb..a202f72c6 100644 --- a/src/common/backend/utils/cache/relcache.cpp +++ b/src/common/backend/utils/cache/relcache.cpp @@ -5665,10 +5665,10 @@ static void UpdatedColFetch(TupleConstr *constr, HeapTuple htup, Relation adrel, bool isnull = false; Datum val; val = fastgetattr(htup, Anum_pg_attrdef_adsrc_on_update, adrel->rd_att, &isnull); - if (val && pg_strcasecmp(TextDatumGetCString(val), "") == 0) { - updatedCol = false; - } else { + if (val && pg_strcasecmp(TextDatumGetCString(val), "") != 0) { updatedCol = true; + } else { + updatedCol = false; } } attrdef[attrdefIndex].has_on_update = updatedCol; diff --git a/src/gausskernel/optimizer/rewrite/rewriteHandler.cpp b/src/gausskernel/optimizer/rewrite/rewriteHandler.cpp index 2e3de2ac6..6d1ff0c7b 100644 --- a/src/gausskernel/optimizer/rewrite/rewriteHandler.cpp +++ b/src/gausskernel/optimizer/rewrite/rewriteHandler.cpp @@ -1173,13 +1173,11 @@ Node* build_column_default(Relation rel, int attrno, bool isInsertCmd, bool need * if adbin is not null character string, then doing convert adbin to expression. */ - if (needOnUpdate && (!isInsertCmd) && defval[ndef].has_on_update && + if (needOnUpdate && (!isInsertCmd) && defval[ndef].adbin_on_update != nullptr && pg_strcasecmp(defval[ndef].adbin_on_update, "") != 0) { expr = (Node*)stringToNode_skip_extern_fields(defval[ndef].adbin_on_update); - } else { - if (pg_strcasecmp(defval[ndef].adbin, "") != 0) { - expr = (Node*)stringToNode_skip_extern_fields(defval[ndef].adbin); - } + } else if (defval[ndef].adbin != nullptr && pg_strcasecmp(defval[ndef].adbin, "") != 0) { + expr = (Node*)stringToNode_skip_extern_fields(defval[ndef].adbin); } if (t_thrd.proc->workingVersionNum < LARGE_SEQUENCE_VERSION_NUM) { (void)check_sequence_return_numeric_walker(expr, &(u_sess->opt_cxt.nextval_default_expr_type));