Commit Graph
101 Commits
Author SHA1 Message Date
Parag Jain d3a92030fa Merged PR 1528481: [Perf] Optimize $merge "merge" option
### 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
[Perf] Optimize $merge "merge" option

----
#### AI description  (iteration 1)
#### PR Classification
Performance optimization:

Single document in collection and  each entry is average of 10 runs.
![image.png](https://msdata.visualstudio.com/ba574a88-a171-48e0-8fcb-5fef6d23739c/_apis/git/repositories/501a5e7e-ffdc-4d1e-a5e6-910f73c6eb9a/pullRequests/1528481/attachments/image.png)

#### PR Summary
This pull request optimizes the `$merge` "merge" option by improving the handling of BSON elements.
- `bson_aggregation_output_pipeline.c`: Replaces the tree-based approach with a hash table to manage BSON elements, ensuring order and improving performance.
- Adds new functions and data structures for creating and managing an ordered hash set of BSON elements.
2025-01-15 07:48:39 +00:00
Vinod Sridharan 3f9a507562 Merged PR 1539950: [OSS] Move helio_api and helio_distributed sources under documentdb
### 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
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))

### Description
Move source files under new directory.

----
#### AI description  (iteration 1)
#### PR Classification
Code reorganization

#### PR Summary
This pull request moves the `helio_api` and `helio_distributed` sources under the `documentdb` directory, updating references and initialization logic accordingly.
- Added `pg_documentdb.c` for initializing the `pg_documentdb` extension.
- Added `documentdb_distributed.c` for initializing the `pg_documentdb_distributed` extension.
- Updated `validate_helio_extension_state.sh` to include new checks for `documentdb`.
- Moved `helio_api_extension_version.c` to `documentdb_extension_version.c` without code changes.
- Updated various `Makefile` configurations to reflect the new directory structure and dependencies.
2025-01-15 07:48:39 +00:00
Vinod Sridharan fd187e6b8f Merged PR 1539949: [Livesite] Fixups from cluster investigations
### Does this PR have any customer impact?
Yes

### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Bugfixes

### 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
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))

### Description
1) The first DDL after add-node needs to replicate reference tables. Since we're already in a broken state, just use block_writes in this path (we can go faster in this path)
2) For back-compat scenarios in upgrade, add ALTER TABLE DROP CONSTRAINT IF EXISTS cluster_data_pkey in the next upgrade
3) Shard_collection broke the colocation of main and retry tables. Ensure that they are colocated under a guc.

Still TODO:
Create a new config collection for rebalance_table_shards_plan().

----
#### AI description  (iteration 1)
#### PR Classification
Bug fix and code improvement from cluster investigations.

#### PR Summary
This pull request addresses issues found during cluster investigations, focusing on retry table creation and sharding improvements.
- `create_collection_core.c`: Refactored to create a separate `CreateRetryTable` function and adjusted table creation logic.
- `sharding.c`: Added logic to recreate retry tables during sharding if the `RecreateRetryTableOnSharding` flag is enabled.
- `helio_api_init.c`: Introduced a new configuration variable `RecreateRetryTableOnSharding`.
- `command_shard_commands.sql` and `command_shard_commands.out`: Updated tests to validate the new retry table creation logic.
- `collection.h`: Added declaration for the new `CreateRetryTable` function.
2025-01-15 07:48:39 +00:00
Vinod Sridharan 5dc631ea31 Merged PR 1539132: [OSS] Move source files from pg_helio_core to pg_documentdb_core
### 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
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))

### Description
- Move c files from pg_helio_core -> pg_documentdb_core
- Make helio_core, and other extensions depend on pg_documentdb_core as a lib dependency

----
#### AI description  (iteration 1)
#### PR Classification
Code reorganization

#### PR Summary
This pull request moves source files from `pg_helio_core` to `pg_documentdb_core` to better organize the project structure.
- Deleted `oss/pg_helio_core/include/utils/helio_codes.txt`.
- Added `oss/pg_documentdb_core/src/pg_documentdb_core.c` for initializing the shared library.
- Updated `oss/Makefile.cflags` to include new paths and installation rules for `pg_documentdb_core`.
- Moved `oss/pg_helio_core/src/bson_init.c` and `oss/pg_helio_core/include/bson_init.h` to `oss/pg_documentdb_core/src/bson_init.c` and `oss/pg_documentdb_core/include/bson_init.h` respectively.
- Modified various `Makefile` files to set `USE_DOCUMENTDB_CORE` and adjust include paths.
2025-01-15 07:48:39 +00:00
Vinod Sridharan dcf5344190 Merged PR 1538375: [OSS] Initial setup for documentdb
### 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)
Not yet

### Are you introducing any new config? If yes, do you have tests with and without them being set?
No
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))

### Description
Initial setup for documentdb extensions.
Create Makefiles and set up build scripts around documentdb.

This does not yet touch the actual code or make anything deployable.

----
#### AI description  (iteration 1)
#### PR Classification
Initial setup for DocumentDB integration.

#### PR Summary
This pull request sets up the initial structure and configuration for DocumentDB integration.
- Added `documentdb_errors.h` for defining DocumentDB-specific error codes.
- Created `Makefile` for `pg_documentdb`, `pg_documentdb_core`, and `pg_documentdb_distributed` to handle build configurations.
- Updated `validate_helio_extension_state.sh` and `validate_headers.sh` scripts to include checks for DocumentDB.
- Modified `bson_aggregation_nested_pipeline.c`, `bson_aggregation_vector_search.c`, and other source files to replace references from Helio to DocumentDB.
- Added control files for `pg_documentdb`, `pg_documentdb_core`, and `pg_documentdb_distributed` extensions.
2025-01-15 07:48:39 +00:00
Vinod Sridharan 0a2f28fdff Merged PR 1537573: Enable sharding commands and rebalancer commands
### Does this PR have any customer impact?
Yes

### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Features

### 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

### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
Enable shard_collection, reshard_collection, unshard_collection with more mongo options.
Moves core processing of this to the backend.

also introduces shard rebalancing APIs

### Description

Enable shard_collection, reshard_collection, unshard_collection with more mongo options.
Moves core processing of this to the backend.

also introduces shard rebalancing APIs

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

