From 0668d1649b958bc8ca425c4998ce8a5070e09a32 Mon Sep 17 00:00:00 2001 From: Tobias Lindaaker Date: Fri, 19 Oct 2018 15:23:12 +0200 Subject: [PATCH 1/4] Specify the behaviour of deleted elements --- .../CIP2018-10-19-Delete-Semantics.adoc | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 cip/1.accepted/CIP2018-10-19-Delete-Semantics.adoc diff --git a/cip/1.accepted/CIP2018-10-19-Delete-Semantics.adoc b/cip/1.accepted/CIP2018-10-19-Delete-Semantics.adoc new file mode 100644 index 0000000000..afdb64f238 --- /dev/null +++ b/cip/1.accepted/CIP2018-10-19-Delete-Semantics.adoc @@ -0,0 +1,49 @@ += CIP2018-10-19 Semantics of Deleted Elements +:numbered: +:toc: +:toc-placement: macro +:source-highlighter: codemirror + +*Author:* Tobias Lindaaker + +toc::[] + +== Semantics of Deleted Elements + +Cypher allows read statements to occur after update statements. +This includes reading statements after statements that delete elements. +Since the driving table of the preceding query is retained into the succeeding reading statements, this means that entries in the driving table that previously contained elements might now contain elements that have been deleted. + +The semantics of accessing such elements is the same as accessing `NULL` values. + +This can be thought of as replacing all occurrences of the deleted elements (anywhere) in the driving table (including in nested values) with `NULL`, or as treating the deleted elements as _effectively_ `NULL`. + +These semantics effect the `DELETE` statement itself, even if not succeeded by further read statements, since the same element can occur in multiple rows in the driving table. + + +=== Accessing properties of deleted Elements + +Accessing properties of deleted elements produces a `NULL` value, just like accessing a property from a `NULL` value would. + +=== Pattern matching on deleted Elements + +Pattern matching on deleted elements produces a single row containing only `NULL` bindings, in the same way as `OPTIONAL MATCH` would. + +=== Deleting deleted Elements + +Deleting a deleted element (or any `NULL` value) is a no-op. + +=== Equality of deleted Elements + +The normal semantics is that two `NULL` values are never considered equal. +This extends to deleted elements, since they are equivalent to `NULL` for _all_ intents and purposes. + +[source, cypher] +.This query returns `same1: *true*; same2: *false*` for all rows +---- +MATCH (n), (m) +WHERE n = m AND NOT EXISTS { (n)-() } +WITH n, m, n = m AS same1 +DELETE n +RETURN same1, n = m AS same2 +---- From 2d07e71300e6067e1ec8a1df1c33fcaef63f09df Mon Sep 17 00:00:00 2001 From: Tobias Lindaaker Date: Fri, 19 Oct 2018 15:42:46 +0200 Subject: [PATCH 2/4] Add a note on the effect DELETE has on type system analysis --- cip/1.accepted/CIP2018-10-19-Delete-Semantics.adoc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cip/1.accepted/CIP2018-10-19-Delete-Semantics.adoc b/cip/1.accepted/CIP2018-10-19-Delete-Semantics.adoc index afdb64f238..52b42de5bb 100644 --- a/cip/1.accepted/CIP2018-10-19-Delete-Semantics.adoc +++ b/cip/1.accepted/CIP2018-10-19-Delete-Semantics.adoc @@ -47,3 +47,11 @@ WITH n, m, n = m AS same1 DELETE n RETURN same1, n = m AS same2 ---- + +=== Effects of DELETE on types + +In the part of a query following a `DELETE` statement that deletes elements of type node, all elements of type node may now be nullable. +In the part of a query following a `DELETE` statement that deletes elements of type relationship, all elements of type relationship may now be nullable. +In the part of a query following a `DETACH DELETE` statement, all elements of type node and of type relationship may now be nullable. + +An implementation that tracks the types of nodes and relationships more closely, such as by which labels they have, it is allowed to not treat elements as nullable in the part of the query following `DELETE` iff it can be proven that those entities are unaffected by the `DELETE`. From c0ee5ba627c8753d39ac575eae7d9ebb19903a80 Mon Sep 17 00:00:00 2001 From: Tobias Lindaaker Date: Fri, 19 Oct 2018 15:57:40 +0200 Subject: [PATCH 3/4] Adding notes on deleted elements in paths --- cip/1.accepted/CIP2018-10-19-Delete-Semantics.adoc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cip/1.accepted/CIP2018-10-19-Delete-Semantics.adoc b/cip/1.accepted/CIP2018-10-19-Delete-Semantics.adoc index 52b42de5bb..d1433fd5ef 100644 --- a/cip/1.accepted/CIP2018-10-19-Delete-Semantics.adoc +++ b/cip/1.accepted/CIP2018-10-19-Delete-Semantics.adoc @@ -48,6 +48,18 @@ DELETE n RETURN same1, n = m AS same2 ---- +=== Deleted elements in paths + +If an element is deleted that is part of a path value, such a path can no longer exist, therefore the path value is to be treated as _effectively_ `NULL` (in the same way that the deleted element that is part of it would). + +[source, cypher] +.This query returns `a: *null*; b: *null*; c: *null*` for all rows +---- +MATCH p=()-[r]->() +DELETE r +RETURN p AS a, nodes(p) AS b, relationships(p) AS c +---- + === Effects of DELETE on types In the part of a query following a `DELETE` statement that deletes elements of type node, all elements of type node may now be nullable. From 634d561bba1cf6f4db92b3ad8d2219916746a405 Mon Sep 17 00:00:00 2001 From: Tobias Lindaaker Date: Fri, 19 Oct 2018 16:04:50 +0200 Subject: [PATCH 4/4] Marry the section on paths with the section on type system --- cip/1.accepted/CIP2018-10-19-Delete-Semantics.adoc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cip/1.accepted/CIP2018-10-19-Delete-Semantics.adoc b/cip/1.accepted/CIP2018-10-19-Delete-Semantics.adoc index d1433fd5ef..525136dbad 100644 --- a/cip/1.accepted/CIP2018-10-19-Delete-Semantics.adoc +++ b/cip/1.accepted/CIP2018-10-19-Delete-Semantics.adoc @@ -60,10 +60,11 @@ DELETE r RETURN p AS a, nodes(p) AS b, relationships(p) AS c ---- -=== Effects of DELETE on types +=== Effects of DELETE on the nullability of types In the part of a query following a `DELETE` statement that deletes elements of type node, all elements of type node may now be nullable. In the part of a query following a `DELETE` statement that deletes elements of type relationship, all elements of type relationship may now be nullable. In the part of a query following a `DETACH DELETE` statement, all elements of type node and of type relationship may now be nullable. +In the part of a query following a `DELETE` statement, all elements of type path may now be nullable. -An implementation that tracks the types of nodes and relationships more closely, such as by which labels they have, it is allowed to not treat elements as nullable in the part of the query following `DELETE` iff it can be proven that those entities are unaffected by the `DELETE`. +An implementation that tracks the types of nodes and relationships more closely, such as by which labels they have, it is allowed to not treat elements as nullable in the part of the query following `DELETE` iff it can be proven that those elements are unaffected by the `DELETE`.