Commit Graph
57 Commits
Author SHA1 Message Date
Santiago Fernandez Madero e8ff45b702 Merged PR 1325618: Treat path expressions as CURRENT.path as that should be the behavior
### 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

CURRENT is a system variable that points to ROOT (current document) unless it is overridden, if it is overridden, path expressions should point to that value rather than ROOT, which means "$a" is equivalent to "$$CURRENT.a".

This PR changes path expressions to be `CURRENT.path` rather than just `path`.

This hasn't been a problem since we don't support $let yet, however, now that we're adding expressions that can define variables, like `$map` this showed up on JS Tests.
2024-04-19 12:03:52 +03:00
Ujjwal Agrawal 7a010db2d7 Merged PR 1304026: [Bugfix] Some self intersecting polygons don't throw error
### 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 jstest for self intersecting polygons

Related work items: #2894103
2024-04-19 12:03:52 +03:00
Ayush Saluja 808ebb466f Merged PR 1324589: [pgmongo] $dateDiff operator 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)

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

### Description

Related work items: #2019195
2024-04-19 12:03:52 +03:00
Jia Hu 👻 f7fc1d3bfd Merged PR 1315834: add array operator: $map, $reduce
### 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
add array operator: $map, $reduce

Related work items: #2019117, #2019128
2024-04-19 12:03:52 +03:00
Vinod Sridharan 8c7173a2d9 Merged PR 1325613: Lookup Index pushdown
### 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
Lookup Index pushdown: Allow index pushdown of lookup queries for both left and right queries.
For _id joins, push to the B-tree index and use the object_id column.
For RUM indexes, introduce a new function and support that allows pushing to the index based on the specified path rather than the document itself.

This caused a customer $lookup query to go from taking 45+ mins and timing out to finishing in under 3 mins
2024-04-19 12:03:52 +03:00
Ayush Saluja 19f13d0fb9 Merged PR 1291177: [pgmongo] DateAdd datesubtract aggregation operators
### 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
DateAdd , dateSubtract aggregation operator pr

Related work items: #2019193, #2019208
2024-04-19 12:03:52 +03:00
Deepak Bisht 58afe0aa8f Merged PR 1275776: [Pgmongo] - Part 1 GeoNear aggregation stage, add documentation and necessary operators and functions
### 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)
Yes

### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
Support $geoNear aggregation stage

### Description
Add the design doc and necessary operators and functions needed for $geoNear

Also,
1-  Implement the $geoNear aggregation stage skeleton and support all options.
     - `distanceField`,
     - `near` (both legacy, geojson point)
     -`includeLocs`,
     -`minDistance` & `maxDistance`
     - `distanceMultiplier`
     - `key`
2- Support index pushdown of the stage to `2d` and `2dspher` index.
    - spherical / non-spherical distance support for `2d` index.
    - spherical distance support for `2dsphere` index

Things still a TODO.
1- ~~Update the mongo explain plans for geonear stage~~.
2- Make the stage require an index always, currently it can be executed without index too.
3- Fix projection for nested array fields.
4- Make common test setup for running $geoNear queries in JSTests which don't require key in mongo.
5- More testing and validations with other stages that can use $geoNear.
6- Test batching and cursor support.
7- Overall testing and validations

Related work items: #3000189, #3065270
2024-04-19 12:03:52 +03:00
Ujjwal Agrawal 38ec9b877d Merged PR 1316954: Change postgis runtime matcher functions for $center
### 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))
1.16
### Description

Use st_dwithin and st_expand for $center

Related work items: #2894556
2024-04-19 12:03:52 +03:00
Vinod Sridharan 6f1ebc3957 Merged PR 1317779: [Colocation] Prep for Colocation Hotfix
### 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)
Yes
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))

### Description
Prep to do schema hotfix for colocation. Port to 1.13 / 1.14
2024-04-05 13:43:51 +03:00
Vinod Sridharan 2da6633812 Merged PR 1314099: Colocation Support Part 2
### 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
2024-04-05 13:43:51 +03:00
Ujjwal Agrawal f09e98eced Merged PR 1314512: Geospatial module code cleanup
### Does this PR have any customer impact?
No
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Code cleanup
### 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

Cleanup dead code