#### PR Summary
This pull request enables sharding commands for pgmongo.
- `src/sharding/sharding.c`: Added functions to handle sharding, resharding, and unsharding collections, including `ShardCollectionLegacy`, `ShardCollectionCore`, `ParseNamespaceName`, `ParseShardCollectionRequest`, `ParseReshardCollectionRequest`, and `ParseUnshardCollectionRequest`.
2025-01-15 07:48:39 +00:00
Lucas Borges Fernandes b09275ac76 Merged PR 1514068: Unique index truncation recheck
### 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.

### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))

### Description

----
#### AI description  (iteration 1)
#### PR Classification
Bug fix

#### PR Summary
This pull request addresses a bug related to unique index truncation by implementing a recheck mechanism.
- `oss/pg_helio_api/src/opclass/rum_exclusion.c`: Implemented `bson_unique_shard_path_equal` function to compare BSON documents for unique shard paths.
- Added `GetUniqueShardDocumentTermsHTAB` utility function to create a hash table of terms from a unique shard document.
- Adjusted include order and added new includes for required utilities.
- Changed `indexTermTruncateLimit` from `UINT32_MAX` to `INT32_MAX` in `generate_unique_shard_document`.

Related work items: #3291671, #3458782
2025-01-15 07:48:39 +00:00
Amit Prabhudesai c6783e2a49 Merged PR 1524148: [Bugfix] Fix handling of compound wildcard text indexes
### 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

### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))

### Description
Handling of wildcard text indexes when compounded with a non-wildcard field is broken. This bug is a **functional bug** affecting query results when used with a wildcard index (see JS test for repro).

----
#### AI description  (iteration 1)
#### PR Classification
Bug fix to correct the handling of compound wildcard text indexes.

#### PR Summary
This pull request addresses a bug in the handling of compound wildcard text indexes by adding additional tests and correcting the index creation and listing logic.
- Modified `commands_create_indexes_text.out` to include more tests and correct the handling of compound wildcard text indexes.
- Added new test file `text_indexes_wildcard.js` to verify the correct behavior of wildcard text indexes.
- Updated `commands_create_indexes_text.sql` to include additional test cases for compound wildcard text indexes.
2025-01-15 07:48:39 +00:00
Santiago Fernandez Madero e7d7e4cbe4 Merged PR 1525883: Push sort by _id down to the primary key index on unsharded or when we have a...
### 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

Push sort by _id down to the primary key index on unsharded or when we have a shard key

----
#### AI description  (iteration 1)
#### PR Classification
Code optimization

#### PR Summary
This pull request optimizes the sorting mechanism by pushing the sort by `_id` down to the primary key index when applicable.
- Added `CanSortByObjectId` and `HasShardKeyFilterWalker` functions in `bson_aggregation_pipeline.c` to determine if sorting by `_id` can be optimized.
- Modified `HandleSort` function in `bson_aggregation_pipeline.c` to use the new optimization logic for sorting by `_id`.
- Updated function declarations in `bson_aggregation_pipeline.c` to include the new helper functions.
2024-12-16 11:37:44 +08:00
Vinod Sridharan 6169cfd57a Merged PR 1532251: [Update] Only do Upsert if the query is on _id
### 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
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))

### Description
Fix up update to only do upsert if the query was exactly on _id. other cases should defer to insert (and fail on unique conflict)

----
#### AI description  (iteration 1)
#### PR Classification
Bug fix to ensure upsert operations are only performed when the query is on `_id`.

#### PR Summary
This pull request modifies the upsert logic to only perform upserts if the query is solely based on the `_id` field.
- Updated `update.c` to check for queries with only `_id` filters and renamed related variables for clarity.
- Added test cases in `commands_update.out` and `commands_update.sql` to verify upsert behavior and handle error cases.
2024-12-16 11:37:44 +08:00
Vinod Sridharan cb85775d7b Merged PR 1531437: Misc changes from service debugging
### Does this PR have any customer impact?
Yes
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Bug fixes
### 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?

### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))

### Description
1) send server group name in node metrics from backend
2) in collstats cap the avg obj size so it doesn’t go below storage size
3) skip run command on all nodes for single node
4) set the multinode behavior in distributed extension

----
#### AI description  (iteration 1)
#### PR Classification
Code cleanup and enhancement for service debugging.

#### PR Summary
This pull request includes various improvements and cleanups identified during service debugging.
- `pg_helio_distributed/src/test/regress/expected/commands_update.out`: Updated SQL command execution notices to use `helio_api_internal.update_worker`.
- `pgmongo/src/infrastructure/mdsd_logger.c`: Added functions to load default dimensions and append server group details to logs. Removed the `append_internal_logs` function.
2024-12-16 11:37:44 +08:00
Vinod Sridharan 215801d5cf Merged PR 1529060: [Tests] Fix don't ignore spaces in OSS tests (Part 2)
### Does this PR have any customer impact?
no
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
testing
### 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
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))

### Description
Don't ignore spaces in OSS tests - honor space changes as diffs

----
#### AI description  (iteration 1)
#### PR Classification
Bug fix for OSS tests to ensure spaces are not ignored.

#### PR Summary
This pull request addresses the issue of spaces being ignored in OSS tests by correcting the expected output formatting.
- `oss/internal/pg_helio_distributed/src/test/regress/expected/bson_aggregation_type_operators_tests.out`: Adjusted the expected output to include spaces in the `bson_dollar_project` results.
2024-12-16 11:37:44 +08:00
Vinod Sridharan 56e2a12845 Merged PR 1528566: Code Cleanup of Feature Flags
### 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
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))

### Description
- Delete old feature flags that are default on for a while.
- Remove ClusterVersion checks < 1.19

----
#### AI description  (iteration 1)
#### PR Classification
Code cleanup

#### PR Summary
This pull request focuses on cleaning up feature flags in the codebase.
- Removed feature flag checks and related code in `bson_aggregation_pipeline.c`.
- Updated test outputs in `bson_aggregation_stage_merge_tests.out` files.
- Removed feature flag settings in `bson_index_truncation_index_tests.sql`.
- Deleted unused function `GetMergeDocumentsFunctionOid` in `bson_aggregation_pipeline_private.h`.
- Removed feature flag definitions in `helio_api_init.c`.
2024-12-16 11:37:44 +08:00
Parag Jain f6feaa4ea7 Merged PR 1494892: [Perf] [Update] Only shard_key And object_id filter for select candiadate for {_id : 1}
### 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
When the query filter includes only the _id field with either the $eq or $in operator, we aim to optimize the update selection query by creating only two qualifiers: one on the shard_key_value and the other on the object_id column, while skipping the match on the document column.

