Skip to content
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

Specify the behaviour of deleted elements #332

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions cip/1.accepted/CIP2018-10-19-Delete-Semantics.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
= CIP2018-10-19 Semantics of Deleted Elements
:numbered:
:toc:
:toc-placement: macro
:source-highlighter: codemirror

*Author:* Tobias Lindaaker <[email protected]>

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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a change from current behaviour.

This is the main change that people seem to agree that we want from this change proposal.


Accessing properties of deleted elements produces a `NULL` value, just like accessing a property from a `NULL` value would.

=== Pattern matching on deleted Elements
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a change from current behaviour.

Currently pattern matching on NULL produces 0 rows.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we deviate from the "behaves like null" in this case?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The proposal in this section is to have this be the behaviour for all nulls.


Pattern matching on deleted elements produces a single row containing only `NULL` bindings, in the same way as `OPTIONAL MATCH` would.

=== Deleting deleted Elements
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same as current behaviour, but should still be documented.


Deleting a deleted element (or any `NULL` value) is a no-op.

=== Equality of deleted Elements
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a change from current behaviour, where two references to the same element are considered equal even after the element has been deleted.


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
----