Related work items: #3059119
2024-04-05 13:43:51 +03:00
Ujjwal Agrawal d340c1951b Merged PR 1304364: [Bugfix] False +ve when $centerSphere covers points but not the shape itself
### 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
2024-04-05 13:43:51 +03:00
Shuai Tian 🚀 fa33a920c7 Merged PR 1310426: add timestamp operator: $tsSecond, $tsIncrement
### 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
add timestamp operator $tsSecond, $tsIncrement

Related work items: #3027168, #3027169, #3027170
2024-04-05 13:43:51 +03:00
Ayush Saluja 1a9dcdd00b Merged PR 1277272: $dateTrunc aggregation operator support
### 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
2024-04-05 13:43:51 +03:00
Deepak Bisht fb2ad03743 Merged PR 1278872: [Pgmongo][Geospatial]: Fix orientaion of polygons, and enhance multi* multi* geowithin match checks
### 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
2024-03-29 10:49:37 +03:00
Santiago Fernandez Madero 2ad7381f79 Merged PR 1291973: Add inverseMatch aggregation stage
### 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> ]}
```
2024-03-29 10:49:37 +03:00
Lucas Borges Fernandes 5fdd275289 Merged PR 1252995: complete_upgrade UDF in C and initialize_cluster version check
This PR adds:

* complete_upgrade UDF in C;
* initialize_cluster version check
2024-03-29 10:49:37 +03:00
Vinod Sridharan 1f8b17e477 Merged PR 1311551: [Part 1: API] Reduce OSS Public API surface
### 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
2024-03-29 10:49:37 +03:00
Vinod Sridharan 14827ac3f9 Merged PR 1307723: [Colocation: Part 1] Support basic colocation of tables
### 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.
2024-03-29 10:49:37 +03:00
Lucas Borges Fernandes ab11777a85 Merged PR 1290864: $push accumulator for $group pipeline stage
### Description
Implementation of the $push accumulator for $group pipeline stage.

Related work items: #2988400
2024-03-22 11:28:50 +03:00
Vinod Sridharan 7c778c19f8 Merged PR 1296261: Graphlookup part2 - Enable Tests and fix up issues
### 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
2024-03-22 11:28:50 +03:00
Vinod Sridharan 6e23d4ff85 Merged PR 1300893: [Misc] Index changes and bugfixes
### 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
2024-03-22 11:28:50 +03:00
Ujjwal Agrawal ee172ea8d1 Merged PR 1279069: $centerSphere geo operator part 2: add support for all GeoJson types
### 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
2024-03-22 11:28:50 +03:00
Santiago Fernandez Madero 400da6cd09 Merged PR 1274835: Introduce non exists index term for exists and null equality scenarios
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.
2024-03-15 13:58:37 +03:00
Deepak Bisht 9d49cabefa Merged PR 1295076: [Geospatial] - Fix results not returned when the query WKB is big
### 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
2024-03-15 13:58:37 +03:00
Vinod Sridharan 6a699bcd46 Merged PR 1289862: Part 1: Skeleton for the GraphLookup aggregation Stage
### 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
2024-03-08 14:01:20 +03:00
Ayush Saluja affba201b1 Merged PR 1276508: $DateFromParts aggregation operator
### 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
2024-03-08 14:01:20 +03:00
Vinod Sridharan c00dcf25a4 Merged PR 1288370: [Tests] Make more tests pass
### 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
2024-03-04 09:53:14 +03:00
Vinod Sridharan 38ae02ad41 Merged PR 1286968: [JSTests] Make exclusion test pass
### 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
2024-03-01 17:24:28 +03:00
Tanvi Bhandari 8d461c2b27 Merged PR 1271218: CurrentOp showing the progress for Index Build in background
### 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)
Yes

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

### Description
Issue:
Since the owner of scheduled cron job for index build background is admin user i.e. 'postgres' in prod, the CREATE INDEX CONCURRETLY queries are owned by 'postgres' user in pg_stat_activity.
And non-admin user who requests for currentOp to get progress of running indexes, does not have enough privilege to read queries owned by admin user in pg_stat_activity.

Solutions:
From inside running cron-job, create LibPQ connection as the non-admin user for CREATE INDEX CONCURRENTLY. The pre-requisite for this approach is that we have the information of user-oid who has submitted the request in queue. I.e. This needs user_name column in index_queue table.

Related work items: #2961369
2024-03-01 17:24:28 +03:00
Vinod Sridharan d4018f7a46 Merged PR 1283033: [PG16] Part2: Enable backend tests for PG16
### 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))

### Description
Changes:
- Unify rum_tuplesort_get_estimated_itemcount between PG16/PG15
- Remove set local force_parallel_mode TO ON; - This flag is removed in PG16
- Remove legacy query generation for lookup tests
- Citus 12.1 made the default behavior not to push down filters - set htat GUC to true for the extension
2024-03-01 17:24:28 +03:00
Vinod Sridharan 0e156314f6 Merged PR 1282170: [PG16] Enable building the extension with PG16
### 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

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

### Description
Part 1: Enable building the extension and fix up pieces for building with PG16.

With this the core extension builds with PG16 and *most* of the backend tests pass. At this point, checking this in as a checkpoint (to ensure compat is retained) as more features are lit up with PG16

One thing to note is PG16 builds changes the default visibility of exports to 'private' that means that to make the current build work, we need to override that to 'default/public'. This needs to be fixed but is left as-is currently to make incremental progress.

There were some attempts to create exports in the code that are left as-is
2024-03-01 17:24:28 +03:00
Jayanta Mondal e916817aa6 Merged PR 1276499: [backend] Skipping optimizing with only $in
### 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

single  fix
2024-03-01 17:24:28 +03:00
Vinod Sridharan 3b6e07f30f Merged PR 1281490: Query operator native support part 1: Enable expansion of the query operator
### 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)
Yes (OSS)

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

### Description
Today in OSS the query operator was evaluated at runtime - move this to expansion of hte operator at planning time using the simplify function.
2024-03-01 17:24:28 +03:00
Parag Jain 7bb916a093 Merged PR 1251259: Run backend test against citus 12 and removed existing change_stream with backward compat
This PR has following changes :
1.removed change_description column from mongo_data.document table because from citus 11.2 there was a [fix](https://github.com/citusdata/citus/commit/27e867afbc72180fb04b618293af5b3a944b6cd4) which results into [behavior mismatch in mongo_api_v1.collection function](https://msdata.visualstudio.com/CosmosDB/_workitems/edit/2942338). To handle this removed change_description column from mongo_data.document table.
2. modified backend pipeline to run backend test against citus 12 container image as well.
3. removed watch_collection and change_feed sql function as it is no longer needed in 1.13 binary.

subsequent PR :
Modify backend_test and deployment_build_pipeline  to run jstest and cSharpe test aginst citus 12.
Change Naming Convention of CosmosDbDrop and deployArtifact for citus-11 and citus-12

Related work items: #2902318, #2942338
2024-02-23 14:49:18 +03:00
Vinod Sridharan 37744ff32a Merged PR 1279725: [Flex] Enable Data plane metrics emission from the Extension
### Does this PR have any customer impact?
No

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

### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
No(ish)

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

### Description

Add function to emit data plane metrics from teh extension. Add a cron job to publish that every min.
Register that function as a cron job in flex.

This first part publishes the FeatureCounter data into warm path config as so:
![image.png](https://msdata.visualstudio.com/ba574a88-a171-48e0-8fcb-5fef6d23739c/_apis/git/repositories/501a5e7e-ffdc-4d1e-a5e6-910f73c6eb9a/pullRequests/1279725/attachments/image.png)

Subsequent changes will be made to add more metrics into the emission path.
2024-02-23 14:49:18 +03:00
Vinod Sridharan b3e28caf50 Merged PR 1280370: [Performance] Improve performance of point reads
### 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

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

### Description
For point reads that go into the B-tree index, we were also evaluating the filter `docid @= { _id : value}` again even though those were equivalent.

Remove the extraneous filter to improve point read performance.
2024-02-23 14:49:18 +03:00
Ujjwal Agrawal 58ccf507d4 Merged PR 1235816: $centerSphere geospatial shape operator impl: Part 1 support for legacy coordinates and GeoJson points
As finalized in the design review on 10th January, `st_dwithin` shall be used for $center and $centerSphere
For index pushdown `st_dwithin` uses `st_expand` method to calculate the bounding box for given point, so we're using `st_expand` directly at the time of index pushdown, and `st_dwithin` at runtime.
This is part 1 of 2 that implements that change - this returns some false positives as st_dwithin returns true for polygons of which at least 1 point lies within the specified distance. It returns true even if all other points lie outside.
The next part will handle checking all points for distance in runtime.

**Brief summary of design discussion -**
$center used ST_BUFFER to create a buffer area, but using the same for geography has a few drawbacks -
1. If the buffer becomes bigger than a UTM zone or it crosses **the international dateline** it results in undefined behaviour. For example, the above query returns false if we increase the buffer radius to **12000000 (12000 km)** as it crosses the dateline at **(180 90)**.
Hence the query behavior looks like this -

```
[direct: mongos] db> db.geoquerytest.find({"a.b": {$geoWithin: {$centerSphere: [[0, 0], 1.57]}}})   //100013.6 km
[
  { _id: 1, a: { b: [ 10, 10 ] } },
  { _id: 2, a: { b: { long: Long("20"), lat: 20 } } },
  {
    _id: 3,
    a: [
      { b: { long: 25, lat: 25 } },
      [ 30, Decimal128("30") ],
      [ 35, 35 ]
    ]
  },
  { _id: 5, a: { b: { x: Long("12"), y: 12 } } }
]
[direct: mongos] db> db.geoquerytest.find({"a.b": {$geoWithin: {$centerSphere: [[0, 0], 1.6]}}})    //10205 km