This optimization reduces a few unnecessary calls; however, it does not yield a noticeable performance improvement because the TrimPrimaryKeyQuals function already removes useless qualifiers after the initial planning stage.

example :  `SELECT helio_api.update('update', '{"update":"updateme", "updates":[{"q":{"_id":{"$eq":1}},"u":{"$set":{"b":0 }},"multi":false}]}');`

- Before My Changes select query for update candidate
`SELECT ctid, object_id, document FROM mongo_data.documents_2_102046 WHERE shard_key_value = $1 AND document OPERATOR(mongo_catalog.@@) $2::mongo_catalog.bson AND object_id OPERATOR(mongo_catalog.=) $3`

 - After My changes
`SELECT ctid, object_id, document FROM mongo_data.documents_2_102046 WHERE shard_key_value = $1 AND object_id OPERATOR(mongo_catalog.=) $3::mongo_catalog.bson LIMIT 1 FOR UPDATE`

----

Why there is no noticeable perf changes  : As we already use `TrimPrimaryKeyQuals` function to remove useless quals after initial planning  even without my changes if we look at explain plan of select query :

```
EXPLAIN SELECT ctid, object_id, document FROM mongo_data.documents_2_102046 WHERE shard_key_value = 2 AND document OPERATOR(mongo_catalog.@@) '{"_id" : {"$eq" : 1}}'::mongo_catalog.bson AND object_id OPERATOR(mongo_catalog.=) '{ "" : { "$numberInt" : "1" } }';
                                                              QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------------
 Index Scan using _id_ on documents_2_102046  (cost=0.00..0.00 rows=1 width=40)
   Index Cond: ((shard_key_value = 2) AND (object_id OPERATOR(mongo_catalog.=) '{ "" : { "$numberInt" : "1" } }'::mongo_catalog.bson))
(2 rows)
```

```
postgres=# EXPLAIN SELECT ctid, object_id, document FROM mongo_data.documents_2_102046 WHERE shard_key_value = 2 AND document OPERATOR(mongo_catalog.@@) '{"_id" : {"$gt" : 1}}'::mongo_catalog.bson AND object_id OPERATOR(mongo_catalog.=) '{ "" : { "$numberInt" : "1" } }';
                                                              QUERY PLAN
------------------------------------------------------------------------------------------...
2024-12-16 11:37:44 +08:00
Vinod Sridharan 7a69840b4f Merged PR 1525667: [Misc Fixes] Fixes for Sharding and Update with Upsert
### Does this PR have any customer impact?
Yes

### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Fixes/Perf

### 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 - to turn off the features

### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))

### Description
1) If there's a $or with shard key - extract the shard key values into the top level filter
2) If there's an update with an upsert, only do Upsert if hte query was on _id
3) Fix the query plan cache for insert/upsert

----
#### AI description  (iteration 1)
#### PR Classification
Bug fix

#### PR Summary
This pull request addresses issues related to sharding and updates with upsert functionality.
- `sharding.c`: Added functions to handle multi-value query predicates for shard keys, including `$and` and `$or` statements.
- `sharding.h`: Updated function declarations and added new functions for computing shard key expressions and creating shard key value filters.
- Added `query_sharding_tests.sql`: New test cases for various sharding scenarios.
- Updated `commands_update.out` and `helio_compat/commands_update.out`: Added tests for upsert error cases.
2024-12-03 17:42:24 +08:00
Lucas Borges Fernandes 555181a2d9 Merged PR 1458242: Upgrading libbson to 1.28.0
### Does this PR have any customer impact?
No.

### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
N/A.

### 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.

### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))

### Description

Upgrading libbson dependency.

----
#### AI description  (iteration 1)
#### PR Classification
Dependency upgrade

#### PR Summary
This pull request upgrades the `libbson` library to version 1.28.0 and updates related initialization code.
- Updated `MONGO_DRIVER_VERSION` to 1.28.0 in `oss/scripts/install_setup_libbson.sh`.
- Added a `NULL` entry to the `bson_mem_vtable_t` structure in `oss/pg_helio_core/src/bson_init.c`.

Related work items: #3468225
2024-12-03 17:42:24 +08:00
Shuai Tian d09aeb6aaf Merged PR 1516163: upgrade pgvector version to 0.8.0
### Does this PR have any customer impact?
No

### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Dependency version

### 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

### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))

### Description

upgrade pgvector version to 0.8.0
Temporarily comment out tests that have different results with new version, to avoid breaking the test pipelines after new docker image is used.

----
#### AI description  (iteration 1)
#### PR Classification
Bug fix for failing tests due to different versions of pgvector.

#### PR Summary
This pull request upgrades the pgvector version to 0.8.0 to address failing tests.
- Modified `bson_aggregation_pipeline_tests_vector_ivf.out` in `pg_helio_distributed` and `pgmongo` to temporarily disable specific tests until the pgvector upgrade is complete.
- Updated `commands_create_indexes_background.out` to temporarily disable tests related to vector index creation until the pgvector upgrade is complete.

Related work items: #3612979
2024-11-19 17:25:36 +08:00
Amit Prabhudesai 95910b3aa9 Merged PR 1512730: Add helio_distributed_test_helpers to helio_compat tests
### Does this PR have any customer impact?
No

### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Testing

### 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

### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))

### Description
Add helio_distributed_test_helpers to helio_compat tests

Without this, tests that rely on `helio_distributed_test_helpers` (e.g., tests for background index builds) crap out with an error like so:

```
 CALL helio_distributed_test_helpers.create_indexes_background('db', '{ "createIndexes": "LargeKeySize", "indexes": [ { "key" : { "a": 1 }, "name": "rumConstraint1"}] }');
