lincoln-lil commented on PR #27506:
URL: https://github.com/apache/flink/pull/27506#issuecomment-3839783250
@nateab Thanks for contributing this!
IIUC, according to SQL:2016 (ISO/IEC 9075-2), the current behavior is
standards-compliant, and I don't recommend changing current execution semantics
here.
Clause 6.26 <value expression>, Syntax Rule (7) explicitly classifies a
value expression as possibly non-deterministic if it contains certain
constructs (e.g., datetime value functions or other system-dependent
expressions). For such expressions, the SQL standard does not guarantee
equivalence across multiple evaluations, even within a single SQL statement.
Furthermore, the General Rules of Clause 6.26 define the semantics of value
expressions in terms of evaluation events. Each evaluation of a <value
expression> produces a value, and the standard does not specify any implicit
sharing or reuse of results across different occurrences of the same expression
in different clauses (e.g., WHERE vs SELECT).
As a result, in your given query:
```sql
SELECT uuid() FROM t WHERE uuid() IS NOT NULL
```
the two occurrences of uuid() are semantically independent evaluations. The
fact that the value used for filtering may differ from the value produced in
the output is valid SQL behavior for a possibly non-deterministic expression,
and should not be treated as a correctness issue.
If users require the function to be evaluated only once per row and reused
consistently, this must be expressed explicitly in SQL, for example via a
subquery or CTE that materializes the value as a column, e.g.,
```sql
SELECT u
FROM (
SELECT uuid() AS u
FROM t
) s
WHERE u IS NOT NULL;
```
This aligns with both SQL semantics and optimizer expectations.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]