Adam Kennedy created CALCITE-6532:
-------------------------------------

             Summary: Postgres RANDOM() is not flagged as non-deterministic
                 Key: CALCITE-6532
                 URL: https://issues.apache.org/jira/browse/CALCITE-6532
             Project: Calcite
          Issue Type: Bug
            Reporter: Adam Kennedy


Putting aside the question of whether the default Calcite RAND can be 
deterministic (when used with a seed) etc, it is most certainly the case that 
the Postgres RANDOM() function is not deterministic.

The following should return two different values.

SELECT RANDOM(), RANDOM()

In Calcite, currently it will return the same value twice as RexProgramBuilder 
deduplicates them to a single invocation (incorrectly).

This bug does not address the behavior of RexProgram, as there are separate 
issues for the problem of RexProgram not obeying isDeterministic = false. But 
were that bug to be fixed, it would be irrelevant to the SELECT RANDOM(), 
RANDOM() problem as it stands, because a RexProgramBuilder that obey'ed 
determinism wouldn't see RANDOM() as deterministic anyway.

Since RANDOM() is very new, and doesn't impact default Calcite use cases, I 
propose that we can also make non-deterministic RANDOM() a trial run for a 
later change of RAND() to non-deterministic.

It's not entirely clear to me what the semantic intent of isDynamic originally 
was, I had assumed it was related to functions that need to reach outside the 
context of the query to read from the environment, and that as a side effect 
they should not be cached.

 



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to