Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e1339bf

Browse files
committed
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
1 parent 8e1f37c commit e1339bf

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

src/backend/utils/adt/ruleutils.c

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4733,7 +4733,7 @@ make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc,
47334733
bool is_instead;
47344734
char *ev_qual;
47354735
char *ev_action;
4736-
List *actions = NIL;
4736+
List *actions;
47374737
Relation ev_relation;
47384738
TupleDesc viewResultDesc = NULL;
47394739
int fno;
@@ -4763,14 +4763,16 @@ make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc,
47634763
Assert(!isnull);
47644764
is_instead = DatumGetBool(dat);
47654765

4766-
/* these could be nulls */
47674766
fno = SPI_fnumber(rulettc, "ev_qual");
47684767
ev_qual = SPI_getvalue(ruletup, rulettc, fno);
4768+
Assert(ev_qual != NULL);
47694769

47704770
fno = SPI_fnumber(rulettc, "ev_action");
47714771
ev_action = SPI_getvalue(ruletup, rulettc, fno);
4772-
if (ev_action != NULL)
4773-
actions = (List *) stringToNode(ev_action);
4772+
Assert(ev_action != NULL);
4773+
actions = (List *) stringToNode(ev_action);
4774+
if (actions == NIL)
4775+
elog(ERROR, "invalid empty ev_action list");
47744776

47754777
ev_relation = table_open(ev_class, AccessShareLock);
47764778

@@ -4820,9 +4822,7 @@ make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc,
48204822
generate_qualified_relation_name(ev_class));
48214823

48224824
/* If the rule has an event qualification, add it */
4823-
if (ev_qual == NULL)
4824-
ev_qual = "";
4825-
if (strlen(ev_qual) > 0 && strcmp(ev_qual, "<>") != 0)
4825+
if (strcmp(ev_qual, "<>") != 0)
48264826
{
48274827
Node *qual;
48284828
Query *query;
@@ -4893,10 +4893,6 @@ make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc,
48934893
}
48944894
appendStringInfoString(buf, ");");
48954895
}
4896-
else if (list_length(actions) == 0)
4897-
{
4898-
appendStringInfoString(buf, "NOTHING;");
4899-
}
49004896
else
49014897
{
49024898
Query *query;
@@ -4926,7 +4922,7 @@ make_viewdef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc,
49264922
bool is_instead;
49274923
char *ev_qual;
49284924
char *ev_action;
4929-
List *actions = NIL;
4925+
List *actions;
49304926
Relation ev_relation;
49314927
int fno;
49324928
Datum dat;
@@ -4950,14 +4946,14 @@ make_viewdef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc,
49504946
Assert(!isnull);
49514947
is_instead = DatumGetBool(dat);
49524948

4953-
/* these could be nulls */
49544949
fno = SPI_fnumber(rulettc, "ev_qual");
49554950
ev_qual = SPI_getvalue(ruletup, rulettc, fno);
4951+
Assert(ev_qual != NULL);
49564952

49574953
fno = SPI_fnumber(rulettc, "ev_action");
49584954
ev_action = SPI_getvalue(ruletup, rulettc, fno);
4959-
if (ev_action != NULL)
4960-
actions = (List *) stringToNode(ev_action);
4955+
Assert(ev_action != NULL);
4956+
actions = (List *) stringToNode(ev_action);
49614957

49624958
if (list_length(actions) != 1)
49634959
{

0 commit comments

Comments
 (0)