```

2. The circle is **imperfect**. It has 8 segments in each quadrant (by default) which may result in boundary cases like below failing -

`SELECT ST_Covers(ST_BUFFER('Point(0 0)'::geography, 630000), 'Point(4.9757 2.66966)'::geography);` returns **false**.

Similar test on native mongo -
```
test> db.coll4.find({"a": {$geoWithin: {$centerSphere: [[0, 0], 0.0987]}}}) //629.5 km
[
  {
    _id: ObjectId("658304b574dc0e47e5cab903"),
    a: { type: 'Point', coordinates: [ 4.9757, 2.66966 ] }
  }
]
```

3. ST_Covers doesn't work well with polygons with holes. So this returns false -

```
SELECT ST_Covers(ST_BUFFER('Point(0 0)'::geography, 50000), 'MultiPolygon(((0.1 0.2, 0.1 0.3, 0.2 0.3, 0.2 0.2, 0.1 0.2), (0.15 0.22, 0.15 0.25, 0.18 0.25, 0.18 0.22, 0.15 0.22)))'::geography);
```

It was decided that ST_DWITHIN be used to overcome these limitations.

There's a bug in Explain behavior where it has a recheck condition even though recheck is set to false, it'll be tracked with this- https://msdata.visualstudio.com/CosmosDB/_workitems/edit/2968574

Related work items: #2903014, #2950457
2024-02-23 14:49:18 +03:00
Vinod Sridharan 3101112245 Merged PR 1262530: Helio API Gateway changes
### 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
Move Gateway to use the Helio_API schema for available top level methods.
2024-02-23 14:49:18 +03:00
Mehmet Yilmaz e329534b27 Merged PR 1265532: [OSS] Refactor some pgmongo references in OSS
### 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
Refactor some pgmongo references in OSS
2024-02-16 13:49:10 +03:00
Ayush Saluja 96408265a7 Merged PR 1248348: [pgmongo] $min $max projection stage operator
This is for supporting the $min, $max in the projection stage.

Related work items: #2954640
2024-02-16 13:49:10 +03:00
Jayanta Mondal 8016914aea Merged PR 1271425: $in query rewrite
### Does this PR have any customer impact?
Limited, the feature is behind a feature flag.

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

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

Queries of the form

```
SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "accid":1, "vid": 1, "val": { "$in": [1, 3]} } }');
```

Will be **effectively** rewritten to

```
SELECT document FROM bson_aggregation_find('db', '{ "find": "in_opt_tests", "filter": { "accid":1, "vid": 1, "val": { "$in": [1, 3]} } }');

