From a59a560ac9aaac43c00f2980dd4e4d066b753a73 Mon Sep 17 00:00:00 2001 From: cuikaifeng <21268172@qq.com> Date: Thu, 12 Oct 2023 18:05:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=A4=E7=A9=BA=E8=AF=AD?= =?UTF-8?q?=E5=8F=A5=EF=BC=8C=E5=B9=B6=E6=8A=8Atrigger=E8=A1=A8=E4=B8=AD?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=AD=97=E6=AE=B5=E7=9A=84=E7=A9=BA=E5=80=BC?= =?UTF-8?q?=E7=BD=AE=E4=B8=BANULL=E8=80=8C=E9=9D=9E=E7=A9=BA=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E4=B8=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/backend/utils/adt/ruleutils.cpp | 8 +++++--- .../optimizer/commands/trigger.cpp | 20 +++++++++---------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/common/backend/utils/adt/ruleutils.cpp b/src/common/backend/utils/adt/ruleutils.cpp index 241a6c6ff..c36411461 100644 --- a/src/common/backend/utils/adt/ruleutils.cpp +++ b/src/common/backend/utils/adt/ruleutils.cpp @@ -3193,9 +3193,11 @@ static char* pg_get_triggerdef_worker(Oid trigid, bool pretty) } if (tgfbody != NULL) { - char* tgordername = DatumGetCString(fastgetattr(ht_trig, Anum_pg_trigger_tgordername, tgrel->rd_att, &isnull)); - char* tgorder = DatumGetCString(fastgetattr(ht_trig, Anum_pg_trigger_tgorder, tgrel->rd_att, &isnull)); - if (tgorder != NULL) + bool isordernull = false; + bool isordernamenull = false; + char* tgordername = DatumGetCString(fastgetattr(ht_trig, Anum_pg_trigger_tgordername, tgrel->rd_att, &isordernamenull)); + char* tgorder = DatumGetCString(fastgetattr(ht_trig, Anum_pg_trigger_tgorder, tgrel->rd_att, &isordernull)); + if (!isordernull && !isordernamenull) appendStringInfo(&buf, "%s %s ", tgorder, tgordername); appendStringInfo(&buf, "%s;", tgfbody); diff --git a/src/gausskernel/optimizer/commands/trigger.cpp b/src/gausskernel/optimizer/commands/trigger.cpp index cbca59d70..f22b02433 100644 --- a/src/gausskernel/optimizer/commands/trigger.cpp +++ b/src/gausskernel/optimizer/commands/trigger.cpp @@ -730,13 +730,13 @@ ObjectAddress CreateTrigger(CreateTrigStmt* stmt, const char* queryString, Oid r } } } else { - values[Anum_pg_trigger_tgordername - 1] = DirectFunctionCall1(namein, CStringGetDatum("")); - values[Anum_pg_trigger_tgorder - 1] = DirectFunctionCall1(namein, CStringGetDatum("")); + nulls[Anum_pg_trigger_tgordername - 1] = true; + nulls[Anum_pg_trigger_tgorder - 1] = true; } } else { - values[Anum_pg_trigger_tgordername - 1] = DirectFunctionCall1(namein, CStringGetDatum("")); - values[Anum_pg_trigger_tgorder - 1] = DirectFunctionCall1(namein, CStringGetDatum("")); - values[Anum_pg_trigger_tgtime - 1] = DirectFunctionCall1(namein, CStringGetDatum("")); + nulls[Anum_pg_trigger_tgordername - 1] = true; + nulls[Anum_pg_trigger_tgorder - 1] = true; + nulls[Anum_pg_trigger_tgtime - 1] = true; } if (stmt->args) { ListCell* le = NULL; @@ -1699,13 +1699,12 @@ void RelationBuildTriggers(Relation relation) char* trigname = DatumGetCString(DirectFunctionCall1(nameout, NameGetDatum(&pg_trigger->tgname))); char* tgordername = DatumGetCString(fastgetattr(htup, Anum_pg_trigger_tgordername, tgrel->rd_att, &isnull)); char* tgorder = DatumGetCString(fastgetattr(htup, Anum_pg_trigger_tgorder, tgrel->rd_att, &isnull)); - char* tgtime = DatumGetCString(fastgetattr(htup, Anum_pg_trigger_tgtime, tgrel->rd_att, &isnull)); - if (strcmp(tgorder, "follows") == 0) { + if (!isnull && strcmp(tgorder, "follows") == 0) { tgNameInfo->follows_name = tgordername; tgNameInfo->precedes_name = NULL; is_has_follows = true; } - else if (strcmp(tgorder, "precedes") == 0) { + else if (!isnull && strcmp(tgorder, "precedes") == 0) { tgNameInfo->follows_name = NULL; tgNameInfo->precedes_name = tgordername; is_has_follows = true; @@ -1714,8 +1713,9 @@ void RelationBuildTriggers(Relation relation) tgNameInfo->follows_name = NULL; tgNameInfo->precedes_name = NULL; } + char* tgtime = DatumGetCString(fastgetattr(htup, Anum_pg_trigger_tgtime, tgrel->rd_att, &isnull)); tgNameInfo->trg_name = trigname; - tgNameInfo->time = tgtime; + tgNameInfo->time = isnull ? NULL:tgtime; } build = &(triggers[numtrigs]); build->tgoid = HeapTupleGetOid(htup); @@ -1787,7 +1787,7 @@ void RelationBuildTriggers(Relation relation) TriggerNameInfo temp = tgNameInfos[end+gap]; Trigger tgtmp = triggers[end+gap]; while (end >= 0) { - if (strcmp(tmp, tgNameInfos[end].time)<0) { + if (tmp != NULL && tgNameInfos[end].time != NULL && strcmp(tmp, tgNameInfos[end].time)<0) { tgNameInfos[end+gap] = tgNameInfos[end]; triggers[end+gap] = triggers[end]; end -= gap;