-
Notifications
You must be signed in to change notification settings - Fork 409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add documentation for volatility. #8005
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,6 +88,7 @@ Introspection command: | |
casts | ||
functions | ||
cardinality | ||
volatility | ||
|
||
select | ||
insert | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
.. _ref_reference_volatility: | ||
|
||
|
||
Volatility | ||
========== | ||
|
||
The **volatility** of an expression refers to how its value may change across | ||
successive evaluations. | ||
|
||
Expressions may have one of the following volatilities, in order of increasing | ||
volatility: | ||
|
||
* ``Immutable``: The expression cannot modify the database and is | ||
guaranteed to have the same value *in all statements*. | ||
|
||
Pointers maybe be treated as immutable for the purposes of some | ||
restrictions. See below for details. | ||
|
||
* ``Stable``: The expression cannot modify the database and is | ||
guaranteed to have the same value *within a single statement*. | ||
|
||
* ``Volatile``: The expression cannot modify the database and can have | ||
different values on successive evaluations. | ||
|
||
* ``Modifying``: The expression can modify the database and can have | ||
different values on successive evaluations. | ||
|
||
|
||
Expressions | ||
----------- | ||
|
||
All :ref:`primitives <ref_datamodel_primitives>`, | ||
:ref:`ranges <ref_std_range>`, and | ||
:ref:`multiranges <ref_std_multirange>` are ``Immutable``. | ||
|
||
:ref:`Arrays <ref_std_array>`, :ref:`tuples <ref_std_tuple>`, and | ||
:ref:`sets <ref_eql_sets>` have the volatility of their most volatile | ||
component. | ||
|
||
:ref:`Globals <ref_datamodel_globals>` are always ``Stable``, even computed | ||
globals with an immutable expression. | ||
|
||
|
||
Objects and shapes | ||
^^^^^^^^^^^^^^^^^^ | ||
|
||
:ref:`Objects <ref_datamodel_object_types>` are generally ``Stable`` except: | ||
|
||
* Objects with a :ref:`shape <ref_eql_shapes>` containing a more volatile | ||
computed pointer will have the volatility of its most volatile component. | ||
|
||
* :ref:`Free objects <ref_eql_select_free_objects>` have the volatility of | ||
their most volatile component. They may be ``Immutable``. | ||
|
||
An object's non-computed pointers are ``Stable``. Its computed pointers have | ||
the volatility of their expressions. | ||
|
||
Any DML (i.e., :ref:`insert <ref_eql_insert>`, :ref:`update <ref_eql_update>`, | ||
:ref:`delete <ref_eql_delete>`) is ``Modifying``. | ||
|
||
|
||
Functions and operators | ||
^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
Unless explicitly specified, a :ref:`function's <ref_eql_sdl_functions>` | ||
volatility will be inferred from its body expression. | ||
|
||
A function call's volatility is highest of its body expression and its call | ||
arguments. | ||
|
||
Given: | ||
|
||
.. code-block:: sdl | ||
|
||
# Immutable | ||
function plus_primitive(x: float64) -> float64 | ||
using (x + 1); | ||
|
||
# Stable | ||
global one := 1; | ||
function plus_global(x: float64) -> float64 | ||
using (x + one); | ||
|
||
# Volatile | ||
function plus_random(x: float64) -> float64 | ||
using (x + random()); | ||
|
||
# Modifying | ||
type One { | ||
val := 1; | ||
}; | ||
function plus_insert(x: float64) -> float64 | ||
using (x + (insert One).val); | ||
|
||
Some example operator and function calls: | ||
|
||
.. code-block:: | ||
|
||
1 + 1: Immutable | ||
1 + global one: Stable | ||
global one + random(): Unstable | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Volatile. Unstable isn't a thing :P. (Though it would be a fine name for it.) |
||
(insert One).val: Modifying | ||
plus_primitive(1): Immutable | ||
plus_stable(1): Stable | ||
plus_random(global one): Unstable | ||
plus_insert(random()): Immutable | ||
|
||
|
||
Restrictions | ||
------------ | ||
|
||
Some features restrict the volatility of expressions. A lower volatility | ||
can be used. | ||
|
||
:ref:`Indexes <ref_datamodel_indexes>` expressions must be ``Immutable``. | ||
Within the index, pointers to the indexed object are treated as immutable | ||
|
||
:ref:`constraints <ref_datamodel_constraints>` expressions must be | ||
``Immutable``. Within the constraint, the ``__subject__`` and its pointers are | ||
treated as immutable. | ||
|
||
:ref:`Access policies <ref_datamodel_access_policies>` must be ``Stable``. | ||
|
||
:ref:`Aliases <ref_eql_ddl_aliases>`, :ref:`globals <ref_datamodel_globals>`, | ||
and :ref:`computed pointers <ref_datamodel_computed>` in the schema must be | ||
``Stable``. | ||
|
||
The :ref:`cartesian product <ref_reference_cardinality_cartesian>` of a | ||
``Volatile`` or ``Modifying`` expression is not allowed. | ||
|
||
.. code-block:: edgeql-repl | ||
|
||
db> SELECT {1, 2} + random() | ||
QueryError: can not take cross product of volatile operation | ||
|
||
``Modifying`` expressions are not allowed in a non-scalar argument to a | ||
function, except for :ref:`standard set functions <ref_std_set>`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd drop this from here, I think?