Skip to content

Explain for UPDATE, UPSERT and DELETE #1181

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 10 additions & 0 deletions src/content/doc-surrealql/statements/delete.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ DELETE [ ONLY ] @targets
[ RETURN NONE | RETURN BEFORE | RETURN AFTER | RETURN DIFF | RETURN @statement_param, ... ]
[ TIMEOUT @duration ]
[ PARALLEL ]
[ EXPLAIN [ FULL ]]
;
```

Expand Down Expand Up @@ -216,3 +217,12 @@ SELECT * FROM deleted_person;
}
]
```

## The `EXPLAIN` clause

When `EXPLAIN` is used:

1. The `DELETE` statement returns an explanation, essentially revealing the execution plan to provide transparency and understanding of the query performance.
2. The records are not deleted.

`EXPLAIN` can be followed by `FULL` to see the number of executed rows.
12 changes: 11 additions & 1 deletion src/content/doc-surrealql/statements/update.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ UPDATE [ ONLY ] @targets
[ RETURN NONE | RETURN BEFORE | RETURN AFTER | RETURN DIFF | RETURN @statement_param, ... | RETURN VALUE @statement_param ]
[ TIMEOUT @duration ]
[ PARALLEL ]
[ EXPLAIN [ FULL ]]
;
```

Expand Down Expand Up @@ -474,4 +475,13 @@ UPDATE person

## UPDATE inside database exports

As `UPDATE` before version 2.0.0 used to create a specified record ID if it did not exist, it was used in the `.surql` files generated by the [`surreal export`](/docs/surrealdb/cli/export) command to export existing records in a database. As of version 2.0.0, the [`INSERT`](/docs/surrealql/statements/insert) statement is used instead.
As `UPDATE` before version 2.0.0 used to create a specified record ID if it did not exist, it was used in the `.surql` files generated by the [`surreal export`](/docs/surrealdb/cli/export) command to export existing records in a database. As of version 2.0.0, the [`INSERT`](/docs/surrealql/statements/insert) statement is used instead.

## The `EXPLAIN` clause

When `EXPLAIN` is used:

1. The `UPDATE` statement returns an explanation, essentially revealing the execution plan to provide transparency and understanding of the query performance.
2. The records are not updated.

`EXPLAIN` can be followed by `FULL` to see the number of executed rows.
10 changes: 10 additions & 0 deletions src/content/doc-surrealql/statements/upsert.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ UPSERT [ ONLY ] @targets
[ RETURN NONE | RETURN BEFORE | RETURN AFTER | RETURN DIFF | RETURN @statement_param, ... | RETURN VALUE @statement_param ]
[ TIMEOUT @duration ]
[ PARALLEL ]
[ EXPLAIN [ FULL ]]
;
```

Expand Down Expand Up @@ -517,3 +518,12 @@ When processing a large result set with many interconnected records, it is possi
```surql
UPSERT person:3 SET important = true WHERE ->knows->person->(knows WHERE influencer = true) TIMEOUT 5s;
```

## The `EXPLAIN` clause

When `EXPLAIN` is used:

1. The `UPSERT` statement returns an explanation, essentially revealing the execution plan to provide transparency and understanding of the query performance.
2. The records are not updated.

`EXPLAIN` can be followed by `FULL` to see the number of executed rows.
Loading