Files
Cornelius Boateng addf8f18e0 Merged PR 1592678: [engine][let] Support for delete
### 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` variables and `$$NOW` in delete queries.

The values of the variables can be accessed in the query by using `$expr`.
Example:
```
{
      delete: <collection>,
      deletes: [
            {
                q: {$expr: {$eq: ["$_id", "$$varRef"]}},
                limit: 0,  // multi
            }
      ],
      let: {"varRef": 1},
      ...
}
```

We parse the `let` value (together with the time system variables - `$$NOW`) and propagate it through the aggregation and variable contexts.

----
#### AI description  (iteration 1)
#### PR Classification
New feature

#### PR Summary
This pull request adds support for the `let` clause in delete operations.
- `delete.c`: Implemented logic to handle `let` clause in delete queries, including variable specification and collation.
- `bson_aggregation_pipeline_tests_let.out`: Added extensive test cases to validate the new `let` clause functionality in delete operations.
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->

Related work items: #3423118, #3613877
2025-05-29 12:12:31 +08:00

72 lines
2.4 KiB
C

/*-------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*
* include/planner/documentdb_plan_cache.h
*
* Common declarations for the pg_documentdb plan cache.
*
*-------------------------------------------------------------------------
*/
#ifndef BSON_PLAN_CACHE_H
#define BSON_PLAN_CACHE_H
#include <executor/spi.h>
/*
* ID prefixes for different types of query.
*
* The first 32 bits of a query ID are used to identity the operation,
* and the latter 32 bits to identify different query variants.
*/
#define QUERY_ID_INSERT (1L << 32)
#define QUERY_ID_UPDATE_BY_TID (2L << 32)
#define QUERY_ID_DELETE_BY_TID (3L << 32)
/* TODO: remove once we fully support let and collation with delete */
#define QUERY_DELETE_WITH_FILTER (4L << 32);
#define QUERY_DELETE_WITH_FILTER_SHARDKEY (5L << 32)
#define QUERY_DELETE_WITH_FILTER_ID (6L << 32)
#define QUERY_DELETE_WITH_FILTER_SHARDKEY_ID (7L << 32)
#define QUERY_CALL_UPDATE_ONE (8L << 32)
#define QUERY_DELETE_ONE (9L << 32)
#define QUERY_DELETE_ONE_ID (10L << 32)
#define QUERY_DELETE_ONE_ID_RETURN_DOCUMENT (11L << 32)
#define QUERY_UPDATE_SELECT_UPDATE_CANDIDATE (12L << 32)
#define QUERY_UPDATE_SELECT_UPDATE_CANDIDATE_NON_OBJECT_ID (13L << 32)
#define QUERY_UPDATE_SELECT_UPDATE_CANDIDATE_ONLY_OBJECT_ID (14L << 32)
#define QUERY_UPDATE_SELECT_UPDATE_CANDIDATE_BOTH_FILTER (15L << 32)
#define QUERY_ID_RETRY_RECORD_INSERT (20L << 32)
#define QUERY_ID_RETRY_RECORD_DELETE (21L << 32)
#define QUERY_ID_RETRY_RECORD_SELECT (22L << 32)
#define QUERY_ID_INSERT_OR_REPLACE (23L << 32)
#define QUERY_DELETE_WITH_FILTER_LET_AND_COLLATION (30L << 32)
#define QUERY_DELETE_WITH_FILTER_SHARDKEY_LET_AND_COLLATION (31L << 32)
#define QUERY_DELETE_WITH_FILTER_ID_LET_AND_COLLATION (32L << 32)
#define QUERY_DELETE_WITH_FILTER_SHARDKEY_ID_LET_AND_COLLATION (33L << 32)
#define QUERY_DELETE_ONE_LET_AND_COLLATION (34L << 32)
#define QUERY_DELETE_ONE_ID_LET_AND_COLLATION (35L << 32)
/* GUC that controls the query plan cache size */
extern int QueryPlanCacheSizeLimit;
void InitializeQueryPlanCache(void);
SPIPlanPtr GetSPIQueryPlan(uint64 collectionId, uint64 queryId,
const char *query, Oid *argTypes, int argCount);
SPIPlanPtr GetSPIQueryPlanWithLocalShard(uint64 collectionId, const char *shardTableName,
uint64 queryId,
const char *query, Oid *argTypes, int argCount);
#endif