```

However, we don't intercept the mongo query and rewrite it. As the `$in` can be used in different query path. Instead, we do the rewrite after the query plan generation, and specifically, when `$in` is shows up a condition in the Index Path. While `$in` today is pushed down to the index, it's not performant.  However, if we rewrite the `$in` to be a `OR` of a set of `$eq` clause, that becomes peformant, as `RUM fast scan` is enabled for `$eq` but not yet for `$in`.  **For, 100K records, the latency goes down from `80ms` to ~`3ms` on devbox.**

**_Explain before rewrite:_**

```
               ->  Bitmap Index Scan on val_accid_vid  (cost=0.00..0.00 rows=1 width=0) (actual time=23.937..23.937 rows=7 loops=1)
                      Index Cond: Index Cond: ((document OPERATOR(mongo_catalog.@*=) '[{ "val" : { "$numberInt" : "1" } }, { "val" : { "$numberInt" : "3" } }]'::mongo_catalog.bson) AND (document OPERATOR(mongo_catalog.@=) '{ "accid" : { "$numberInt" : "1" } }'::mongo_catalog.bson) AND (document OPERATOR(mongo_catalog.@=) '{ "vid" : { "$numberInt" : "1" } }'::mongo_catalog.bson))*/

```

**_Explain after rewrite:_**
```

