### Does this PR have any customer impact?
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
### Are you introducing any new config? If yes, do you have tests with and without them being set?
### ChangeLog (Refer [Template](../oss/CHANGELOG.md))
### Description
Code cleanup and documentation updates to match contribution guidelines
----
#### AI description (iteration 1)
#### PR Classification
This pull request is a code cleanup and documentation update.
#### PR Summary
The updates refine inline comments and documentation across update, error handling, and collation components to improve clarity and consistency, while replacing obsolete Mongo references with DocumentDB terminology. Key changes include:
- **`oss/pg_documentdb/src/update/bson_update_operators.c`**: Revised comments for update operators (e.g., `$currentDate`, `$push`, `$mul`) to clarify behavior and update examples.
- **`oss/pg_documentdb/src/utils/error_utils.c`**: Updated documentation to reference DocumentDB errors instead of Mongo errors.
- **`oss/pg_documentdb/src/update/bson_update.c` and `oss/pg_documentdb/src/update/bson_update_aggregation.c`**: Improved inline comment wording to accurately describe update specifications and error conditions.
- **`oss/pg_documentdb_core/src/collation/collation.c`**: Cleaned up collation conversion comments and locale handling explanations.
- **Test files under `oss/internal/pg_documentdb_distributed/src/test` and `pgmongo/src/test/docdb_compat/expected`**: Updated expected output comments to align with the revised error message tests.
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
### Does this PR have any customer impact?
No
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Refactor
### 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
Fix up docs across some files to match contributing guidelines.
----
#### AI description (iteration 1)
#### PR Classification
This PR focuses on documentation improvements and in-code comment cleanup to comply with contributing guidelines.
#### PR Summary
The pull request refines comment texts and error messages across several source files, removes unused code documentation, and updates internal clarifications.
- `oss/pg_documentdb/src/aggregation/bson_aggregates.c`: Removed the unused `BsonOutAggregateState` typedef and updated aggregation comments (e.g., changing "HASHTBL" to "HASHCTL") while eliminating redundant code comments.
- `oss/pg_documentdb/src/commands/create_collection_view.c`: Removed several unused fields from the `CreateSpec` structure and updated header comments to reflect the correct file path.
- `oss/pg_documentdb/src/aggregation/bson_aggregation_pipeline.c`: Revised comment formatting and error messages in aggregation and query generation functions to ensure consistent terminology.
- `oss/pg_documentdb/src/auth/scram256.c` & `oss/pg_documentdb/src/commands/update.c`: Updated documentation comments for authentication responses and update error handling for improved clarity.
- Other files in `/oss/pg_documentdb/src/opclass/` and `/oss/pg_documentdb_core/`: Corrected typographical errors and adjusted error code references to align with the project’s guidelines.
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
### Does this PR have any customer impact?
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
### Are you introducing any new config? If yes, do you have tests with and without them being set?
### ChangeLog (Refer [Template](../oss/CHANGELOG.md))
### Description
One NodeJS test cases was failing when running against the rust GW since we were not handling the case where the index is too long.
----
#### AI description (iteration 1)
#### PR Classification
Bug fix addressing error handling during index creation.
#### PR Summary
The pull request improves how over-sized index creation errors are handled by introducing explicit checks and returning a clearer error message.
- In `src/responses/pg.rs`: Added a conditional branch that detects when the error message contains "index row size" and "exceeds maximum" to return a specific error code with the message "Index key is too large."
- In `src/error.rs`: Introduced a new error variant `CannotBuildIndexKeys` with code 201 to support the enhanced error handling.
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
### Does this PR have any customer impact?
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
### Are you introducing any new config? If yes, do you have tests with and without them being set?
### ChangeLog (Refer [Template](../oss/CHANGELOG.md))
### Description
3 c files
----
#### AI description (iteration 1)
#### PR Classification
This pull request focuses on code cleanup and documentation updates.
#### PR Summary
The changes standardize and simplify documentation comments and examples across several operator implementations, removing obsolete references and unnecessary details.
- `oss/pg_documentdb/src/aggregation/bson_aggregation_output_pipeline.c`: Updated doc examples for `$merge` and `$out` to use generic placeholders and removed temporary test-related comments.
- `oss/pg_documentdb/src/query/bson_dollar_operators.c`: Cleaned up comments for multiple BSON dollar operators by eliminating "Mongo's" references and redundant test notes.
- `oss/pg_documentdb_core/src/types/pcre_regex.c`: Refined regex compile option comments and removed legacy test reference lines.
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
### Does this PR have any customer impact?
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
### Are you introducing any new config? If yes, do you have tests with and without them being set?
### ChangeLog (Refer [Template](../oss/CHANGELOG.md))
### Description
When using mongodb-driver-sync 4.0.6, and performing a query, the namespace in the request looks like "<db>.$cmd" compared to other version where it is "admin.$cmd". To accommodate this version, we just check if the collection name equals $cmd which is similar to what we do in the other Gateway
----
#### AI description (iteration 1)
#### PR Classification
This PR implements an API update and bug fix to correctly handle OP_QUERY messages for Java driver 4.0.6.
#### PR Summary
The pull request refines the query parsing logic by extracting the collection name from the namespace instead of using the full collection path, ensuring that command queries are accurately identified and unsupported queries are logged.
- In `oss/pg_documentdb_gw/src/protocol/reader.rs`, the code now extracts a tuple (_db, collection_name) from the namespace.
- The condition to detect command messages is simplified to check if `collection_name` equals "$cmd".
- An informational log is added to print the collection name when OP_QUERY is unsupported.
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
### Does this PR have any customer impact?
no
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
parity
### 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
1. Implement unshardCollection command
2. Do the logical separation inside the `process.rs`
Related work items: #4306635
### Does this PR have any customer impact?
yes
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
feature + refactoring
### 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
Finish the work on the query processing logic separation. This pull request is a design and architectural enhancement that finalizes query processing separation in the Rust gateway.
**For more details see the author comment.**
Related work items: #3666511
### Does this PR have any customer impact?
Yes
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Performance
### 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?
Yes
### ChangeLog (Refer [Template](../oss/CHANGELOG.md))
### Description
Currently, each round of the sproc that does create indexes does exactly 1 index build and bails. This means if a single client request queues 4 indexes and the job runs every 2 seconds, it'll take 8 seconds to build all 4 indexes. This is wasteful since we know all 4 indexes up front.
Add a loop to the index build process so that multiple indexes can be built without waiting the 2 seconds.
As part of this, there were a few places allocating in memory contexts that are unstable across executions. Fix this.
Additionally there was a loop that could cause index builds to starve for ~20 mins if it picked the wrong index. Fix this loop too.
Finally, Noticed that the version cache does not cache properly if the Major version is 0. Fix this (which can cause perf regressions in DocumentDB).
### Does this PR have any customer impact?
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
### Are you introducing any new config? If yes, do you have tests with and without them being set?
### ChangeLog (Refer [Template](../oss/CHANGELOG.md))
### Description
[OSS] fix 0.104-1 hotfix upgrade scripts
----
#### AI description (iteration 1)
#### PR Classification
Hotfix update to upgrade SQL upgrade scripts correcting version references.
#### PR Summary
This pull request updates SQL upgrade scripts to use the correct UDF and documentdb version numbers.
- In `pgmongo/sql/pgmongo--1.103-0--1.103-1.sql`, the include directive was updated from version 0.105-0 to 0.104-1.
- In `oss/pg_documentdb/sql/documentdb--0.104-0--0.104-1.sql`, the UDF include reference was changed to use version 0.104-1.
- The file `oss/pg_documentdb/sql/documentdb--0.104-0--0.105-0.sql` was moved to `oss/pg_documentdb/sql/documentdb--0.104-1--0.105-0.sql` with no code changes.
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
### Does this PR have any customer impact?
Yes
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Feature
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
Yes, the API schema
### 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))
1.05
### Description
We are adding support for the Connection Status command, which exists in native Mongo, and allows users to see their authenticated user, authenticated roles, and user privileges. For more information, visit connectionStatus.md.
This PR is the second of three PRs for this feature. The first one added extensible role privileges to our `users_info` command, allowing users to retrieve role privileges with `showPrivileges: true`. This second PR adds a callable `connection_status` command to our API, that utilizes the role privileges. The last PR will add a gateway change that calls this `connection_status` command.
Related work items: #4287246
### Does this PR have any customer impact?
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
### Are you introducing any new config? If yes, do you have tests with and without them being set?
### ChangeLog (Refer [Template](../oss/CHANGELOG.md))
### Description
----
#### AI description (iteration 1)
#### PR Classification
Enhancement and bug fix to improve the stability and management of file-based cursors.
#### PR Summary
This pull request refactors and bolsters file-based cursor management by introducing shared memory support, improved cleanup, error handling, and configuration changes. It also adds new API endpoints and logging for better cursor lifecycle control.
- **`cursor_store.c` and related files:** Added shared memory functions (e.g., `FileCursorShmemSize`, `InitializeFileCursorShmem`), cursor count regulation (with `IncrementCursorCount`/`DecrementCursorCount`), and cleanup routines to ensure stable cursor file operations.
- **Test and expected output files:** Updated regression tests and expected outputs to cover scenarios like duplicate cursor creation, cursor deletion limits, and error reporting when the file cursor capacity is reached.
- **API enhancements:** Introduced new UDFs (e.g., `command_delete_cursors`) and tenant client methods for killing and deleting cursors, improving session management.
- **Configuration updates:** Renamed and added GUC parameters (e.g., `MaxAllowedCursorIntermediateFileSizeMB`, `MaxCursorFileCount`, and cursor expiry settings) to control file-based cursor behavior.
- **Logging and metrics improvements:** Enhanced logging in `mdsd_logger.c` to report current cursor counts and related metrics for operational insight.
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
### Does this PR have any customer impact?
Yes
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Constraint
### 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
Change streams does not support rebalancing at the moment
Related work items: #4116549
### Does this PR have any customer impact?
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
### Are you introducing any new config? If yes, do you have tests with and without them being set?
### ChangeLog (Refer [Template](../oss/CHANGELOG.md))
### Description
update changelog
----
#### AI description (iteration 1)
#### PR Classification
This pull request is a documentation update focused on revising changelog entries to reflect the latest documentdb release.
#### PR Summary
The changes update two changelog files to record the new release details and feature updates.
- `oss/packaging/debian_files/changelog`: Adjusted the documentdb version to v0.104-0 with updated urgency, revised the bullet list with new features, bug fixes, and performance enhancements, and added a historical section for v0.103-0.
- `oss/CHANGELOG.md`: Updated the documentdb v0.104-0 header from "Unreleased" to a released version with the date June 09, 2025.
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
### Does this PR have any customer impact?
no
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
refactoring
### 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
Define common interface for all user-related pg queries to be executed as part of the PgDataClient trait
Related work items: #3666511
### Does this PR have any customer impact?
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
### Are you introducing any new config? If yes, do you have tests with and without them being set?
### ChangeLog (Refer [Template](../oss/CHANGELOG.md))
### Description
Removing unnecessary in/out from bson_update_document which were preset eariler due to older change_stream implementation.
1. For now moving udf to helio_api_internal and same time removing useless in/out params
TODO:
In next release will modify this for oss with updating test and minimal c changes will update --latest files also.
----
#### AI description (iteration 1)
#### PR Classification
This pull request is a code cleanup and update to simplify the integration of the `bson_update_document` function into OSS.
#### PR Summary
The PR introduces a new C-based SQL function for `bson_update_document` with streamlined parameters, updates the main SQL script to include this new file, and refreshes the API schema output to reflect the change.
- `pgmongo/sql/udfs/crud/bson_update_document--1.105-0.sql`: Adds the new function definition with cleaned-up parameter handling.
- `pgmongo/sql/pgmongo--1.104-0--1.105-0.sql`: Updates the script to include the newly added UDF file.
- `pgmongo/src/test/regress/expected/public_api_schema.out`: Modifies the schema output to include the new function entry.
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
### Does this PR have any customer impact?
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
### Are you introducing any new config? If yes, do you have tests with and without them being set?
### ChangeLog (Refer [Template](../oss/CHANGELOG.md))
### Description
setting guc enableDataTableWithoutCreationTime to on so that all the new tables will not have creation_time column
----
#### AI description (iteration 1)
#### PR Classification
This pull request is a new feature change that enables omitting the creation_time field from query results.
#### PR Summary
The PR updates the behavior of the system by setting the GUC flag enableDataTableWithoutCreationTime to true, so that output from various commands no longer includes the creation_time column.
- In `configs/feature_flag_configs.c`, the default for enableDataTableWithoutCreationTime is switched to true.
- Expected output files in multiple test folders (`oss/pg_documentdb`, `oss/internal/pg_documentdb_distributed`, and `pgmongo`) have been revised to remove the creation_time field.
- Test SQL scripts have been updated to set the flag as needed, ensuring consistency between the new behavior and test expectations.
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
### Does this PR have any customer impact?
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
### Are you introducing any new config? If yes, do you have tests with and without them being set?
### ChangeLog (Refer [Template](../oss/CHANGELOG.md))
### Description
Add support of altrernate index handler in 1.103
### 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
`deleteOne` requires `_id` or shard key value filter. If only `_id` is used, we query for the minimum shard key value and use it.
The querying for that shard key must be able to use the `variableSpec`.
----
#### AI description (iteration 1)
#### PR Classification
API change to enable proper handling of deleteOne commands on sharded collections using only an _id filter by incorporating variable specification support.
#### PR Summary
This pull request enhances deleteOne functionality by integrating a variableSpec (let variable) into query construction for sharded collections, ensuring that _id-only filters are handled correctly. The changes update core command functions, test expectations, and configuration flags to support the new behavior.
- **`commands_common.c`**: Revised the `FindShardKeyValueForDocumentId` function to accept a new variableSpec parameter and conditionally modify the query.
- **`delete.c` and `update.c`**: Updated deletion and update operations to process the variableSpec for write commands.
- **Test and Configuration Files**: Renamed and updated GUC flags (from enableLet... to enableVariablesAndCollationSupportForQueryMatch) and adjusted expected outputs to reflect the new deleteOne behavior.
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
### Does this PR have any customer impact?
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
### Are you introducing any new config? If yes, do you have tests with and without them being set?
### ChangeLog (Refer [Template](../oss/CHANGELOG.md))
### Description
----
#### AI description (iteration 1)
#### PR Classification
This pull request implements a new feature that enhances explain plan output and composite index functionality by adding order‑by pushdown and related index option validations.
#### PR Summary
The changes add new metrics in explain plans and strengthen composite index handling for order-by pushdown across the system. Key changes include:
- **`/gateway/managed/Mongo.Service.Postgres/Helpers/PostgresExplainHelper.cs` & `/oss/pg_documentdb_gw/src/explain/mod.rs`** – Added fields like `sortKeysCount`, `sortKey`, `presortedKey(s)`, and `hasOrderBy` to enhance explain output.
- **`/oss/pg_documentdb/src/metadata/index.c` and related index management files** – Implemented improved composite index option checks and support functions such as `CompositeIndexSupportsOrderByPushdown` and equality-range predicate validation.
- **UDF and operator files (e.g., `bson_dollar_comparison--*.sql`, `/oss/pg_documentdb/src/query/bson_dollar_operators.c`)** – Introduced new functions like `bson_dollar_fullscan` to support full scan pushdowns in combination with composite indexes.
- **`/pgmongo_rum/src/rumget.c`** – Enhanced ordered scan handling and duplicate management for multi-key indexes.
- **Pipeline and configuration files (e.g., `.pipelines/templates/single_node_tests.yml`)** – Updated test scripts and experimental configuration parameters to enable the new composite opclass and order‑by pushdown features.
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
### Does this PR have any customer impact?
Yes
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Bugfix
### 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
[DocumentDB issus 178](https://github.com/microsoft/documentdb/issues/178)
When the document size exceeds 2000, the tuple is toasted. We need to detoast the datum before converting it to pgbson.
----
#### AI description (iteration 1)
#### PR Classification
Bug fix addressing improper detoasting of pgbson values.
#### PR Summary
This pull request replaces direct pointer extraction and SPI_datumTransfer calls with dedicated DatumGetPgBson macros to ensure both toasted and non-toasted bson documents are correctly handled. It also enhances test coverage for find-and-modify operations on large documents.
- `commands_find_and_modify.out` and SQL test files: Added new queries for deleting large (toasted) and non-toasted documents.
- `retryable_writes.c`, `delete.c`, metadata, index, and query operator files: Replaced manual SPI_datumTransfer and DatumGetPointer calls with DatumGetPgBson (and DatumGetPgBson_MAYBE_NULL) to properly detoast and copy pgbson objects.
- `pgbson.h` and `bson_io.c`: Introduced and integrated new macros to streamline detoasting of pgbson data.
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
### Does this PR have any customer impact?
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
### Are you introducing any new config? If yes, do you have tests with and without them being set?
### ChangeLog (Refer [Template](../oss/CHANGELOG.md))
### Description
This change allows us to swap between C# and Rust gateways by setting the pgmongo.use_rust_native_gateway GUC on and off without depending on Flex "outside" restarts and trigger the restart at runtime.
We read the value of the GUC and if it doesn't match the running gateway, we gracefully shut it down. Upon restart by Docker, C# flow will be executed and StartupHost.sh will be executed. Since the GUC, pgmongo.use_rust_native_gateway, will also be set in a config file, and that will mandate the gateway to actually start up.
This change was validated against a dev cluster by setting the GUC on and off
----
#### AI description (iteration 1)
#### PR Classification
This pull request introduces a new mechanism for runtime gateway switching, enabling a graceful shutdown of the C# gateway to transition to a Rust gateway.
#### PR Summary
The changes implement a unified shutdown mechanism that allows the service to detect a configuration flag for using the Rust native gateway and to trigger a graceful shutdown accordingly.
- **`Compute.Host/HostShutdown.cs`**: Added a new static class that provides a shutdown task and trigger method.
- **`Compute.Host/HostServiceContainer.cs`**: Introduced a configuration check for the "use_rust_native_gateway" flag that triggers shutdown via the new mechanism.
- **`Host.Postgres.Linux/PostgresMongoServiceHost.cs`**: Updated shutdown and signal handling to use the new HostShutdown mechanism, replacing the previous ctrl-break task approach.
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
### Does this PR have any customer impact?
Yes
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Feature
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
Yes
### Are you introducing any new config? If yes, do you have tests with and without them being set?
Yes
### ChangeLog (Refer [Template](../oss/CHANGELOG.md))
### Description
More general improvements to order by and composite:
Create Indexes
1) Support creating a composite index side by side with a regular index
2) Block creation of descending or wildcard and unsupported set ups for composite indexes
Planner:
1) Support ordering by the Nth path of an index if the prefixes are equality.
2) Validate that if it's not the first column, prefixes are provided
3) Support incremental sort with index pushdown.
----
#### AI description (iteration 1)
#### PR Classification
This pull request delivers a new feature and API enhancement to enable order-by index pushdown and refined composite index support.
#### PR Summary
The update streamlines composite index processing by introducing stricter equivalency checks, new UDF functions for full-scan order-by pushdown, and enhanced validations during index creation while updating explain outputs and tests.
- `src/metadata/index.c` refines index options equivalency logic to correctly compare composite term settings.
- `src/opclass/bson_gin_composite_entrypoint.c` and `src/index_am/rum.c` add functions to support order-by pushdown and manage duplicate entries efficiently.
- `sql/udfs/query/bson_dollar_comparison--0.105-0.sql` (and related operator files) introduce new UDFs including `bson_dollar_fullscan` to enable full scan operations.
- `src/commands/create_indexes.c` enforces new composite index validations (restricting use to ascending, non-wildcard regular indexes) with precise error reporting.
- Test scripts and explain plan outputs in the `regress` and `pgmongo` directories are updated to confirm the new composite order-by behavior.
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
### Does this PR have any customer impact?
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
### Are you introducing any new config? If yes, do you have tests with and without them being set?
### ChangeLog (Refer [Template](../oss/CHANGELOG.md))
### Description
more
----
#### AI description (iteration 1)
#### PR Classification
Performance optimization.
#### PR Summary
This PR eliminates an unnecessary memory allocation during BSON parsing by omitting the call to `pstrdup` for the collation string.
- `/oss/pg_documentdb_core/src/io/pgbsonelement.c`: Replaced `pstrdup(bson_iter_utf8(&iter, NULL))` with a direct pointer assignment from `bson_iter_utf8(&iter, NULL)`.
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
### Does this PR have any customer impact?
Yes
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Bugfix
### 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))
- Fix $match filters not applied after preserving null on $lookup and $unwind combinations
### Description
This fixes the OSS issue: https://github.com/microsoft/documentdb/issues/198
- Starting PG 16 the the right join query that will have NULL results need to assign `varnullingrels` index of RTE which can replace the NULL values for outer JOIN conditions, if the VAR expression is a result of JOIN.
This is seen as the diff in the parse plan of not working and working case of the same query in PG 16

