mirror of https://github.com/citusdata/citus.git
Merge pull request #1506 from citusdata/descend_function_evaluation
Function evaluation descends into expression treespull/1474/head
commit
3248f1a2b7
|
@ -100,12 +100,10 @@ RequiresMasterEvaluation(Query *query)
|
||||||
void
|
void
|
||||||
ExecuteMasterEvaluableFunctions(Query *query, PlanState *planState)
|
ExecuteMasterEvaluableFunctions(Query *query, PlanState *planState)
|
||||||
{
|
{
|
||||||
CmdType commandType = query->commandType;
|
|
||||||
ListCell *targetEntryCell = NULL;
|
ListCell *targetEntryCell = NULL;
|
||||||
ListCell *rteCell = NULL;
|
ListCell *rteCell = NULL;
|
||||||
ListCell *cteCell = NULL;
|
ListCell *cteCell = NULL;
|
||||||
Node *modifiedNode = NULL;
|
Node *modifiedNode = NULL;
|
||||||
bool insertSelectQuery = InsertSelectIntoDistributedTable(query);
|
|
||||||
|
|
||||||
if (query->jointree && query->jointree->quals)
|
if (query->jointree && query->jointree->quals)
|
||||||
{
|
{
|
||||||
|
@ -123,16 +121,8 @@ ExecuteMasterEvaluableFunctions(Query *query, PlanState *planState)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (commandType == CMD_INSERT && !insertSelectQuery)
|
|
||||||
{
|
|
||||||
modifiedNode = EvaluateNodeIfReferencesFunction((Node *) targetEntry->expr,
|
|
||||||
planState);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
modifiedNode = PartiallyEvaluateExpression((Node *) targetEntry->expr,
|
modifiedNode = PartiallyEvaluateExpression((Node *) targetEntry->expr,
|
||||||
planState);
|
planState);
|
||||||
}
|
|
||||||
|
|
||||||
targetEntry->expr = (Expr *) modifiedNode;
|
targetEntry->expr = (Expr *) modifiedNode;
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,4 +115,26 @@ SELECT * FROM example WHERE key = 3;
|
||||||
-----+-------
|
-----+-------
|
||||||
(0 rows)
|
(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;
|
DROP TABLE example;
|
||||||
|
|
|
@ -110,4 +110,20 @@ SELECT * FROM example WHERE key = 3;
|
||||||
DELETE FROM example WHERE key = 3 AND value < now() - interval '1 hour';
|
DELETE FROM example WHERE key = 3 AND value < now() - interval '1 hour';
|
||||||
SELECT * FROM example WHERE key = 3;
|
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;
|
DROP TABLE example;
|
||||||
|
|
Loading…
Reference in New Issue