Skip to content

Commit 0f6627d

Browse files
Improve raw http and transaction explanation
Correct Raw HTTP examples and explain transactions
1 parent 4e40fca commit 0f6627d

File tree

8 files changed

+812
-448
lines changed

8 files changed

+812
-448
lines changed

docusaurus-docs/docs/clients/raw-http.md

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

docusaurus-docs/docs/dql/dql-mutation.md

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ In DQL, you add data using a set mutation, identified by the `set` keyword.
5050
```
5151
</TabItem>
5252
<TabItem value="rdf" label="RDF">
53-
```
53+
triples are in [RDF](dql-rdf) format.
54+
```sh
5455
{
5556
set {
5657
# triples in here
@@ -62,8 +63,8 @@ In DQL, you add data using a set mutation, identified by the `set` keyword.
6263
}
6364
}
6465
```
65-
66-
triples are in [RDF](dql-rdf) format.
66+
</TabItem>
67+
</Tabs>
6768

6869
### Node reference
6970
A mutation can include a blank nodes as an identifier for the subject or object, or a known UID.
@@ -87,8 +88,7 @@ will add the `release_date` information to the node identified by UID `0x632ea2`
8788
}
8889
```
8990

90-
</TabItem>
91-
</Tabs>
91+
9292

9393

9494
## delete block
@@ -127,14 +127,9 @@ indexing) is removed with the pattern `S P *`.
127127
}
128128
```
129129

130-
The pattern `S * *` deletes all the known edges out of a node, any reverse edges
130+
The pattern `S * *` deletes all predicates from a node `S`, along with any reverse edges
131131
corresponding to the removed edges, and any indexing for the removed data.
132132

133-
:::note For mutations that fit the `S * *` pattern, only
134-
predicates that are among the types associated with a given node (using
135-
`dgraph.type`) are deleted. Any predicates that don't match one of the
136-
node's types will remain after an `S * *` delete mutation.:::
137-
138133
```sh
139134
{
140135
delete {
@@ -143,13 +138,29 @@ node's types will remain after an `S * *` delete mutation.:::
143138
}
144139
```
145140

146-
If the node `S` in the delete pattern `S * *` has only a few predicates with a
147-
type defined by `dgraph.type`, then only those triples with typed predicates are
148-
deleted. A node that contains untyped predicates will still exist after a
149-
`S * *` delete mutation.
141+
:::note
142+
When using the `S * *` pattern, Dgraph only deletes predicates that are defined in the types associated with the node via `dgraph.type`.
143+
144+
For example, if a node has `dgraph.type: ["Person", "Author"]`, and the `Person` type defines predicates `name`, `age`, and `email`, while the `Author` type defines predicates `name` and `author.of`, then `S * *` will only delete triples for predicates that appear in at least one of these types (`name`, `age`, `email`, `author.of`).
145+
146+
Any predicates on the node that are not defined in any of the node's types will remain after the `S * *` delete mutation. This means:
147+
- If a node has untyped predicates (predicates not in any `dgraph.type`), those predicates will not be deleted.
148+
- If a node has no `dgraph.type` assigned, `S * *` will have no effect.
149+
:::
150+
151+
**Example:**
152+
153+
Consider a node with UID `0x123` that has:
154+
- `dgraph.type: "Person"` (where `Person` type defines `name`, `age`, `email`)
155+
- Predicate `name: "Alice"` (typed - will be deleted)
156+
- Predicate `age: "30"` (typed - will be deleted)
157+
- Predicate `custom_field: "value"` (untyped - will NOT be deleted)
158+
159+
After executing `delete { <0x123> * * . }`, the node will still exist with only `custom_field: "value"` remaining.
150160

151-
:::note The patterns `* P O` and `* * O` are not supported because
152-
it's inefficient to store and find all the incoming edges. :::
161+
:::note
162+
The patterns `* P O` and `* * O` are not supported.
163+
:::
153164

154165
### Deletion of non-list predicates
155166

docusaurus-docs/docs/dql/index.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,35 @@ Dgraph stores data as facts using predicates. Each fact follows the pattern: `<n
2121

2222
For detailed definitions, see the [Dgraph Glossary](/dgraph-glossary) and [design concepts](/design-concepts/relationships-concept).
2323

24-
---
24+
## Transactions
25+
26+
Dgraph supports transactions to ensure data consistency and atomicity. A transaction groups multiple operations (queries and mutations) into a single atomic unit.
27+
28+
### Transaction Lifecycle
29+
30+
1. **Start a transaction**: When you execute a query or mutation, Dgraph automatically starts a new transaction and assigns it a unique transaction ID (also called `start_ts` or start timestamp).
31+
32+
2. **Execute operations**: Within a transaction, you can perform multiple queries and mutations. All operations in the same transaction use the same transaction ID to ensure they see a consistent view of the data.
33+
34+
3. **Commit or rollback**:
35+
- **Commit**: Makes all changes in the transaction permanent. After committing, the changes are visible to other transactions.
36+
- **Rollback (abort)**: Discards all changes in the transaction. The database returns to its state before the transaction started.
37+
38+
### Transaction Contents
39+
40+
A transaction can contain:
41+
- **Queries**: Read data from the database
42+
- **Mutations**: Add, modify, or delete data
43+
44+
You can perform multiple queries and mutations within a single transaction before committing. This allows you to read data, make decisions based on that data, and then apply mutations—all while maintaining consistency.
45+
46+
### Read-Only Transactions
47+
48+
Read-only transactions are optimized for read operations and cannot contain mutations. They are useful to increase read speed because they can circumvent the usual consensus protocol. Attempting to perform a mutation in a read-only transaction will result in an error.
49+
50+
Read-only queries can optionally be set as **best-effort**. Using this flag asks the Dgraph Alpha to try to get timestamps from memory on a best-effort basis to reduce the number of outbound requests to Zero. This may yield improved latencies in read-bound workloads where linearizable reads are not strictly needed.
51+
52+
For more details, see [Transactions](../design-concepts/transactions-concept) and [DQL Query](query/dql-query).
2553

2654

2755

docusaurus-docs/docs/dql/query/dql-query.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,19 @@ A DQL query has
2323

2424
![DQL Query with parameterization](/images/dql-syntax/query-syntax-1.png)
2525

26+
### Read-Only Transactions
27+
28+
Read-only transactions can be created by calling `c.NewReadOnlyTxn()`. Read-only
29+
transactions are useful to increase read speed because they can circumvent the
30+
usual consensus protocol. Read-only transactions cannot contain mutations and
31+
trying to call `txn.Commit()` will result in an error. Calling `txn.Discard()`
32+
will be a no-op.
33+
34+
Read-only queries can optionally be set as best-effort. Using this flag will ask
35+
the Dgraph Alpha to try to get timestamps from memory on a best-effort basis to
36+
reduce the number of outbound requests to Zero. This may yield improved
37+
latencies in read-bound workloads where linearizable reads are not strictly
38+
needed.
2639

2740
### Query parameterization
2841
**Parameters**

0 commit comments

Comments
 (0)