mirror of
https://github.com/FerretDB/documentdb.git
synced 2026-11-07 03:22:46 -05:00
### Does this PR have any customer impact? No
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc) Feature
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes) No
### Are you introducing any new config? If yes, do you have tests with and without them being set? No
### ChangeLog (Refer [Template](../oss/CHANGELOG.md))
### Description
Support let and `$$NOW` variables with update queries.
The values of the variables can be accessed in the query `q` with `$expr` and 'u' with an aggregation pipeline.
Example:
```
{
update: <collection>,
updates: [
{
q: {$expr: {$eq: ["$_id", "$$varRef"]}},
u: [{$set: {"a": "$$NOW"}}],
multi: false, // updateOne
}
],
let: {"varRef": 1},
...
}
```
We parse the let value (together with the time system variables - $$NOW) and propagate it through the aggregation and variable contexts.
To enable feature, turn on the `EnableVariablesSupportForWriteCommands` GUC.
----
#### AI description (iteration 1)
#### PR Classification
This PR implements a new feature by adding support for the "let" variable specification in update commands.
#### PR Summary
The changes integrate "let" support into update operations, allowing dynamic variable specifications to be applied during update candidate selection, serialization, and execution. This enhancement improves the flexibility and expressiveness of update queries in the engine.
- In `src/commands/update.c`, the code now parses and applies a new `variableSpec` (under the "let" field) when building update queries and managing SQL arguments.
- In `include/infrastructure/documentdb_plan_cache.h`, new plan cache macros are added to account for update candidates using let and collation.
- In `include/commands/update.h`, the `UpdateOneParams` structure is updated to include the `variableSpec` parameter.
- In `src/commands/delete.c`, references to the unsupported "let" field in delete commands are removed.
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
Related work items: #3423115, #3613875