Custom Scan (Citus Adaptive)
   Task Count: 1
   Tasks Shown: All
   ->  Task
         Node: host=localhost port=58080 dbname=regression
         ->  Bitmap Heap Scan on documents_33000_330023 collection
               Recheck Cond: (((document OPERATOR(mongo_catalog.@=) '{ "val" : { "$numberInt" : "1" } }'::mongo_catalog.bson) AND (document OPERATOR(mongo_catalog.@=) '{ "accid" : { "$numberInt" : "1" } }'::mongo_catalog.bson) AND (document OPERATOR(mongo_catalog.@=) '{ "vid" : { "$numberInt" : "1" } }'::mongo_catalog.bson)) OR ((document OPERATOR(mongo_catalog.@=) '{ "val" : { "$numberInt" : "3" } }'::mongo_catalog.bson) AND (document OPERATOR(mongo_catalog.@=) '{ "accid" : { "$numberInt" : "1" } }'::mongo_catalog.bson) AND (document OPERATOR(mongo_catalog.@=) '{ "vid" : { "$numberInt" : "1" } }'::mongo_catalog.bson)))
               Filter: ((document OPERATOR(mongo_catalog.@*=) '{ "val" : [ { "$numberInt" : "1" }, { "$numberInt" : "3" } ] }'::mongo_catalog.bson) AND (shard_key_value = '4322365043291501017'::bigint))
               ->  BitmapOr
                     ->  Bitmap Index Scan on val_accid_vid
       ...
2024-02-16 13:49:10 +03:00
Ayush Saluja 075acbf3a0 Merged PR 1267038: [pgmongo]Aggregation Operator BinarySize
### Does this PR have any customer impact?
Yes, Support for new

### 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  $binarySize operator in data size.
https://www.mongodb.com/docs/manual/reference/operator/aggregation/binarySize/

Related work items: #2019187
2024-02-16 13:49:10 +03:00
Vinod Sridharan 6c8bf4f145 Merged PR 1268933: Enable Primary key lookup pushdown
### 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
### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))
Push primary key lookup where available
### Description
Due to RUM index limitations today we would push to the rum index even if we are matching a single doc or a few docs. Ensure that we have a primary key lookup if we see an explicit lookup there

Primary key lookup
2024-02-07 23:20:07 +03:00
Zinan Ren 🐾 69118d324f Merged PR 1246367: [Vector Search] Support pre-filtering in search - Part 2
### Known limitations & TODO for part 2
- [ ]  The current implementation intersects results from both vector index and bitmap index, it is actually the post-filtering
- [ ]  Not work for sharded collection