-                                                                                                                retval                                                                                                                | ok
----------------------------------------------------------------------
- { "raw" : { "defaultShard" : { "numIndexesBefore" : { "$numberInt" : "1" }, "numIndexesAfter" : { "$numberInt" : "2" }, "createdCollectionAutomatically" : false, "ok" : { "$numberInt" : "1" } } }, "ok" : { "$numberInt" : "1" } } | t
-(1 row)
-
+ERROR:  procedure helio_distributed_test_helpers.create_indexes_background(unknown, unknown) does not exist
+LINE 1: CALL helio_distributed_test_helpers.create_indexes_backgroun...
+             ^
+HINT:  No procedure matches the given name and argument types. You might need to add explicit type casts.
```

----
#### AI description  (iteration 1)
#### PR Classification
Code cleanup

#### PR Summary
This pull request updates the test setup for `helio_compat` by adding a new test helper.
- `pgmongo/src/test/helio_compat/helio_setup_schedule`: Added `helio_distributed_test_helpers` to the test setup.
2024-11-19 17:25:36 +08:00
Duan Pei✨ cbd1780c97 Merged PR 1506905: [Fix] fix memory_check for maxN/minN
### 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

update

----
#### AI description  (iteration 1)
#### PR Classification
Bug fix for memory check in maxN/minN aggregation functions.

#### PR Summary
This pull request addresses a bug in the memory check for maxN/minN aggregation functions by adding size validation and handling large element sizes.
- `bson_aggregates.c`: Added size validation for intermediate documents and updated element type handling to support int64.
- `bson_aggregation_pipeline_tests_maxnminn_group.out`: Added tests to verify the 100 MB limit for $maxN and $minN operations.
2024-11-19 17:25:36 +08:00
Vinod Sridharan df093213ad Merged PR 1511148: [Upsert] On Update with Upsert, convert the final insert to INSERT ON CONFLICT UPDATE
### 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
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))

### Description
On Update with Upsert, convert the final insert to INSERT ON CONFLICT UPDATE
This is to handle a race condition where two threads do SELECT for update -> don't find the doc -> one does the insert, and the other will get a unique conflict when it should just succeed.

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

#### PR Summary
This pull request introduces a new feature to handle upserts by converting the final insert to `INSERT ON CONFLICT UPDATE`.
- `oss/pg_helio_api/src/commands/insert.c`: Added `InsertOrUpdateDocument` function to handle upserts.
- `oss/pg_helio_api/src/commands/update.c`: Updated functions to use `InsertOrUpdateDocument` for upsert operations.
- `oss/pg_helio_api/include/commands/insert.h`: Declared the new `InsertOrUpdateDocument` function.
- `oss/internal/pg_helio_distributed/src/test/regress/expected/commands_update.out` and `pgmongo/src/test/helio_compat/expected/commands_update.out`: Added tests for the new upsert behavior.
- `oss/internal/pg_helio_distributed/src/test/regress/sql/commands_update.sql`: Added SQL tests for upsert functionality.
2024-11-19 17:25:36 +08:00
Cornelius Boateng 918504553e Merged PR 1511567: [pgmongo][let 5/n]Let Support for Inline Projection
### 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

### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))

### Description

Support let variables with inlin projection

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

#### PR Summary
This pull request adds support for inline projection in the aggregation pipeline.
- Modified `oss/pg_helio_api/src/aggregation/bson_project.c` to handle new function OIDs for inline projection and addFields with let variables.
- Updated test files `/oss/internal/pg_helio_distributed/src/test/regress/expected/bson_aggregation_pipeline_tests_let.out` and `/pgmongo/src/test/helio_compat/expected/bson_aggregation_pipeline_tests_let.out` to include new test cases for the inline projection feature.
- Added new SQL test cases in `/oss/internal/pg_helio_distributed/src/test/regress/sql/bson_aggregation_pipeline_tests_let.sql` to validate the new functionality.
2024-11-19 17:25:36 +08:00
Santiago Fernandez Madero 738f66ab62 Merged PR 1511256: Fix check-dist-minimal
### 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

When check-dist-minimal initially was added it didn't include `helio_distributed_setup` so 2 commits in parallel attempted to fix this. One by including minimal_schedule to the make target: https://msdata.visualstudio.com/CosmosDB/_git/pgmongo/commit/36ace0cb18d7aed12de01f5e14d8ae3898e051ac?refName=refs%2Fheads%2Fusers%2Fdeepakbisht%2FfixMinimal

The other one by running `helio_distributed_setup` on the `minimal_schedule`: https://msdata.visualstudio.com/CosmosDB/_git/pgmongo/commit/6cb01bd1c3ca9ec2584e50b8fff6808562e660e1?refName=refs%2Fheads%2Fmain&path=%2Foss%2Finternal%2Fpg_helio_distributed%2Fsrc%2Ftest%2Fregress%2Fminimal_schedule&_a=compare

We should take the second one as for correctness `check-dist-minimal` should not use `basic_schedule` as that "runs more than just the actual setup + the extra test provided".

Also, this cleans up duplicated `check-dist-minimal` targets on the make files.

----
#### AI description  (iteration 1)
#### PR Classification
Bug fix

#### PR Summary
This pull request addresses a bug in the `check-dist-minimal` target.
- Removed `check-dist-minimal` target from `oss/internal/pg_helio_distributed/Makefile`
- Removed `check-dist-minimal` target from `oss/internal/pg_helio_distributed/src/test/regress/Makefile`
2024-11-19 17:25:36 +08:00
Cornelius Boateng e62bdce75d Merged PR 1505458: [pgmongo][let 4/n] $groupBy with sorted accumulators on sharded collection
### 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

### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))

### Description
Support for Let on $groupBy with sorted accumulators.
Cast intermediate stage output from helio bson to catalog bson
2024-11-12 18:48:09 +08:00
Zinan Ren 🐾 4742ecce61 Merged PR 1487201: [Vector Search][Embedding Gen Part 2] Integrate azure_ai extension and add local tests
### 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

### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))

### Description

- Create azure_ai extension if it is available( in flex cluster)
- Add mock aoai server
- Add local only tests which will never be run in CI pipeline

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

#### PR Summary
This pull request integrates the `azure_ai` extension and adds local tests for embedding generation using a mock AOAI server.
- Added `scripts/mock_aoai/aoai_mock_server.py` to mock AOAI API server for local testing.
- Added `pgmongo/src/test/regress/sql/bson_aggregation_pipeline_tests_vector_gen_embedding.sql` and `pgmongo/src/test/regress/expected/bson_aggregation_pipeline_tests_vector_gen_embedding.out` for embedding generation tests.
- Updated `pgmongo/src/infrastructure/process_utility_hook.c` to check and create the `azure_ai` extension if available.
- Added `scripts/mock_aoai/setup_and_start_mock_server.sh` to set up and start the mock AOAI server.
- Modified `pgmongo/src/test/regress/Makefile` to include embedding generation tests with the mock server.
2024-11-12 18:48:09 +08:00
Parag Jain 48f3e026c2 Merged PR 1506658: [Bug-Fix] setting merge whenMatched default option to merge from replace
### 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
[Bug-Fix] setting merge whenMatched default option to merge from replace
![image.png](https://msdata.visualstudio.com/ba574a88-a171-48e0-8fcb-5fef6d23739c/_apis/git/repositories/501a5e7e-ffdc-4d1e-a5e6-910f73c6eb9a/pullRequests/1506658/attachments/image.png)

----
#### AI description  (iteration 1)
#### PR Classification
Bug fix

#### PR Summary
This pull request fixes a bug by setting the default `whenMatched` option to `merge` instead of `replace` in the merge operation.
- Added tests in `bson_aggregation_stage_merge_tests.out` to verify the default `whenMatched` behavior.
- Updated shard key values in `bson_aggregation_stage_merge_tests.out` to reflect the new default behavior.
2024-11-12 18:48:09 +08:00
Jia Hu 778bc161e3 Merged PR 1452968: [schema validation] apply on general update
### 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?

### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))

### Description
apply schema validation on general update

####Comments to follow:https://msdata.visualstudio.com/DefaultCollection/CosmosDB/_git/pgmongo/pullRequest/1452968#1729531108

----
#### AI description  (iteration 1)
#### PR Classification
New feature: Schema validation applied on general update operations.

#### PR Summary
This pull request introduces schema validation for update operations, ensuring documents comply with defined schemas during updates.
- Added `command_schema_validation_against_update` function and `ValidateSchemaOnDocumentUpdate` in `schema_validation.c` to handle schema validation during updates.
- Updated `bson_expr_eval.h` to include `ExprEvalState` struct definition.
- Modified `update.c` to integrate schema validation logic into batch and single document update processes.
- Enhanced `schema_validation_insert.sql` with tests for update operations involving schema validation.
2024-11-12 18:48:09 +08:00
Cornelius Boateng 962996b8ce Merged PR 1490665: [engine] Collation Support for $graphLookup
### Does this PR have any customer impact?

### 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

### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))

### Description
Enable support for collation with $graphlookup

----
#### AI description  (iteration 1)
#### PR Classification
New feature: Collation support for `$graphLookup` in the engine.

#### PR Summary
This pull request adds collation support to the `$graphLookup` operator, enabling locale-specific string comparison.
- `src/operators/bson_expression.c`: Added logic to handle collation strings in BSON expressions and pass them to relevant functions.
- `src/aggregation/bson_aggregation_nested_pipeline.c`: Updated functions to include collation handling in aggregation pipelines.
- `src/collation/collation.c`: Fixed typos and improved comments related to locale string handling.

Related work items: #3431063
2024-11-12 18:48:09 +08:00
Duan Pei✨ ce79fc0ac5 Merged PR 1501001: [Fix] add memory check for maxN/minN accumulator
### 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

----
#### AI description  (iteration 1)
#### PR Classification
Bug fix

#### PR Summary
![image (2).png](https://msdata.visualstudio.com/ba574a88-a171-48e0-8fcb-5fef6d23739c/_apis/git/repositories/501a5e7e-ffdc-4d1e-a5e6-910f73c6eb9a/pullRequests/1501001/attachments/image%20%282%29.png)
This pull request adds a memory usage check for the `maxN` and `minN` accumulators to prevent excessive memory consumption.
- `oss/pg_helio_api/src/aggregation/bson_aggregates.c`: Added a memory check to ensure the total size does not exceed the allowed limit, raising an error if it does.
- `oss/internal/pg_helio_distributed/src/test/regress/sql/bson_aggregation_pipeline_tests_maxnminn_group.sql`: Added test cases to verify the memory limit enforcement for `maxN` and `minN`.
- `oss/internal/pg_helio_distributed/src/test/regress/expected/bson_aggregation_pipeline_tests_maxnminn_group.out`: Updated expected output to include error messages for exceeding memory limits.
- `pgmongo/src/test/helio_compat/expected/bson_aggregation_pipeline_tests_maxnminn_group.out`: Updated expected output to include error messages for exceeding memory limits.
2024-11-04 17:14:58 +08:00
Santiago Fernandez Madero 6f9ec2f60c Merged PR 1501766: [HELIO_GIN] Port rum fast scan improvements and PoC new features
### 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 ports the RUM fast scan improvements we've made into our RUM clone into helio_gin and also adds improvements like:
- multibitmap and, which is a strategy to instead of building multiple bitmaps on filters on multiple indexes and then intersecting them, we share the information of each of the bitmaps as they're built between them to build a single bitmap that honors all the filters.
- push limit down to the index.

These features where worked by @<Vinod Sridharan> and @<Dmitri Melnikov> on:
https://msdata.visualstudio.com/CosmosDB/_git/pgmongo/pullrequest/1485843

Next step is to actually load helio_gin on pgmongo behind a GUC and run tests against it.

----
#### AI description  (iteration 1)
#### PR Classification
New feature and performance improvement.

#### PR Summary
This pull request ports improvements to the fast scan functionality and introduces new features for the Helio Gin index.
- `helio_gin/src/helioginget.c`: Added `initScanCore` and `MultiAndGetNextMatch` functions to enhance scan initialization and matching logic.
- `helio_gin/src/helioginget.c`: Implemented `helio_gin_multiandgetbitmap` to handle multi-scan operations and bitmap collection.
- Removed outdated functions and replaced them with optimized versions to improve performance and maintainability.
2024-11-04 17:14:58 +08:00
Lucas Borges Fernandes 179da8cded Merged PR 1499631: Scripts for unique index truncation opclass
### 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.

### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))

### Description

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

#### PR Summary
This pull request introduces scripts for unique index truncation opclass and updates the extension upgrade process.
- Added `extension_upgrade_unique_index_opclass.sql` for testing unique index opclass during extension upgrades.
- Updated `upgrade_schedule` to include the new unique index opclass test.
- Added `pgmongo--1.21-0--1.21-1.sql`, `pgmongo--1.22-0--1.22-1.sql`, and `pgmongo--1.21-0--1.21-1.sql` for unique index opclass updates.
- Modified `pgmongo--1.23-0--1.24-0.sql` to include unique index opclass scripts.
- Updated SHA1 checksum files for the new and modified SQL scripts.
2024-11-04 17:14:58 +08:00
Ujjwal Agrawal 37681b511b Merged PR 1493190: Update error codes from pg to helio and add missing sql tests
### 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

Bug fix to update error codes from Postgres to HelioDB-specific codes. Checking and updating error codes for each command. FerretDB reported bug.

Related work items: #3554201
2024-11-04 17:14:58 +08:00
Shuai Tian 🚀 8fad30b687 Merged PR 1495735: Update bson_aggregation_date_operators_tests to fix errors
### Does this PR have any customer impact?
No

### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Testing

### 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

### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))

### Description
This test has two cases failed on GitHub.

One related to timezone "Europe/Amsterdam" which has a historical shift from "Amsterdam Mean Time" to Central European time in 1940, update this case to reflect modern timezone rules used now. refer to https://en.wikipedia.org/wiki/Time_in_the_Netherlands

Second one is related to that postgre added a overflow check, but pgmongo is still depending on old versions (15.3 and 16.2). there is a ongoing bugfix for postgre which blocks us from bumping up versions used in pgmongo. For now, we can skip this case.

----
#### AI description  (iteration 1)
#### PR Classification
Bug fix for failing tests.

#### PR Summary
This pull request addresses errors in the `bson_aggregation_date_operators_tests` by updating test cases to handle overflow checks introduced in newer PostgreSQL minor versions.
- `bson_aggregation_date_operators_tests.out`: Commented out test cases causing overflow errors and added TODOs for future updates.
- `bson_aggregation_date_operators_tests.sql`: Commented out overflow test cases and added TODOs for future updates.
- `helio_compat/expected/bson_aggregation_date_operators_tests.out`: Synchronized changes with the main test output file, including commenting out overflow test cases.

Related work items: #3572010
2024-11-04 17:14:58 +08:00
Shuai Tian 🚀 5918fdc82a Merged PR 1495556: move 2 tests depending on custom rum back to pgmongo
### Does this PR have any customer impact?
No
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Testing only

### 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

### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))

### Description
we have 2 tests failed due to different rums being used. In pgmogo we have custom rum, but on GitHub we use public rum instead. Before we publish custom rum to public, we need to keep related tests in pgmongo and not moving them into distributed tests.

----
#### AI description  (iteration 1)
#### PR Classification
Failing test

#### PR Summary
This pull request addresses failing tests by moving two test files that depend on custom RUM back to the `pgmongo` directory.
- Deleted `bson_index_fast_scan_tests.out` and `bson_index_fast_join_scan_tests.out` from `oss/internal/pg_helio_distributed/src/test/regress/expected`.
- Moved `bson_index_fast_join_scan_tests.out` and `bson_index_fast_scan_tests.out` to `pgmongo/src/test/regress/expected`.
- Moved `bson_index_fast_join_scan_tests.sql` and `bson_index_fast_scan_tests.sql` to `pgmongo/src/test/regress/sql`.
- Updated `basic_schedule_core` to remove the moved tests.
- Updated `bson_schedule` to include the moved tests.

Related work items: #3572014
2024-11-04 17:14:58 +08:00
Vinod Sridharan 055383c27d Merged PR 1483236: Truncation GUC and unique part 1
### Does this PR have any customer impact?
No
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Feature/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
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))

### Description
Fix up truncation for unique indexes behind a flag.
- This is part 1 of many. This makes unique conflicts with truncation harder to hit with the hash of the untruncated value stored as a compound term with the shard_key.
- Subsequent changes should make it so that even on hash collision the values should be validated.

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

#### PR Summary
This pull request introduces support for creating unique indexes with truncation in the Helio API.
- `helio_api_init.c`: Added a new configuration `enable_large_unique_index_keys` to allow large unique index keys.
- `create_indexes.c`: Modified logic to support large unique index keys and handle truncation.
- `bson_unique_index.sql` and `bson_unique_index.out`: Added tests for creating unique indexes with and without truncation.
- `helio_distributed_test_helpers.sql` and `helio_distributed_test_helpers.out`: Added tests for native colocation settings.
- `Makefile` and related files: Added a new `check-dist-minimal` target for minimal distributed tests.
2024-11-04 17:14:58 +08:00
Jia Hu 👻 0fa4669612 Merged PR 1494340: [DBRef] fix index issue
### 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
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))

### Description

----
#### AI description  (iteration 1)
#### PR Classification
Bug fix

#### PR Summary
This pull request addresses an issue with DBRef index handling in the query operator.
- `query_operator.c`: Simplified the creation of DBRef qualifiers by consolidating the `$ref`, `$id`, and `$db` fields into a single BSON value.
- `bson_aggregates_distinct_tests.out` and `bson_aggregates_distinct_tests.sql`: Added tests for inserting documents with DBRefs and creating indexes on these fields.
- `reference.md`: Updated documentation to reflect changes in DBRef handling and indexing.
2024-11-04 17:14:58 +08:00
Ujjwal Agrawal 5e68dee1bc Merged PR 1467812: [BugFix] $setOnInsert no-op instead of error with upsert: false
### 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

make setOnInsert no-op instead of error

----
#### AI description  (iteration 1)
#### PR Classification
Bug fix

#### PR Summary
This pull request addresses a bug where the `$setOnInsert` operator would cause an error instead of being a no-op when `upsert` is set to `false`.

For example,
mongos> coll.find()
{ "_id" : "double", "v" : 42.13 }
{ "_id" : "array", "v" : [ 42 ] }
mongos> db.runCommand({update: 'test', updates: [{q: {_id: 'double'}, u: {$setOnInsert: {'v.foo': NumberInt(1)}}}]})
{
        "n" : 0,
        "nModified" : 0,
        "writeErrors" : [
                {
                        "index" : 0,
                        "code" : 28,
                        "errmsg" : "Cannot create field 'v' in element {v : 42.13}"
                }
        ],
        "ok" : 1
}

mongo returns { "n" : 1, "nModified" : 0, "ok" : 1 }

Related work items: #3463180
2024-11-04 17:14:58 +08:00
Cornelius Boateng ee9c5de90c Merged PR 1453287: [Perf] Type Aggregation Ops
### Does this PR have any customer impact? No

### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc) Perf

### 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

### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md)) No

### Description
Migrate `$isNumber`, `$type`, `$toBool`, `$toObjectId`, `$toInt`, `$toLong`, `$toString`, `$toDate`, `$toDouble`, `$toDecimal`, and `$convert` to the new aggregation framework.

----
#### AI description  (iteration 1)
#### PR Classification
Performance improvement for type aggregation operations.

#### PR Summary
This pull request optimizes the handling of type aggregation operations, specifically focusing on the `$convert` and `$makeArray` expressions.
- `src/operators/bson_expression_type_operators.c`: Refactored the `$convert` expression to pre-parse and handle arguments more efficiently, reducing redundant evaluations and improving error handling.
- Added new functions to handle pre-parsed `$convert` and `$makeArray` expressions, ensuring better performance and cleaner code structure.

Related work items: #3458660
2024-11-04 17:14:58 +08:00
Deepak Pemmaraju f7d07bb884 Merged PR 1493950: Fixing a syntax error in cluster upgrade
### Does this PR have any customer impact? It fixes an upgrade blocked due to a syntax error

### 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

Fixing a syntax error in cluster upgrade

----
#### AI description  (iteration 1)
#### PR Classification
Bug fix

#### PR Summary
This pull request addresses a syntax error in the cluster upgrade process.
- Added new test files `extension_upgrade_add_role_creation_privileges_1.21-0.out` and `extension_upgrade_add_role_creation_privileges_1.21-0.sql` to validate the upgrade process.
- Fixed a syntax error in `cluster_operations.c` by changing `quote_literal_cstr` to `quote_identifier` for the `ClusterAdminRole`.
2024-11-04 17:14:58 +08:00
Shuai Tian f8c366966d Revert "HelioDB Push 2024-10-31" (#76)
Reverts microsoft/heliodb#75, redo the merge instead of squash merge
which discarded the commit history
2024-11-04 14:38:52 +08:00
69edcc3556 HelioDB Push 2024-10-31 (#75)
Co-authored-by: Deepak Pemmaraju <deepakpe@microsoft.com>
Co-authored-by: Cornelius Boateng <cboateng@microsoft.com>
Co-authored-by: Ujjwal Agrawal <uagrawal@microsoft.com>
Co-authored-by: Jia Hu 👻 <jiahu2@microsoft.com>
Co-authored-by: Jayanta Mondal <jmondal@microsoft.com>
Co-authored-by: Vinod Sridharan <visridha@microsoft.com>
2024-10-31 16:09:00 +08:00
Deepak Bisht 1225b7ea85 Merged PR 1490664: [InternalError] [Fix] Too many args
### 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

### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))

### Description
For `$group` and `$setWindowFields` we tend to create `bson_repath_and_build` function expression with the path and values as arguments to the function, if this argument list goes beyond 100 its an internal error.

So with this PR huge number of aggregates are broken down using functions expression of `bson_dollar_merge` and `bson_repath_and_build`.
e.g If there are 110 groupby operators then the projector will be of this form.

```
bson_dollar_merge_documents(
    bson_repath_and_build(<50 operators>),
    bson_dollar_merge_documents(
        bson_repath_and_build(<50 operators>),
        bson_repath_and_build(<10 operators>)
    )
)
```

----
#### AI description  (iteration 1)
#### PR Classification
Bug fix

#### PR Summary
This pull request addresses an issue with handling too many arguments in aggregation functions by introducing a new method to manage large numbers of arguments.
- `bson_aggregation_pipeline.c`: Added `GenerateMultiExpressionRepathExpression` function to handle cases where the number of arguments exceeds `FUNC_MAX_ARGS`.
- `bson_aggregation_pipeline.c`: Updated `HandleGroup` to use the new function for generating repath expressions.
- `setwindowfields_and_group_compliance.sql`: Added tests to verify the handling of multiple arguments in aggregation functions.
- `bson_aggregation_window_operators.c`: Modified `HandleSetWindowFieldsCore` to use the new function for repath expressions.
- `bson_aggregation_pipeline_private.h`: Declared the new function for generating multi-expression repath expressions.
2024-10-25 09:11:39 +03:00
Vinod Sridharan 965b2a01bc Merged PR 1491491: [Perf] Fix filter on _id $in queries
### Does this PR have any customer impact?
Yes
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Perf
### 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
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))

### Description
[Perf] Fix  filter on _id $in queries

When you have queries of `{ "_id": { "$in": [ 1, 2, 3 ] }` This formed a query of
`document @*= '{ "_id": [ 1, 2, 3 ] }' AND object_id ANY= '{ 1, 2, 3 ]'::bson[]`
These are redundant if it's pushed to the primary key index. In this case, remove the $in filter to reduce runtime filters.

----
#### AI description  (iteration 1)
#### PR Classification
Bug fix to improve performance of `_id $in` queries.

#### PR Summary
This pull request optimizes the handling of `_id $in` queries to improve performance by refining the query planning logic.
- `planner.c`: Added functions to handle `FuncExpr` and `ScalarArrayOpExpr` for `_id` filters, and updated logic to correctly identify and process these expressions.
- `bson_query_operator_object_id_tests.out`: Updated expected output to reflect the optimized query plans.
- `bson_query_operator_tests_explain_index.out` and `bson_query_operator_tests_explain_runtime.out`: Adjusted expected rows and query plans to match the new logic.
2024-10-25 09:11:39 +03:00
Parag Jain f801b9e7a3 Merged PR 1490550: [Bug Fix] $merge bug fix while checking presence of compound index on target collection
### 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 PR contains 2 fixes
- In $merge `on` field cannot contain duplicate element:    `{ "$merge" :  {"on" : [a,a] }`
- we were missing a case while validating on field against index array.

```
let's say indexSpec :  { "x" : 1, "y" : 1, "z" : 1}
then below cases also expected to be fail as index array has extra element.
 `{ "$merge" :  {"on" : [x,z] }`
 `{ "$merge" :  {"on" : [x,y] }`
```

----
#### AI description  (iteration 1)
#### PR Classification
Bug fix

#### PR Summary
Fixes a bug in the `$merge` operation by ensuring proper detection of compound unique indexes and handling duplicate fields.
- `bson_aggregation_output_pipeline.c`: Corrected logic to check for compound unique indexes and added error handling for duplicate fields.
- `bson_aggregation_stage_merge_tests.sql` and related test output files: Added tests to verify the detection of duplicate fields and proper index checking.
- `helio_conversion_codes.c`: Added a new error code for duplicate field detection.
- Updated error code mappings in `mongoerrors.csv`, `helioerrors.csv`, `helio_codes.txt`, and `mongo_codes.csv`.
2024-10-25 09:11:39 +03:00
Parag Jain b755d9924f Merged PR 1490793: [OSS] Test migrations: Part 15 [ parallelizing tests]
### 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
[OSS] Test migrations: Last One [ parallelizing tests]

----
#### AI description  (iteration 1)
#### PR Classification
Test enhancement for parallelizing tests.

#### PR Summary
This pull request updates test output files to support parallel execution of tests.
- `oss/internal/pg_helio_distributed/src/test/regress/expected/bson_query_operator_tests_index.out`: Adjusted line numbers in error messages to align with changes in the test SQL file.
2024-10-25 09:11:39 +03:00
Deepak Bisht 1921ac37ee Merged PR 1490629: [Infra] Fix dist-minimal test step, and add compat-minimal too
### Does this PR have any customer impact?
no

### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Infra

### 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

### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
NA

### Description
fix dist-minimal

----
#### AI description  (iteration 1)
#### PR Classification
Bug fix for a failing test step in the infrastructure.

#### PR Summary
This pull request addresses an issue in the `dist-minimal` test step by modifying the test schedule configuration.
- `oss/internal/pg_helio_distributed/src/test/regress/Makefile`: Updated the `check-dist-minimal` target to include both `basic_schedule` and `minimal_schedule` in the test execution.
2024-10-25 09:11:39 +03:00
Vinod Sridharan 4165e5ce47 Merged PR 1489183: [Infra] Add PG16 to dev container, add dist-minimal to run individual tests
### Does this PR have any customer impact?
No
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Infra
### 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
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))

### Description
Add PG16 to dev container, add dist-minimal to run individual tests

----
#### AI description  (iteration 1)
#### PR Classification
Infrastructure update to add PostgreSQL 16 to the development container and introduce a minimal distribution for running individual tests.

#### PR Summary
This pull request updates the development environment to support PostgreSQL 16 and adds a new target for running minimal tests.
- `.devcontainer/Dockerfile`: Added installation steps for PostgreSQL 16.
- `Makefile` and `oss/internal/pg_helio_distributed/Makefile`: Introduced `check-dist-minimal` target for running minimal tests.
- `oss/internal/pg_helio_distributed/src/test/regress/Makefile`: Added `check-dist-minimal` target and updated test schedules.
- `scripts/install_setup_postgres.sh`: Modified script to handle PostgreSQL version-specific directories.
- `oss/internal/pg_helio_distributed/src/test/regress/sql/helio_distributed_test_helpers.sql`: Added tests for native colocation feature.
2024-10-25 09:11:39 +03:00
Deepak Bisht cb8964171d Merged PR 1487560: [Oss] Test migrations part 14 [9 tests]
### Does this PR have any customer impact?
no

### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
testing

### 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

### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
Test migration

### Description
Move miscellaneous tests from pgmongo to helio_distributed

----
#### AI description  (iteration 1)
#### PR Classification
Test migration

#### PR Summary
This pull request adds a new test file to validate collection management functionalities.
- Added `oss/internal/pg_helio_distributed/src/test/regress/expected/collection_management.out` to test various collection operations such as creation, insertion, querying, renaming, and dropping collections.
2024-10-25 09:11:39 +03:00
Parag Jain d3db854dae Merged PR 1485054: [Perf] [Update] Query Positional Update 10x faster for 1 Lakh Elements
### Does this PR have any customer impact?
No

### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Perf

### 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

### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))

### Description
query :
`
db.test.updateOne(
    { _id: ObjectId("670e3a9f9b192eb7f2f1cce7"), "items.id": 99999},
    { $set: { "items.$.status": "asdasasasddd" } }
)`

num elements in array items: `100000`

Time taken before: `120265 Ms'
Time taken after improvement: `250 Ms'
**Perf Gain: 10 x**.

**Changes Description:**
Previously, for each element in the array of the source document (O(n)), we were attempting to match it against positional qualifiers, which was also O(n), resulting in a total complexity of O(n²).

However, now we evaluate and find the index only the first time we encounter a positional node, and then reuse that index for all subsequent elements in the source document, reducing the complexity to O(n).

----
#### AI description  (iteration 1)
#### PR Classification
Performance improvement

#### PR Summary
This pull request optimizes the query positional update process, making it 10x faster for handling 1 lakh elements.
- `bson_update_operators_workflow.c`: Added `indexOfPositionalTypeQueryFilter` parameter to various functions to avoid redundant evaluations and improve performance.
2024-10-25 09:11:39 +03:00
Cornelius Boateng aa43200a75 Merged PR 1486812: [OSS] Tests Migration Part 13 [1 Test]
### Does this PR have any customer impact? No

### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc) Migration

### 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

### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))

### Description

Tests migration to OSS
2024-10-25 09:11:39 +03:00
Deepak Bisht d325973fd0 Merged PR 1424623: $text and $geoNear index support enhancement for mandatory index usage
### 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

### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
- $geoNear, $near and $nearSphere queries will require suitable geospatial indexes to be present in the collection.

### Description
Make $geoNear require index and fail if no suitable index is found.
Also move $text to same infrastructure to mandate index usage

Steps:
- Check if the index paths are created for Geonear and Text queries in the planner.
- If not update the query tree to only have quals needed to generate the index path and again try to create index path using
`create_index_paths`.
- If the index paths are created then revert back to original query but retain the index path created and allow the query.
- else return error that the indexes were not found for the query
- Clean customsetup.js to not pass key if key is missing is JStest that is handled on the backend now

----
#### AI description  (iteration 1)
#### PR Classification
Enhancement for mandatory index usage in `$text` and `$geoNear` queries.

#### PR Summary
This pull request enhances the support for mandatory index usage in `$text` and `$geoNear` queries by ensuring the appropriate index paths are enforced.
- `planner.c`: Added functions `ProcessQueryOperatorsWithSortClauses` and `ForceIndexForQueryOperators` to handle index path enforcement for special query operators.
- `metadata_cache.c`: Introduced functions `BsonGistGeographyOperatorFamily` and `BsonGistGeometryOperatorFamily` to fetch OIDs for BSON GIST spherical geometries.
- `helio_bson_text_gin.h`: Added `ForceIndexQueryOperatorData` struct to manage index enforcement for special query operators.
- `index_support.c`: Updated `ProcessRestrictionInfoAndRewriteFuncExpr` to set `QUERY_OPERATOR_TEXT` type and handle text index enforcement.
- Removed legacy test cases for `$nearSphere` with coordinate pairs from `bson_query_operator_near_nearsphere.out`.
2024-10-17 11:43:08 +03:00