Skip to content

Commit 94802d8

Browse files
authored
Re-add relationship constraint documentation (#490)
Companion PR to neo4j/docs-cheat-sheet#69
1 parent 473cec7 commit 94802d8

File tree

8 files changed

+288
-416
lines changed

8 files changed

+288
-416
lines changed

modules/ROOT/pages/constraints/examples.adoc

Lines changed: 227 additions & 227 deletions
Large diffs are not rendered by default.

modules/ROOT/pages/constraints/index.adoc

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,10 @@ Unique node property constraints, or node property uniqueness constraints, ensur
1818
For property uniqueness constraints on multiple properties, the combination of the property values is unique.
1919
Node property uniqueness constraints do not require all nodes to have a unique value for the properties listed (nodes without all properties are not subject to this rule).
2020

21-
// TODO: Re-add this part when adding back relationship key and uniqueness constraints
22-
////
2321
*Unique relationship property constraints*::
2422
Unique relationship property constraints, or relationship property uniqueness constraints, ensure that property values are unique for all relationships with a specific type.
2523
For property uniqueness constraints on multiple properties, the combination of the property values is unique.
2624
Relationship property uniqueness constraints do not require all relationships to have a unique value for the properties listed (relationships without all properties are not subject to this rule).
27-
////
2825

2926
*Node property existence constraints* label:enterprise-edition[]::
3027
Node property existence constraints ensure that a property exists for all nodes with a specific label.
@@ -50,8 +47,6 @@ Queries attempting to do any of the following will fail:
5047
* Remove one of the mandatory properties.
5148
* Update the properties so that the combination of property values is no longer unique.
5249

53-
// TODO: Re-add this part when adding back relationship key and uniqueness constraints
54-
////
5550
*Relationship key constraints* label:enterprise-edition[]::
5651
Relationship key constraints ensure that, for a given type and set of properties:
5752
+
@@ -65,14 +60,11 @@ Queries attempting to do any of the following will fail:
6560
* Create new relationships without all the properties or where the combination of property values is not unique.
6661
* Remove one of the mandatory properties.
6762
* Update the properties so that the combination of property values is no longer unique.
68-
////
6963

7064

7165
[NOTE]
7266
====
73-
Node key constraints, node property existence constraints, and relationship property existence constraints are only available in Neo4j Enterprise Edition.
74-
// TODO: Switch the row above to the one below when adding back relationship key and uniqueness constraints
75-
//Node key constraints, relationship key constraints, node property existence constraints, and relationship property existence constraints are only available in Neo4j Enterprise Edition.
67+
Node key constraints, relationship key constraints, node property existence constraints, and relationship property existence constraints are not available in Neo4j Community Edition.
7668
Databases containing one of these constraint types cannot be opened using Neo4j Community Edition.
7769
====
7870

@@ -81,26 +73,15 @@ Databases containing one of these constraint types cannot be opened using Neo4j
8173

8274
Creating a constraint has the following implications on indexes:
8375

84-
* Adding a node key or property uniqueness constraint on a single property also adds an index on that property, and therefore, an index of the same index type, label, and property combination cannot be added separately.
85-
* Adding a node key or property uniqueness constraint for a set of properties also adds an index on those properties, and therefore, an index of the same index type, label, and properties combination cannot be added separately.
86-
* Cypher will use these indexes for lookups just like other indexes.
87-
Refer to xref::indexes-for-search-performance.adoc[] for more details on indexes.
88-
* If a node key or property uniqueness constraint is dropped and the backing index is still required, the index need to be created explicitly.
89-
90-
////
91-
TODO: Switch the part above to the one below when adding back relationship key and uniqueness constraints
9276
* Adding a node key, relationship key, or property uniqueness constraint on a single property also adds an index on that property, and therefore, an index of the same index type, label/relationship type, and property combination cannot be added separately.
9377
* Adding a node key, relationship key, or property uniqueness constraint for a set of properties also adds an index on those properties, and therefore, an index of the same index type, label/relationship type, and properties combination cannot be added separately.
9478
* Cypher will use these indexes for lookups just like other indexes.
9579
Refer to xref::indexes-for-search-performance.adoc[] for more details on indexes.
9680
* If a node key, relationship key, or property uniqueness constraint is dropped and the backing index is still required, the index need to be created explicitly.
97-
////
9881

9982
Additionally, the following is true for constraints:
10083

101-
* A given label can have multiple constraints, and uniqueness and property existence constraints can be combined on the same property.
102-
// TODO: Switch the row above to the one below when adding back relationship key and uniqueness constraints
103-
//* A given label or relationship type can have multiple constraints, and uniqueness and property existence constraints can be combined on the same property.
84+
* A given label or relationship type can have multiple constraints, and uniqueness and property existence constraints can be combined on the same property.
10485
* Adding constraints is an atomic operation that can take a while -- all existing data has to be scanned before Neo4j DBMS can turn the constraint 'on'.
10586
* Best practice is to give the constraint a name when it is created.
10687
If the constraint is not explicitly named, it will get an auto-generated name.

modules/ROOT/pages/constraints/syntax.adoc

Lines changed: 10 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ REQUIRE (n.propertyName_1, ..., n.propertyName_n) IS [NODE] UNIQUE
5656
Index provider can be specified using the `OPTIONS` clause.
5757

5858

59-
////
60-
TODO: Re-add this part when adding back relationship key and uniqueness constraints
6159
[[constraints-syntax-create-rel-unique]]
6260
[discrete]
6361
=== Create a relationship property uniqueness constraint
@@ -81,7 +79,6 @@ REQUIRE (r.propertyName_1, ..., r.propertyName_n) IS [REL[ATIONSHIP]] UNIQUE
8179
----
8280

8381
Index provider can be specified using the `OPTIONS` clause.
84-
////
8582

8683

8784
[[constraints-syntax-create-node-exists]]
@@ -149,8 +146,6 @@ REQUIRE (n.propertyName_1, ..., n.propertyName_n) IS [NODE] KEY
149146
Index provider can be specified using the `OPTIONS` clause.
150147

151148

152-
////
153-
TODO: Re-add this part when adding back relationship key and uniqueness constraints
154149
[[constraints-syntax-create-rel-key]]
155150
[discrete]
156151
=== Create a relationship key constraint label:enterprise-edition[]
@@ -174,7 +169,6 @@ REQUIRE (r.propertyName_1, ..., r.propertyName_n) IS [REL[ATIONSHIP]] KEY
174169
----
175170

176171
Index provider can be specified using the `OPTIONS` clause.
177-
////
178172

179173

180174
[[constraints-syntax-drop]]
@@ -208,21 +202,6 @@ Listing constraints requires the xref::administration/access-control/database-ad
208202

209203
The simple version of the command allows for a `WHERE` clause and will give back the default set of output columns:
210204

211-
[source, syntax, role="noheader", indent=0]
212-
----
213-
SHOW [
214-
ALL
215-
|UNIQUE[NESS]
216-
|NODE [PROPERTY] EXIST[ENCE]
217-
|REL[ATIONSHIP] [PROPERTY] EXIST[ENCE]
218-
|[PROPERTY] EXIST[ENCE]
219-
|NODE KEY
220-
] CONSTRAINT[S]
221-
[WHERE expression]
222-
----
223-
224-
////
225-
TODO: Switch the syntax above to the one below when adding back relationship key and uniqueness constraints
226205
[source, syntax, role="noheader", indent=0]
227206
----
228207
SHOW [
@@ -239,27 +218,9 @@ SHOW [
239218
] CONSTRAINT[S]
240219
[WHERE expression]
241220
----
242-
////
243221

244222
To get the full set of output columns, a yield clause is needed:
245223

246-
[source, syntax, role="noheader", indent=0]
247-
----
248-
SHOW [
249-
ALL
250-
|UNIQUE[NESS]
251-
|NODE [PROPERTY] EXIST[ENCE]
252-
|REL[ATIONSHIP] [PROPERTY] EXIST[ENCE]
253-
|[PROPERTY] EXIST[ENCE]
254-
|NODE KEY
255-
] CONSTRAINT[S]
256-
YIELD { * | field[, ...] } [ORDER BY field[, ...]] [SKIP n] [LIMIT n]
257-
[WHERE expression]
258-
[RETURN field[, ...] [ORDER BY field[, ...]] [SKIP n] [LIMIT n]]
259-
----
260-
261-
////
262-
TODO: Switch the syntax above to the one below when adding back relationship key and uniqueness constraints
263224
[source, syntax, role="noheader", indent=0]
264225
----
265226
SHOW [
@@ -278,7 +239,6 @@ YIELD { * | field[, ...] } [ORDER BY field[, ...]] [SKIP n] [LIMIT n]
278239
[WHERE expression]
279240
[RETURN field[, ...] [ORDER BY field[, ...]] [SKIP n] [LIMIT n]]
280241
----
281-
////
282242

283243

284244
The type filtering keywords filters the returned constraints on constraint type:
@@ -293,18 +253,14 @@ The type filtering keywords filters the returned constraints on constraint type:
293253
| Returns all constraints, no filtering on constraint type.
294254
This is the default if none is given.
295255

296-
// TODO: Re-add these parts when adding back relationship key and uniqueness constraints
297-
//|NODE UNIQUE[NESS]
298-
//| Returns the node property uniqueness constraints.
256+
|NODE UNIQUE[NESS]
257+
| Returns the node property uniqueness constraints.
299258

300-
//|REL[ATIONSHIP] UNIQUE[NESS]
301-
//| Returns the relationship property uniqueness constraints.
259+
|REL[ATIONSHIP] UNIQUE[NESS]
260+
| Returns the relationship property uniqueness constraints.
302261

303262
|UNIQUE[NESS]
304-
| Returns all property uniqueness constraints.
305-
// TODO: Switch the part above to the one below when adding back relationship key and uniqueness constraints
306-
//|UNIQUE[NESS]
307-
//| Returns all property uniqueness constraints, for both nodes and relationships.
263+
| Returns all property uniqueness constraints, for both nodes and relationships.
308264

309265
|NODE [PROPERTY] EXIST[ENCE]
310266
| Returns the node property existence constraints.
@@ -318,12 +274,11 @@ This is the default if none is given.
318274
|NODE KEY
319275
| Returns the node key constraints.
320276

321-
// TODO: Re-add these parts when adding back relationship key and uniqueness constraints
322-
//|REL[ATIONSHIP] KEY
323-
//| Returns the relationship key constraints.
277+
|REL[ATIONSHIP] KEY
278+
| Returns the relationship key constraints.
324279

325-
//|KEY
326-
//| Returns all node and relationship key constraints.
280+
|KEY
281+
| Returns all node and relationship key constraints.
327282

328283
|===
329284

@@ -344,9 +299,7 @@ The returned columns from the show command is:
344299
| STRING
345300

346301
| type
347-
| The ConstraintType of this constraint (`UNIQUENESS`, `NODE_PROPERTY_EXISTENCE`, `RELATIONSHIP_PROPERTY_EXISTENCE`, or `NODE_KEY`). label:default-output[]
348-
// TODO: Switch the row above to the one below when adding back relationship key and uniqueness constraints
349-
//| The ConstraintType of this constraint (`UNIQUENESS` (node uniqueness), `RELATIONSHIP_UNIQUENESS`, `NODE_PROPERTY_EXISTENCE`, `RELATIONSHIP_PROPERTY_EXISTENCE`, `NODE_KEY`, or `RELATIONSHIP_KEY`). label:default-output[]
302+
| The ConstraintType of this constraint (`UNIQUENESS` (node uniqueness), `RELATIONSHIP_UNIQUENESS`, `NODE_PROPERTY_EXISTENCE`, `RELATIONSHIP_PROPERTY_EXISTENCE`, `NODE_KEY`, or `RELATIONSHIP_KEY`). label:default-output[]
350303
| STRING
351304

352305
| entityType

modules/ROOT/pages/deprecations-additions-removals-compatibility.adoc

Lines changed: 39 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ a|
3636

3737
The Cypher query option `connectComponentsPlanner` is deprecated and will be removed without a replacement.
3838
The product's default behavior of using a cost-based IDP search algorithm when combining sub-plans will be kept.
39+
3940
|===
4041

4142

@@ -54,8 +55,44 @@ label:updated[]
5455
ALTER DATABASE ... [WAIT [n [SEC[OND[S]]]]\|NOWAIT]
5556
----
5657
a|
57-
New sub-clause `WAIT` for `ALTER DATABASE`.
58-
This enables adding a waiting clause to specify a time limit in which the command must be completed and returned.
58+
New sub-clause `WAIT` for `ALTER DATABASE`.
59+
This enables adding a waiting clause to specify a time limit in which the command must be completed and returned.
60+
61+
a|
62+
label:functionality[]
63+
label:new[]
64+
[source, cypher, role="noheader"]
65+
----
66+
CREATE CONSTRAINT name FOR ()-[r:TYPE]-() REQUIRE r.prop IS UNIQUE
67+
68+
CREATE CONSTRAINT name FOR ()-[r:TYPE]-() REQUIRE r.prop IS RELATIONSHIP KEY
69+
----
70+
a|
71+
72+
Added relationship xref:constraints/syntax.adoc#constraints-syntax-create-rel-key[key] and xref:constraints/syntax.adoc#constraints-syntax-create-rel-unique[uniqueness] constraints.
73+
74+
a|
75+
label:functionality[]
76+
label:new[]
77+
[source, cypher, role="noheader"]
78+
----
79+
SHOW NODE UNIQUE[NESS] CONSTRAINTS
80+
81+
SHOW REL[ATIONSHIP] UNIQUE[NESS] CONSTRAINTS
82+
83+
SHOW UNIQUE[NESS] CONSTRAINTS
84+
85+
SHOW REL[ATIONSHIP] KEY CONSTRAINTS
86+
87+
SHOW KEY CONSTRAINTS
88+
----
89+
a|
90+
91+
Added filtering for the new constraint types to `SHOW CONSTRAINTS`.
92+
Includes filtering for the node part, relationship part, or both parts of each type (`NODE KEY` filtering already exists previously).
93+
94+
The existing `UNIQUENESS` filter will now return both node and relationship property uniqueness constraints.
95+
5996
|===
6097

6198
[[cypher-deprecations-additions-removals-5.6]]
@@ -164,32 +201,6 @@ RETURN 'val' as one, 'val' as two
164201
[[cypher-deprecations-additions-removals-5.3]]
165202
== Version 5.3
166203

167-
// TODO: Re-add this part in whatever version (not 5.3...) the relationship key and uniqueness constraints are added back in
168-
////
169-
=== Deprecated features
170-
171-
[cols="2", options="header"]
172-
|===
173-
| Feature
174-
| Details
175-
176-
a|
177-
//not sure what category this should be, it is more information about a coming breaking change than actual deprecation
178-
label:returnValues[]
179-
label:deprecated[]
180-
[source, cypher, role="noheader"]
181-
----
182-
SHOW NODE UNIQUENESS CONSTRAINTS YIELD type
183-
----
184-
a|
185-
186-
The current constraint type for node property uniqueness constraints, `UNIQUENESS`, will be updated to `NODE_UNIQUENESS` in Neo4j version 6.0.
187-
188-
This will also be reflected in updates to some error messages and query statistics.
189-
190-
|===
191-
////
192-
193204
=== Updated features
194205

195206
[cols="2", options="header"]
@@ -252,53 +263,6 @@ The property uniqueness constraint type filter now allow both `UNIQUE` and `UNIQ
252263

253264
|===
254265

255-
// TODO: Re-add this part in whatever version (not 5.3...) the relationship key and uniqueness constraints are added back in
256-
////
257-
=== New features
258-
259-
[cols="2", options="header"]
260-
|===
261-
| Feature
262-
| Details
263-
264-
a|
265-
label:functionality[]
266-
label:new[]
267-
[source, cypher, role="noheader"]
268-
----
269-
CREATE CONSTRAINT name FOR ()-[r:TYPE]-() REQUIRE r.prop IS UNIQUE
270-
271-
CREATE CONSTRAINT name FOR ()-[r:TYPE]-() REQUIRE r.prop IS RELATIONSHIP KEY
272-
----
273-
a|
274-
275-
Added relationship xref:constraints/syntax.adoc#constraints-syntax-create-rel-key[key] and xref:constraints/syntax.adoc#constraints-syntax-create-rel-unique[uniqueness] constraints.
276-
277-
a|
278-
label:functionality[]
279-
label:new[]
280-
[source, cypher, role="noheader"]
281-
----
282-
SHOW NODE UNIQUE[NESS] CONSTRAINTS
283-
284-
SHOW REL[ATIONSHIP] UNIQUE[NESS] CONSTRAINTS
285-
286-
SHOW UNIQUE[NESS] CONSTRAINTS
287-
288-
SHOW REL[ATIONSHIP] KEY CONSTRAINTS
289-
290-
SHOW KEY CONSTRAINTS
291-
----
292-
a|
293-
294-
Added filtering for the new constraint types to `SHOW CONSTRAINTS`.
295-
Includes filtering for the node part, relationship part, or both parts of each type (`NODE KEY` filtering already exists previously).
296-
297-
The existing `UNIQUENESS` filter will now return both node and relationship property uniqueness constraints.
298-
299-
|===
300-
////
301-
302266
[[cypher-deprecations-additions-removals-5.2]]
303267
== Version 5.2
304268

modules/ROOT/pages/execution-plans/operators.adoc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5022,9 +5022,7 @@ This constraint can have any of the available constraint types:
50225022

50235023
* Property uniqueness constraints
50245024
* Property existence constraints label:enterprise-edition[]
5025-
* Node key constraints label:enterprise-edition[]
5026-
// TODO: Switch the row above to the one below when adding back relationship key and uniqueness constraints
5027-
//* Node or relationship key constraints label:enterprise-edition[]
5025+
* Node or relationship key constraints label:enterprise-edition[]
50285026

50295027
The following query will create a property uniqueness constraint with the name `uniqueness` on the `name` property of nodes with the `Country` label.
50305028

modules/ROOT/pages/introduction/cypher_neo4j.adoc

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,12 @@ a|
3232
All constraints:
3333
xref::constraints/examples.adoc#constraints-examples-node-property-existence[node existence constraints],
3434
xref::constraints/examples.adoc#constraints-examples-relationship-property-existence[relationship existence constraints],
35-
xref::constraints/examples.adoc#constraints-examples-node-uniqueness[node property uniqueness constraints], and
36-
xref::constraints/examples.adoc#constraints-examples-node-key[node key constraints].
37-
////
38-
TODO: Switch the part above to the one below when adding back relationship key and uniqueness constraints
39-
All constraints:
40-
xref::constraints/examples.adoc#constraints-examples-node-property-existence[node existence constraints],
41-
xref::constraints/examples.adoc#constraints-examples-relationship-property-existence[relationship existence constraints],
4235
xref::constraints/examples.adoc#constraints-examples-node-uniqueness[node property uniqueness constraints],
4336
xref::constraints/examples.adoc#constraints-examples-relationship-uniqueness[relationship property uniqueness constraints],
4437
xref::constraints/examples.adoc#constraints-examples-node-key[node key constraints], and
4538
xref::constraints/examples.adoc#constraints-examples-relationship-key[relationship key constraints].
46-
////
4739
a|
48-
Only xref::constraints/examples.adoc#constraints-examples-node-uniqueness[node property uniqueness constraints].
49-
// TODO: Switch the row above to the one below when adding back relationship key and uniqueness constraints
50-
//Only xref::constraints/examples.adoc#constraints-examples-node-uniqueness[node] and xref::constraints/examples.adoc#constraints-examples-relationship-uniqueness[relationship] property uniqueness constraints.
40+
Only xref::constraints/examples.adoc#constraints-examples-node-uniqueness[node] and xref::constraints/examples.adoc#constraints-examples-relationship-uniqueness[relationship] property uniqueness constraints.
5141

5242
|===
5343

0 commit comments

Comments
 (0)