On 2015-11-27 5:46 AM, Keith Medcalf wrote: >> Is there a way I could programatically determine that a query is non- >> deterministic at query prepare time? > > What do you mean, non-deterministic? The result is deterministic in all > cases. > > It may be complicated and/or difficult for you to compute, but it is always > deterministic. The result is generated by running an unchanging algorithm on > unchanging data. If there is no random inputs and the computer hardware is > not broken, then the results are entirely determined by the algorithm > executed and the state of the data upon which it is operating.
While what you say is true, deterministic if same algorithm and same data, I think there's a higher standard for determinism. The concept of "arbitrary row" presumably is based on certain implementation details like the structure of an index or other hidden metadata, which can change even if there are no user-visible changes to the database. Unless the algorithm guarantees that the exact same row will be selected whenever the user-visible parts of the database have the exact same value, it is not actually deterministic from the user's point of view, which I think is what really matters here. Selecting an "arbitrary row" can only be called deterministic otherwise if the user is able to query all of the conditions that would make it chosen, such as index details, as are applicable. Any visible change is significant; if the user can get a different answer to any question about the database, including 'hidden' parts, then the database is different, whereas if all questions they can ask return the same answer, then the "arbitrary row" should be the same row. -- Darren Duncan

