Merge pull request #1506 from citusdata/descend_function_evaluation

Function evaluation descends into expression trees
pull/1474/head
Marco Slot 2017-08-06 22:24:22 +04:00 committed by GitHub
commit 3248f1a2b7
3 changed files with 40 additions and 12 deletions

View File

@ -100,12 +100,10 @@ RequiresMasterEvaluation(Query *query)
void
ExecuteMasterEvaluableFunctions(Query *query, PlanState *planState)
{
CmdType commandType = query->commandType;
ListCell *targetEntryCell = NULL;
ListCell *rteCell = NULL;
ListCell *cteCell = NULL;
Node *modifiedNode = NULL;
bool insertSelectQuery = InsertSelectIntoDistributedTable(query);
if (query->jointree && query->jointree->quals)
{
@ -123,16 +121,8 @@ ExecuteMasterEvaluableFunctions(Query *query, PlanState *planState)
continue;
}
if (commandType == CMD_INSERT && !insertSelectQuery)
{
modifiedNode = EvaluateNodeIfReferencesFunction((Node *) targetEntry->expr,
planState);
}
else
{
modifiedNode = PartiallyEvaluateExpression((Node *) targetEntry->expr,
planState);
}
modifiedNode = PartiallyEvaluateExpression((Node *) targetEntry->expr,
planState);
targetEntry->expr = (Expr *) modifiedNode;
}

View File

@ -115,4 +115,26 @@ SELECT * FROM example WHERE key = 3;
-----+-------
(0 rows)
-- test that function evaluation descends into expressions
CREATE OR REPLACE FUNCTION stable_fn()
RETURNS timestamptz STABLE
LANGUAGE plpgsql
AS $function$
BEGIN
RAISE NOTICE 'stable_fn called';
RETURN timestamp '10-10-2000 00:00';
END;
$function$;
INSERT INTO example VALUES (44, (ARRAY[stable_fn(),stable_fn()])[1]);
NOTICE: stable_fn called
CONTEXT: PL/pgSQL function stable_fn() line 3 at RAISE
NOTICE: stable_fn called
CONTEXT: PL/pgSQL function stable_fn() line 3 at RAISE
SELECT * FROM example WHERE key = 44;
key | value
-----+------------------------------
44 | Tue Oct 10 00:00:00 2000 PDT
(1 row)
DROP FUNCTION stable_fn();
DROP TABLE example;

View File

@ -110,4 +110,20 @@ SELECT * FROM example WHERE key = 3;
DELETE FROM example WHERE key = 3 AND value < now() - interval '1 hour';
SELECT * FROM example WHERE key = 3;
-- test that function evaluation descends into expressions
CREATE OR REPLACE FUNCTION stable_fn()
RETURNS timestamptz STABLE
LANGUAGE plpgsql
AS $function$
BEGIN
RAISE NOTICE 'stable_fn called';
RETURN timestamp '10-10-2000 00:00';
END;
$function$;
INSERT INTO example VALUES (44, (ARRAY[stable_fn(),stable_fn()])[1]);
SELECT * FROM example WHERE key = 44;
DROP FUNCTION stable_fn();
DROP TABLE example;