cockroach
cockroach copied to clipboard
sql: support UDFs with named args, strictness, and volatility
sql: UDF with empty result should evaluate to NULL
If the last statement in a UDF returns no rows, the UDF will evaluate to NULL. Prior to this commit the evaluation of the UDF would panic.
Release note: None
sql: support UDFs with named arguments
UDFs with named arguments can now be evaluated.
During query planning, statements in the function body are built with a scope that includes the named arguments for the function as columns. This allows references to arguments to be resolved as variables.
During evaluation, the input expressions are first evaluated into datums. When a plan is built for each statement in the UDF, the argument columns in the expression are replaced with the input datums before the expression is optimized.
Note that anonymous arguments and integer references to arguments (e.g.,
$1) are not yet supported.
Also, the formatting of UDFExprs has been improved to show argument
columns and input expressions.
Release note: None
sql: do not evaluate strict UDFs if any input values are NULL
A UDF can have one of two behaviors when it is invoked with NULL inputs:
- If the UDF is
CALLED ON NULL INPUT(the default) then the function is evaluated regardless of whether or not any of the input values are NULL. - If the UDF
RETURNS NULL ON NULL INPUTor isSTRICTthen the function is not evaluated if any of the input values are NULL. Instead, the function directly results in NULL.
This commit implements these two behaviors.
In the future, we can add a normalization rule that folds a strict UDF if any of its inputs are constant NULL values.
Release note: None
sql: make mutations visible to volatile UDFs
The volatility of a UDF affects the visibility of mutations made by the statement calling the function. A volatile function will see these mutations. Also, statements within a volatile function's body will see changes made by previous statements the function body (note that this is left untested in this commit because we do not currently support mutations within UDF bodies). In contrast, a stable, immutable, or leakproof function will see a snapshot of the data as of the start of the statement calling the function.
Release note: None
TFTRs!
bors r+
bors r+
bors r-
Canceled.
bors r+
bors r+
Already running a review
bors r+
Already running a review