The final query described in the bug has below format and the last `WHERE` filter can merge with the inner right query if `varnullingrels` is not specified which yields incorrect results
```SQL
SELECT document
FROM ( WITT debug_print_parse to on;
LECT document
FROM ( WITH "lookupLeftCte_0" AS (
SELECT collection.document,
bson_dollar_lookup_extract_filter_expression(collection.document, '{ "name" : "author" }'::bson) AS lookup_filter
FROM documentdb_data.documents_3 collection
WHERE collection.shard_key_value = '3'::bigint
)
SELECT bson_dollar_merge_documents_at_path(lookup_stage_1.document, COALESCE("lookupRight_stage_1".document, '{ }'::bson), 'author-names'::text) AS document
FROM "lookupLeftCte_0" lookup_stage_1
LEFT JOIN LATERAL ( WITH lookup_right_query AS (
SELECT collection_0_1.document
FROM documentdb_data.documents_2 collection_0_1
WHERE collection_0_1.shard_key_value = '2'::bigint
)
SELECT lookup_right_query_stage_0.document
FROM lookup_right_query lookup_right_query_stage_0
WHERE bson_dollar_lookup_join_filter(lookup_right_query_stage_0.document, lookup_stage_1.lookup_filter, 'name'::text)) "lookupRight_stage_1" ON true) agg_stage_1
WHERE document #= '{ "title" : "Emma" }'::bsonquery;
```
----
#### AI description (iteration 1)
#### PR Classification
Bug fix addressing the incorrect application of match filters in aggregation pipelines combining $lookup and $unwind stages.
#### PR Summary
This pull request fixes the issue by updating the aggregation pipeline processing logic for null-preserving $lookup/$unwind operations and enhancing test coverage to verify correct filtering.
- **`oss/p...
* first commit
* update action
* fix
* fix
* test push
* test push
* test push
* test push
* test push
* test push
* add lables
* update tag
* clean up
* try to resolve unknown/unknown
* clean up
* test sign
* clean up
* update action name
* fix bug
* clean up
---------
Co-authored-by: root <root@CPC-yangq-FRSGK>
### Does this PR have any customer impact?
Unblock customer using mongoimport with 8.0 cluster
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Bugfix
### 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))
N/A
### Description
In the [ticket](https://portal.microsofticm.com/imp/v5/incidents/details/627206133/summary), cx reported an error while using mongoimport with 8.0 cluster
There might be typo in cx's statement, as we have ignored startTransaction in our code. However, the mongoimport does fail with 8.0 cluster, with error saying "Failed: (UnknownBsonField) BSON field 'insert.bypassEmptyTsReplacement' is an unknown field"

bypassEmptyTsReplacement was [introduced in mongo 5.0](https://www.mongodb.com/docs/manual/release-notes/5.0/#:~:text=SERVER%2D88750%20Add%20%22bypassEmptyTsReplacement%22%20param%20to%20insert%2C%20update%2C%20findAndModify%2C%20and%20bulkWrite).
It seems mongoimport add `bypassEmptyTsReplacement` field for 8.0 clusters, which leads to insertion failure with vCore 8.0 version but not on 7.0
This PR adds bypassEmptyTsReplacement to ignore field to unblock cx from using mongoimport
----
#### AI description (iteration 1)
#### PR Classification
This pull request implements a new feature to support mongoimport in mongo8.0.
#### PR Summary
The update adds the "bypassEmptyTsReplacement" field to the list of ignored fields in the `oss/pg_documentdb/src/commands/commands_common.c` file, ensuring compatibility for insert, update, findAndModify, and bulkWrite commands when using mongoimport.
- `oss/pg_documentdb/src/commands/commands_common.c`: Inserted "bypassEmptyTsReplacement" into the ignore list for relevant commands.
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
### Does this PR have any customer impact?
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
### Are you introducing any new config? If yes, do you have tests with and without them being set?
### ChangeLog (Refer [Template](../oss/CHANGELOG.md))
### Description
Move bucketAuto to schema 105
----
#### AI description (iteration 1)
#### PR Classification
This pull request introduces a schema migration for the `$bucketAuto` aggregation stage, moving its support from schema 104 to schema 105.
#### PR Summary
The changes update documentation, SQL scripts, and test configuration to reflect the migration of `$bucketAuto` support to the new schema.
- `pgmongo/sql/pgmongo--1.104-0--1.105-0.sql`: Added inclusion of the new `$bucketAuto` UDF file for schema 105.
- `oss/pg_documentdb/sql/documentdb--0.104-0--0.105-0.sql`: New file added to include `$bucketAuto` support for the updated schema.
- `oss/CHANGELOG.md` and release notes files: Updated to move the `$bucketAuto` aggregation stage support from the previous schema version to the new release notes for schema 105.
- Several test CSV files under `/gateway/managed/Tests.Integration.Shell.Postgres` were updated to reflect the new schema version.
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
### Does this PR have any customer impact?
No
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Bugfix
### 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
Change default for localhost to false
----
#### AI description (iteration 1)
#### PR Classification
This pull request is a configuration change that updates the default behavior for local host usage.
#### PR Summary
The changes modify the configuration setup to return false by default for using localhost, ensuring that the application does not use the local host unless explicitly configured.
- `oss/pg_documentdb_gw/src/configuration/setup.rs`: Changed the `use_local_host` method to use `unwrap_or(false)` instead of `unwrap_or(true)`.
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
### Does this PR have any customer impact?
Yes
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Bugfix
### 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?
Yes
### ChangeLog (Refer [Template](../oss/CHANGELOG.md))
### Description
In a distributed set up, shard keys specified with $and/$eq/$or were tracked but not $in. This adds support for $in as well in pushdown.
----
#### AI description (iteration 1)
#### PR Classification
New feature to enhance sharding by supporting pushdown of queries with shard keys specified using the $in operator.
#### PR Summary
This pull request extends the sharding logic to process $in operator predicates for shard keys, optimizing query routing and pushdown.
- `oss/pg_documentdb/src/sharding/sharding.c`: Added new helper functions (e.g., FindShardKeyValuesExprPhase1, ConsiderShardKeyFiltersForInClauses, and FindShardKeyValuesExprNew) and refactored shard key handling to use a new `ShardKeyMetadata` structure with updated `setCount` tracking.
- `oss/pg_documentdb/src/configs/feature_flag_configs.c`: Introduced the `UseNewShardKeyCalculation` flag to enable the new shard key calculation logic.
- Test files and SQL regression scripts: Updated expected outputs and queries to validate the new $in operator support for shard key pushdown.
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
### Does this PR have any customer impact?
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
### Are you introducing any new config? If yes, do you have tests with and without them being set?
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
This pull request adds documentation for the `$bucketAuto` aggregation stage in PostgreSQL, detailing its design, usage, and implementation.
- Adds `bucketAuto.md` with details on the `$bucketAuto` aggregation stage
- code implementation
- support all granularity types: POWERSOF2, 1-2-5, Renard numbers, E series
Related work items: #3234185
### Does this PR have any customer impact?
Yes
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Bugfix/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?
Yes
### ChangeLog (Refer [Template](../oss/CHANGELOG.md))
### Description
1) Orderby on null/undefined documents was incorrect - fix up the ordering
2) Equality on null/undefined was also incorrect fix this up
3) When traversing the document, we were doing an extra traversal into arrays when it was not needed. fix this up
4) Order by on composite index didn't handle nulls correctly - fix this too.
5) Support pushdown of $elemMatch into composite indexes without array terms.
----
#### AI description (iteration 1)
#### PR Classification
This pull request fixes bugs in the composite index and orderby functionality.
#### PR Summary
The changes correct the orderby comparison logic and improve composite index term generation in BSON processing. The pull request also adds new functions to handle intermediate array paths and introduces legacy behavior flags, while supplementing the fixes with comprehensive integration tests.
- **`src/query/bson_dollar_operators.c`**: Modified `OrderByVisitArrayField` to pass the correct BSON value and added new functions for array path handling.
- **`src/opclass/gin_index_term.c` and related opclass files**: Introduced `GenerateValueMaybeUndefinedTerm` and updated index term comparison to distinguish between undefined and partially undefined values.
- **`pgbson_utils.c`**: Adjusted array traversal logic with a new callback for missing intermediate array paths and a flag to control array traverse optimization.
- **Test files under `/oss/pg_documentdb/src/test/regress/expected/` and `/pgmongo/src/test/regress/expected/`**: Added extensive composite ordering and filtering tests to validate the corrected behavior.
- **`configs/feature_flag_configs.c`**: Added custom GUCs for `useLegacyOrderByBehavior` and `useLegacyNullEqualityBehavior` to manage legacy ordering and null equality rules.
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
### Does this PR have any customer impact?
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
### Are you introducing any new config? If yes, do you have tests with and without them being set?
### ChangeLog (Refer [Template](../oss/CHANGELOG.md))
### Description
Upgrading toolchain to remove warnings in PR gates. "Installing an old toolchain, please consider upgrading. Latest available toolchain for v1 is 1.87."
Tested locally in dev container to make sure the gateway started and there were no cargo dependency issues
----
#### AI description (iteration 1)
#### PR Classification
Toolchain upgrade to address warnings in PR gates.
#### PR Summary
This pull request updates the Rust toolchain version used in both the development container and pipeline configuration to maintain consistency and eliminate warning messages.
- `/.devcontainer/Dockerfile`: Updated the MSRUSTUP_TOOLCHAIN from ms-1.84.1 to ms-1.87.0.
- `/.pipelines/templates/common_variables.yml`: Set RustToolchainVersion to ms-1.87.0.
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
### Does this PR have any customer impact?
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
### Are you introducing any new config? If yes, do you have tests with and without them being set?
### ChangeLog (Refer [Template](../oss/CHANGELOG.md))
### Description
Version update for 104
Related work items: #4281831
### Does this PR have any customer impact?
Not yet
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Feature/POC
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
Yes
### 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
This adds more changes for orderby support in the index
1) Fixes the correctness issue arising from indexing arrays for order by - we remove the top level array term from indexing. To handle this, we move the query operators to support querying the index correctly when the query is on an array
2) For `$elemMatch` this temporarily makes elemMatch just a full scan for now (a subsequent change wil tackle updating the logic)
3) Adds orderby to the top level schema for the internal extension
4) For exists false/true, we were pushing a lot more terms to the runtime recheck. Ensure that we're hitting the right index terms and evaluate correctly against the index.
----
#### AI description (iteration 1)
#### PR Classification
This pull request is a code cleanup and enhancement that removes array term generation for composite indexes and updates related index term handling.
#### PR Summary
The changes streamline composite index generation by eliminating dedicated array terms, and they adjust boundary, metadata, and recheck logic to ensure consistent behavior. Key updates include:
- **`oss/pg_documentdb/src/opclass/bson_gin_composite_core.c`**: Removed redundant array term generation and introduced functions like `SetArrayEqualityBound` to properly handle equality bounds for arrays.
- **`oss/pg_documentdb/src/opclass/gin_index_term.c`**: Updated index term serialization and metadata management (including handling of undefined values via `GenerateValueUndefinedTerm`) to align with the new composite index behavior.
- **Test and expected output files**: Revised expected composite index term outputs and SQL tests to reflect the removal of array-specific terms.
- **Documentation and configuration**: Updated design docs and removed the configuration flag for skipping array term generation, consolidating the new composite index strategy.
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
### Does this PR have any customer impact?
No
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
Yes
### 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))
Adding support for custom index handler.
### Description
Adding support for custom index handler. Currently the default index access method to index bson data type is "rum". This change allows one to swap out "rum" for something else.
The use an alternate index handler one needs to specify two things
1. Firstly, register the index handler and its capabilities and relevant utility call backs. Currently, the system only allows a maximum of 5 alternate index handler.
2. Secondly, set the alternate_index_handler GUC to let the system chose the alternate index handler to index bson.
Following are a few notes on the mechanism
1. During index create if the alternate AM does not support certain kind of bson index (e.g, unique index, wildcard index) then the index is created via the default rum index. Otherwise, the alternate AM is chosen.
2. If an index has been created using alternate index AM but then reset the alternate_index_handler GUC or set it to another third alternate index AM, the old alternate index AM will still be in use, and long as both the old and new alternate index AM are in the registry.
Other: Fixed Densify and SetWindow fields flakey tests for sharded collection
----
Related work items: #3796361
### Does this PR have any customer impact?
Yes
### 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
We've implemented several key improvements to DocumentDB's user management system, with a focus on enhancing the `usersInfo` command to support privilege information display.
### Feature Overview
- Added support for the `showPrivileges` flag in `usersInfo` command
- When enabled, user information responses now include detailed privilege documents
- Privileges are organized by resource and action, similar to MongoDB's privilege format
### Implementation Details
1. **Privilege Data Structures**
- Created predefined privilege sets for each role type (readOnly, readWrite, clusterAdmin)
- Designed efficient merging of privilege sets with hash-based deduplication
2. **GUC Configuration**
- Added `EnableUsersInfoPrivileges` boolean GUC to control feature availability
3. **Command Flow**
- Parse `showPrivileges` flag from incoming BSON documents
- When flag is true and GUC is enabled, append privilege array to user documents
- Privileges include resource targets (cluster/database/collection) and action lists
4. **Memory Optimization**
- Implemented hash-based privilege merging to avoid duplicate entries
- Proper memory management with PostgreSQL allocation functions
This functionality supports the `connectionStatus` command, which requires authenticated user privileges.
We will also support `dbowner` and `root` roles, which will come in a follow-up PR.
Related work items: #3852887
### Does this PR have any customer impact?
Nothing negative
### 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))
Support Mongo version 8 in pg_documentdb_gw *[Feature]*
### Description
Add mongo 8 to list on version.rs
----
#### AI description (iteration 1)
#### PR Classification
This pull request is an enhancement, adding native support for Mongo 8.
#### PR Summary
The changes update versioning in the OSS gateway to support Mongo 8 by extending the existing enum and its associated conversion methods.
- `oss/pg_documentdb_gw/src/configuration/version.rs`: Added the `Eight` variant to the enum and updated methods to parse "8.0", return `"8.0.0"`, provide the version tuple `[8, 0, 0, 0]`, and assign the corresponding numerical value.
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
Related work items: #4094504
Yes
Feature
Yes
No
- Support compact database administration command behind the GUC `enableCompact`.
- Add support for compact command in backend using VACUUM FULL which is a blocking operation.
- Only one compact command can be run at a time on a specified collection.
- VACUUM FULL is run using libpq in a top level transaction as it it not supported inside functions or procedures.
- Add support of tracking compact command in current_op.
- `dryRun` estimation is based on the query defined [here at pgexperts](https://github.com/pgexperts/pgx_scripts/blob/master/bloat/table_bloat_check.sql), this can be a rough estimation and doesn't provided details about the space reclaimed by vacuuming RUM indexes of the collection.
- Read only users can't perform `compact` command.
----
New feature implementation to support the backend compact command.
This PR adds complete backend support for a blocking compact command that estimates table bloat and conditionally performs a VACUUM FULL operation on collection tables.
- `src/utils/storage_utils.c` and `include/utils/storage_utils.h`: Introduced a new bloat estimation utility returning collection bloat stats.
- `src/commands/compact.c`: Implemented the compact command including BSON command parsing, dry-run handling, and conditional execution of VACUUM FULL.
- `internal/pg_documentdb_distributed/src/test/regress/sql/command_compact.sql`: Added regression tests covering various compact command scenarios.
- `include/utils/feature_counter.h` and `src/infrastructure/feature_counter.c`: Updated feature counter mapping to include the new compact command feature.
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
Related work items: #4237921
### 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?
Yes
### ChangeLog (Refer [Template](../oss/CHANGELOG.md))
### Description
----
#### AI description (iteration 1)
#### PR Classification
This pull request introduces a new feature to support “order by” queries on composite indexes and refines how composite query operators are handled.
#### PR Summary
The changes enable ordering by composite indexes by expanding the $all operator into an AND of expressions, adjusting index pushdown and term generation logic, and enforcing index-only paths when sequential scans are disabled. Key changes include:
- **`src/query/query_operator.c`**: Added the `ExpandExprForDollarAll` function to decompose $all into composite AND expressions, and integrated its use controlled by a new feature flag.
- **`src/planner/documents_planner.c`**: Introduced helper functions (e.g. `TrimPathListForSeqTypeScans` and `ForceExcludeNonIndexPaths`) to eliminate sequential scan paths when `ForceDisableSeqScan` is enabled, ensuring better index-based execution.
- **`src/configs/feature_flag_configs.c` & `src/configs/testing_configs.c`**: Added new configuration flags like `ExpandDollarAllInQueryOperator`, `SkipGeneratingArrayTermForCompositeIndex`, and `ForceDisableSeqScan` to control composite index behavior.
- **Composite Index Code (e.g. in `bson_gin_composite_entrypoint.c` and related files)**: Updated index strategy handling and term generation to support composite ordering and correct treatment of array terms.
- **Test Files**: Numerous expected output and SQL regression tests (both in the distributed and pgmongo modules) were updated to reflect the new composite index ordering and query operator changes.
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->