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

Commit d0b1dbc

Browse files
committed
Remove publicationcmds.c's expr_allowed_in_node as a function
Its API is quite strange, and since there's only one caller, there's no reason for it to be a separate function in the first place. Inline it instead. Discussion: https://postgr.es/m/20220927124249.4zdzzlz6had7k3x2@alvherre.pgsql
1 parent 2e560b9 commit d0b1dbc

File tree

1 file changed

+22
-36
lines changed

1 file changed

+22
-36
lines changed

src/backend/commands/publicationcmds.c

+22-36
Original file line numberDiff line numberDiff line change
@@ -447,36 +447,6 @@ contain_mutable_or_user_functions_checker(Oid func_id, void *context)
447447
func_id >= FirstNormalObjectId);
448448
}
449449

450-
/*
451-
* Check if the node contains any disallowed object. Subroutine for
452-
* check_simple_rowfilter_expr_walker.
453-
*
454-
* If a disallowed object is found, *errdetail_msg is set to a (possibly
455-
* translated) message to use as errdetail. If none, *errdetail_msg is not
456-
* modified.
457-
*/
458-
static void
459-
expr_allowed_in_node(Node *node, ParseState *pstate, char **errdetail_msg)
460-
{
461-
if (IsA(node, List))
462-
{
463-
/*
464-
* OK, we don't need to perform other expr checks for List nodes
465-
* because those are undefined for List.
466-
*/
467-
return;
468-
}
469-
470-
if (exprType(node) >= FirstNormalObjectId)
471-
*errdetail_msg = _("User-defined types are not allowed.");
472-
else if (check_functions_in_node(node, contain_mutable_or_user_functions_checker,
473-
(void *) pstate))
474-
*errdetail_msg = _("User-defined or built-in mutable functions are not allowed.");
475-
else if (exprCollation(node) >= FirstNormalObjectId ||
476-
exprInputCollation(node) >= FirstNormalObjectId)
477-
*errdetail_msg = _("User-defined collations are not allowed.");
478-
}
479-
480450
/*
481451
* The row filter walker checks if the row filter expression is a "simple
482452
* expression".
@@ -586,12 +556,26 @@ check_simple_rowfilter_expr_walker(Node *node, ParseState *pstate)
586556
}
587557

588558
/*
589-
* For all the supported nodes, check the types, functions, and collations
590-
* used in the nodes.
559+
* For all the supported nodes, if we haven't already found a problem,
560+
* check the types, functions, and collations used in it. We check List
561+
* by walking through each element.
591562
*/
592-
if (!errdetail_msg)
593-
expr_allowed_in_node(node, pstate, &errdetail_msg);
563+
if (!errdetail_msg && !IsA(node, List))
564+
{
565+
if (exprType(node) >= FirstNormalObjectId)
566+
errdetail_msg = _("User-defined types are not allowed.");
567+
else if (check_functions_in_node(node, contain_mutable_or_user_functions_checker,
568+
(void *) pstate))
569+
errdetail_msg = _("User-defined or built-in mutable functions are not allowed.");
570+
else if (exprCollation(node) >= FirstNormalObjectId ||
571+
exprInputCollation(node) >= FirstNormalObjectId)
572+
errdetail_msg = _("User-defined collations are not allowed.");
573+
}
594574

575+
/*
576+
* If we found a problem in this node, throw error now. Otherwise keep
577+
* going.
578+
*/
595579
if (errdetail_msg)
596580
ereport(ERROR,
597581
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
@@ -653,13 +637,15 @@ TransformPubWhereClauses(List *tables, const char *queryString,
653637
errdetail("WHERE clause cannot be used for a partitioned table when %s is false.",
654638
"publish_via_partition_root")));
655639

640+
/*
641+
* A fresh pstate is required so that we only have "this" table in its
642+
* rangetable
643+
*/
656644
pstate = make_parsestate(NULL);
657645
pstate->p_sourcetext = queryString;
658-
659646
nsitem = addRangeTableEntryForRelation(pstate, pri->relation,
660647
AccessShareLock, NULL,
661648
false, false);
662-
663649
addNSItemToQuery(pstate, nsitem, false, true, true);
664650

665651
whereclause = transformWhereClause(pstate,

0 commit comments

Comments
 (0)