diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2020-11-02 14:34:34 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2020-11-02 14:34:34 -0500 |
commit | e1339bfc7a2fd4629e1c3f8f919ddd05b4745e13 (patch) | |
tree | 06a824407f287a5efeafca2d8b6de6d38be462fb /src/backend/utils/adt/ruleutils.c | |
parent | 8e1f37c07aafd4bb7aa6e1e1982010af11f8b5c7 (diff) | |
download | postgresql-e1339bfc7a2fd4629e1c3f8f919ddd05b4745e13.tar.gz postgresql-e1339bfc7a2fd4629e1c3f8f919ddd05b4745e13.zip |
Remove special checks for pg_rewrite.ev_qual and ev_action being NULL.
make_ruledef() and make_viewdef() were coded to cope with possible
null-ness of these columns, but they've been marked BKI_FORCE_NOT_NULL
for some time. So there's not really any need to do more than what
we do for the other columns of pg_rewrite, i.e. just Assert that
we got non-null results.
(There is a school of thought that says Asserts aren't the thing
to do to check for corrupt data, but surely here is not the place
to start if we want such a policy.)
Also, remove long-dead-if-indeed-it-ever-wasn't-dead handling of
an empty actions list in make_ruledef(). That's an error case
and should be treated as such. (DO INSTEAD NOTHING is represented
by a CMD_NOTHING Query, not an empty list; cf transformRuleStmt.)
Kyotaro Horiguchi, some changes by me
Discussion: https://postgr.es/m/CAEudQApoA=tMTic6xEPYP_hsNZ8XtToVThK_0x7D_aFQYowq3w@mail.gmail.com
Diffstat (limited to 'src/backend/utils/adt/ruleutils.c')
-rw-r--r-- | src/backend/utils/adt/ruleutils.c | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index 74461932529..28f56074c0c 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -4733,7 +4733,7 @@ make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc, bool is_instead; char *ev_qual; char *ev_action; - List *actions = NIL; + List *actions; Relation ev_relation; TupleDesc viewResultDesc = NULL; int fno; @@ -4763,14 +4763,16 @@ make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc, Assert(!isnull); is_instead = DatumGetBool(dat); - /* these could be nulls */ fno = SPI_fnumber(rulettc, "ev_qual"); ev_qual = SPI_getvalue(ruletup, rulettc, fno); + Assert(ev_qual != NULL); fno = SPI_fnumber(rulettc, "ev_action"); ev_action = SPI_getvalue(ruletup, rulettc, fno); - if (ev_action != NULL) - actions = (List *) stringToNode(ev_action); + Assert(ev_action != NULL); + actions = (List *) stringToNode(ev_action); + if (actions == NIL) + elog(ERROR, "invalid empty ev_action list"); ev_relation = table_open(ev_class, AccessShareLock); @@ -4820,9 +4822,7 @@ make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc, generate_qualified_relation_name(ev_class)); /* If the rule has an event qualification, add it */ - if (ev_qual == NULL) - ev_qual = ""; - if (strlen(ev_qual) > 0 && strcmp(ev_qual, "<>") != 0) + if (strcmp(ev_qual, "<>") != 0) { Node *qual; Query *query; @@ -4893,10 +4893,6 @@ make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc, } appendStringInfoString(buf, ");"); } - else if (list_length(actions) == 0) - { - appendStringInfoString(buf, "NOTHING;"); - } else { Query *query; @@ -4926,7 +4922,7 @@ make_viewdef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc, bool is_instead; char *ev_qual; char *ev_action; - List *actions = NIL; + List *actions; Relation ev_relation; int fno; Datum dat; @@ -4950,14 +4946,14 @@ make_viewdef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc, Assert(!isnull); is_instead = DatumGetBool(dat); - /* these could be nulls */ fno = SPI_fnumber(rulettc, "ev_qual"); ev_qual = SPI_getvalue(ruletup, rulettc, fno); + Assert(ev_qual != NULL); fno = SPI_fnumber(rulettc, "ev_action"); ev_action = SPI_getvalue(ruletup, rulettc, fno); - if (ev_action != NULL) - actions = (List *) stringToNode(ev_action); + Assert(ev_action != NULL); + actions = (List *) stringToNode(ev_action); if (list_length(actions) != 1) { |