### 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
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
Fixes large buffer area bug where all the points of a shape are covered by the buffer area but the shape itself is not container, we were returning false positives in this case leading to failing geo_s2within_line_polygon_sphere.js.
With this we check for intersection with the compliment area in case the buffer area is greater than hemishpere of earth. If intersection is there that means the shape lies outside buffer area so we return false.
**Note:** this will also result in perf improvement for centerSphere radius greater than pi as in that case we just return true without any recheck.
Related work items: #2992082
### 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
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
adding support for $dateTrunc mongo operator
Related work items: #2019212
### 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
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
This PR addresses compatibility issues between $geoWithin and ST_Covers. It aims to fix some issues and outline others that are not easily resolved at the moment.
**Issue 1**: PostGIS uses a clockwise orientation rule for polygons, where exterior rings should be oriented clockwise and hole rings should be oriented counterclockwise. This is different from the GeoJSON standard specification, which is the opposite. Therefore, we need to ensure that all our polygons follow a clockwise orientation to be modeled correctly.
Few referrence where the difference is mention:
1- https://gis.stackexchange.com/questions/306567/postgis-geojson-query-not-validating#comment496061_306571
2- https://dev.to/rodreegez/geojson-right-hand-rule-2idk
**Solution**: This PR fixes the issue by forcing polygons to follow a clockwise orientation. This resolves some cases where a polygon sharing a boundary point is considered a match in ST_Covers. Without this fix, the same polygon or any shape sharing a boundary point would not be considered a match.
**Issue 2**: For a Multi*/Multi* GeoJSON type coverage, PostGIS expects a single component to cover all the components of the other GeoJSON, which is not the behavior in Mongo.
**Solution**: This PR fixes the issue by reading individual components from Multi*/GeometryCollection GeoJSON types and calling ST_Covers for each one individually. If all components are covered by the query, it is considered a match.
**Issue 3**: The coverage of polygons with holes is faulty in PostGIS, and there is no workaround for this issue. These limitations are documented and should throw not supported error for now until we fix this in pgmongo layer.
Mongo DB also has some undefined behaviors as they don't guarantee degeneracy https://www.mongodb.com/docs/manual/reference/operator/query/geoWithin/#degenerate-geometry, where the polygon doesn't guarantee to contain another polygon sharing its boundaries.
Also along with this PR the wkb iterator now follows a visitor patter in order to be reusable for other scenarios as well e.g. wkb traversing logic of $centerSphere is now also used for multi multi geowithin checks
Related work items: #2958169
### 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)
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
Add inverseMatch aggregation stage
Currently it supports a spec like:
```
{ path: <path>, input: <doc or array of docs/path expression>, defaultResult: [optional | <bool> ]}
```
So if we want to fetch the input to the document query from an external collection, a lookup stage would need to be added prior to the inverseMatch.
The next stage of this feature is to support a spec like:
```
{ path: <path>, fromCollection: <coll>, pipelines: [$match/$project/$limit], defaultResult: [optional | <bool> ]}
```
### Does this PR have any customer impact?
No
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
OSS
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
Yes
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
N/A
### Description
Start bringing down the Public surface area with back compat for helio_api
### 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
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
We defaulted to PG16, but some parts were still left as 15.
### Does this PR have any customer impact?
No
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Test
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
No
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
N/A
### Description
Adds a test showing the public api surface of Helio. Any changes to this will update the test output and allows us to see (roughly) what the exports are.
These can then be trimmed as part of the OSS effort.
### 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
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
N/A
### Description
Fixes bug in query generation for FirstN/LastN as reported by FerretDB.
### 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
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
N/A
### Description
- Add support for colocating tables in Postgres using the citus colocation mechanisms.
- Add support for modifying colocation with collMod
- Add support for querying shardCount and colocationId of tables in Mongo
Do this in a way that extends Helio using hooks.
### 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
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
Flaky test fix for $currentDate update op.
The currentDate related test in `bson_update_document_tests.sql` is flaly.
The test is taking a begin timestamp, then doing the update with $currentDate, then taking an end timestamp after the update, and expecting that the updated timestamp should be between the begin and end timestamps. But in the flaky case, it wasn't.
The error log:
`Updated timestamp "a" : 1710989509000 should be between 1710989507998 and 1710989508001`
Notice the updated timestamp for field "a" is exactly 1 second more than the begin/end timestamp.
It looks like, it was happening due to a rounding issue at the edge case (and which is why its flaky).
### 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
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
Remove msdata references from OSS
[OSS] Remove msdata references
### Does this PR have any customer impact?
No
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Dev environment
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
No
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
Use PG16 in dev container
### 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
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
Change "ok" message type from int to double, to simulate MongoDB response.
[OSS] Modify update comment response
### 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
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
MongoDB responds with `"ok": float64(1)`, and Helio responds with `"ok": int32(1)}`. This PR modify count command response to simulate MongoDB response.
### 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
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
building the project under debian 12 failed with dangling pointer warning. and error existing memory usage
optimization was using compiler dependent feature that should be removed.
### Does this PR have any customer impact?
Yes
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Log fix
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
No
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
NA
### Description
1. Turn-off all cron statements prior to execution.
2. Minor log fix.
### 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
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
The delete command, MongoDB responds with `{"n": int32(1), "ok": float64(1)}`, and Helio responds with `{"ok": int32(1), "n": int32(1)}`. This PR modify delete command response to simulate MongoDB response.
### Does this PR have any customer impact?
No
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Bufix
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
No
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
N/A
### Description
Per reports for Helio, remove $clusterTime as a field ignored by Helio.
### 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
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
N/A
### Description
This was a bug reported by Ferret. Removing the perf optimization due to a scenario being broken.
### 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
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
The insert command, MongoDB responds with `{"n": int32(1), "ok": float64(1)}`, and Helio responds with `{"ok": int32(1), "n": int32(1)}`. This PR modify insert command response to simulate MongoDB response.
### 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
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
check for the git index file assumed specific placement of the root dir and failed
when used as submodule
This fix make sure git can find the index file
### Does this PR have any customer impact?
Yes - in 1.16
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Perf
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
Yes
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
In Postgres default behavior for Group by/Distinct is to ORDER BY the Grouping term/Distinct which means building a tuple sort + Ordering it before doing the group.
However, if the type defines a hash operator class then the GROUP will use a HashAgg instead of OrderedAgg which is better since it only needs to handle equality (and not Sorted).
Implement a bson hash operator class and add it to 1.15. When the schema deploys it will automatically pick this in the planner.
### 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)
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
From the remaining TODOs handles the following:
- [Done] To handle arrays we do a `$unwind` - move that to doing an eq/in based on the input: This is done by adding a makeArray aggregation operator and using that with `$in` expression
- [Done] Think about cycles: Add a visited check and ignore nodes that are visited before.
- [Done] Need to handle maxDepth infinite recursion more gracefully with $graphLookup.
- [Done] Need to validate against jstests
Still TODO:
- More testing on dotted paths and arrays & reducing traversals
- Implement a hash aggregate operator class for BSON
### Does this PR have any customer impact?
Yes
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Bugfix/Features
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
No
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
1) Enable fast scan by default
2) Fix memory leaks in unique index creations
3) Add option to enable large index keys on an account basis by default
4) Introduce Index term version v1 as a valid version for single path indexes
5) Use index version v1 to ensure metadata terms are marked metadata
6) Enable index term truncation by default on V1 index version
### 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
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
pgmongo_1.14.md
### Description
Add support for all GeoJson types with $centerSphere.
Postgis returns true if 1 out of n points in the doc's GeoJson lies inside the query, but mongodb returns true only if all points are inside. So I added runtime check for all points.
Also added a better way to iterate through WKB buffer without having to worry about segfault if traversal overflows (See IncrementBufferDataBySize in geospatial_query_operator)
Related work items: #2928131
With 100K documents optimizes $exists:true/false in the index from 5x -> 10x depending on the query and scenario now that $exists is not a partial match for non-wildcard indexes.
The optimization uses a new term, the non-exists term, which is a term with no path `""` and of bson type `undefined`, which is generated when the document doesn't contain a field for the indexed path.
This gives us more information when doing index evaluations and we can compare against the non-exist term when doing null equality comparisons or exists checks.
### 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
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
Bug fix while creating the WKB for geometries/geographies where we fill the number of components later (num of points, num of linestring, num of polygons, num of geometries etc) after doing the traversal.
Earlier we used to store the memory address of the place where the `number` is needed to be updated but thats bad because with larger geometries, reallocation of buffer happens and we were losing the place to update the `number`; now instead of storing the memory address, we store the the position relative to the start of buffer so even if the memory is reallocated we know where to add the `number`.
Related work items: #3012835
### 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
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
N/A
### Description
Implement the basic skeleton for $graphLookup under a feature flag.
Remaining TODOs:
1) To handle arrays we do a $unwind - move that to doing an $eq/$in based on the input
2) Implement a hash aggregate operator class for BSON so we can use a UNION query instead of UNION ALL
3) Need to validate against jstests
4) Need to handle maxDepth infinite recursion more gracefully with $graphLookup.
5) More testing on dotted paths and arrays
6) Think about cycles
Related work items: #1798581
### 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
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
Flakyness fix in $currentDate tests.
It appears to be rounding error and failure log didnt give much info.
Took these steps to eleminate (or atleast reduce flakyness)
- Used FLOOR/CEIL instead of ROUND to be in control of what we want.
- Used correct datatype (reduced unnecessary typecasting, and usage of numeric datatypes).
- Added better error log, so that if a test fails, we will know, if it's a real issue of big time difference and not just rounding error.
Related work items: #2999363
Add inverse match UDF to 1.14 schema to be able to use it sooner in prod
This UDF will be used for the new $inverseMatch aggregation stage which will take the document to apply the match on, the path where the document defines the query and the input value to evaluate the query against.
Since we need a UDF to do this against every document in a query like so:
```
SELECT document FROM mongo_data.documents_1_102045 collection WHERE helio_api.bson_dollar_inverse_match(document,{ "path": "a", "input" : [ { "foo" : { "$numberInt" : "3" } } ] }'::mongo_catalog.bson)
```
This is schema dependent, let's add a no-op UDF so that we can use the 1.14 train and that way in the 1.15 branch it will be already available to be used by the binary since we ship schema n-1 always.
### Does this PR have any customer impact?
No
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Logging
### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
No
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
decreased log level to DEBUG1 for decimal 128 operations
### 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
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
Adds support for $dateFromParts aggregation operator
Related work items: #2019203
### 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
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
fix seg fault in currentOp while reading blocking PIDs for an acitivity. Currently it was read as a varlen data but it is INT8 and should be read as by value.
### Description
Move main to 1.15 binary and 1.14 schema and fix rename collection version
Rename collection PR went in after we forked the 1.14 release branch but before main was bumped to the new schema and binary version, so fix that in this PR as well.
### 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
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
- Remove Buffers from explain - it's not stable across runs and PG versions
- in the scenario where you had an intersection filter, when we set the cost to 0, a bitmapAnd path could be picked. Ensure for PK lookups we always prefer the PK index.
### 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
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
N/A
### Description
Make more JSTests pass by implementing or fixing bugs
### 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)
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
More
Related work items: #2453917
### 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
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
### Description
We will enable the HNSW index on SKU m40 and above.
The GUC pgmongo.enableVectorPreFilter is "on" by default, on the lower SKUs it will be set to be "off" by control plane
Related work items: #2600904