### Part 1 explain result
![](https://msdata.visualstudio.com/ba574a88-a171-48e0-8fcb-5fef6d23739c/_apis/git/repositories/501a5e7e-ffdc-4d1e-a5e6-910f73c6eb9a/pullRequests/1238453/attachments/image.png)

### New explain result
![image (5).png](https://msdata.visualstudio.com/ba574a88-a171-48e0-8fcb-5fef6d23739c/_apis/git/repositories/501a5e7e-ffdc-4d1e-a5e6-910f73c6eb9a/pullRequests/1246367/attachments/image%20%285%29.png)
From mongo command:
```
SELECT document FROM
    bson_aggregation_pipeline('db', '
        {
        "aggregate": "aggregation_pipeline_ivf_filter",
        "pipeline": [
                {
                "$search": {"cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "k": 4, "path": "v", "filter": { "a": "some sentence" }, "nProbes": 1 }  }
                }
        ],
        "cursor": {}
}');

```
To psql command
```
1. SELECT c1(search query):
			SELECT
				document,
				(public.vector(mongo_catalog.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<=>) public.vector(mongo_catalog.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "1" }, "path" : "v" }'::mongo_catalog.bson, 'vector'::text), 3, true)) AS orderVal,
				ctid
			FROM
				mongo_data.documents_1 collection
			WHERE
				shard_key_value = 0
				AND ((mongo_catalog.bson_extract_vector(collection.document, 'v'::text) IS NOT NULL))
			ORDER BY
				(public.vector(mongo_catalog.bson_extract_vector(collection.document, 'v'::text), 3, true) OPERATOR(public.<=>) public.vector(mongo_catalog.bson_extract_vector('{ "vector" : [ { "$numberDouble" : "3.0" }, { "$numberDouble" : "4.9000000000000003553" }, { "$numberDouble" : "1.0" } ], "k" : { "$numberInt" : "1" }, "path" : "v" }'::mongo_catalog.bson, 'vector'::text), 3, true))
2. SELECT c2(filter query):
			SELECT
				ctid
			FROM
				mongo_data.documents_1
			WHERE
				shard_key_value = 0
				AND document @@ '{ "a": "some sentence" }'

3. JOIN c1 ON c1.ctid = c2.ctid
			SELECT
				c1.document
			FROM c1 JOIN c2 ON c2.ctid = c1.ctid
			ORDER BY c1.orderVal
			LIMIT 1
```

Related work items: #2586299
2024-02-07 23:20:07 +03:00
Vinod Sridharan da2c098f3c Merged PR 1265302: Make sh.status() work
### 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))
Make sh.status() work in mongo shell.

### Description
sh.status() used to return
![image.png](https://msdata.visualstudio.com/ba574a88-a171-48e0-8fcb-5fef6d23739c/_apis/git/repositories/501a5e7e-ffdc-4d1e-a5e6-910f73c6eb9a/pullRequests/1265302/attachments/image.png)

With these changes, this now looks like:
![image (2).png](https://msdata.visualstudio.com/ba574a88-a171-48e0-8fcb-5fef6d23739c/_apis/git/repositories/501a5e7e-ffdc-4d1e-a5e6-910f73c6eb9a/pullRequests/1265302/attachments/image%20%282%29.png)
2024-02-07 23:20:07 +03:00
Tanvi Bhandari 08365f523c Merged PR 1262739: To enable feature in 1.12 and main release as well
### 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))
To enable IndexBuild Background in 1.12

### Description
To enable IndexBuild Background in 1.12 on old schema and new schema as well based on cluster version.
2024-02-07 23:20:07 +03:00
Vinod Sridharan 3775e5a27a Merged PR 1263670: Add more checks for OSS references
### 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 more checks for OSS references
2024-02-07 23:20:07 +03:00
Tanvi Bhandari b1d31514b2 Merged PR 1244012: Misc changes 'mongo_catalog.pgmongo_index_queue'
1. Make index queue table name compatible to oss i.e its name should be helio_api_catalog.helio_index_queue and grant permission for helio_admin_role

2. Add citus_add_local_table_to_metadata('helio_api_catalog.helio_index_queue')

3. Due to extension upgrade scripts, the table was created on all nodes of cluster. Therefore, dropped the table from all nodes.
And create it only on coordinator using initialize_cluster(for new cluster) and complete_pgmongo_upgrade (for upgrade path)

4. Simplify CleanUpIndexBuildRequest query

Related work items: #2897026
2024-01-31 12:06:30 +03:00
Vinod Sridharan 1ca13d07e5 Merged PR 1253069: [Truncation] Fix up a bug with single path wildcard index with truncation
Fix up a bug with single path wildcard index with truncation
2024-01-31 12:06:30 +03:00