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
2024-01-12 19:10:20 +00:00
2023-12-27 09:20:09 -08:00
2024-01-12 19:10:20 +00:00
2024-01-12 19:10:20 +00:00
2024-01-12 19:10:20 +00:00
2024-01-12 19:10:20 +00:00
2023-12-27 09:20:11 -08:00
2023-12-27 09:20:11 -08:00
2023-12-27 09:20:10 -08:00

Project

This repo has been populated by an initial template to help get you started. Please make sure to update the content to build a great experience for community-building.

As the maintainer of this project, please make a few updates:

  • Improving this README.MD file to provide a great experience
  • Updating SUPPORT.MD with content about this project's support experience
  • Understanding the security reporting process in SECURITY.MD
  • Remove this section from the README

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.

2026-11-05 10:29:15 -05:00
Languages
C 78%
PLpgSQL 16.2%
Rust 3.9%
Shell 1.1%
Go 0.3%
Other 0.3%