matrixorigin / matrixorigin/matrixone

[Bug]: ST_FrechetDistance and ST_HausdorffDistance ignore geographic SRID 4326

Open
#28,194 0 comments 0 reactions 1 assignee Claimed by @XuPeng-SH View on GitHub
kind/bug needs-triage
Dominant language
Go
Stars
1.9k
Forks
311
Avg merge
1d 3h
Merged PRs (30d)
768

Description

## Description

`ST_FrechetDistance` 和 `ST_HausdorffDistance` 忽略 geometry 的 SRID 4326,始终用平面 `math.Hypot` 计算坐标差。地理坐标相差 1° 时,两者返回 `1`,与 SRID 0 的结果完全相同,而正确结果应使用地理 SRS 的长度单位,约为 111 km。

## Environment

- Branch: `main`
- Commit: `e7bb0572235ec4bac81eb098eb0ad8900f0065ab`
- Deployment: macOS arm64,单节点 MatrixOne,默认 launch 配置
- Date: 2026-09-05

## Steps to reproduce

```sql
SELECT ST_FrechetDistance(
ST_GeomFromText('LINESTRING(0 0,1 0)', 4326),
ST_GeomFromText('LINESTRING(0 1,1 1)', 4326)
);

SELECT ST_HausdorffDistance(
ST_GeomFromText('LINESTRING(0 0,1 0)', 4326),
ST_GeomFromText('LINESTRING(0 1,1 1)', 4326)
);

-- Cartesian control
SELECT ST_FrechetDistance(
ST_GeomFromText('LINESTRING(0 0,1 0)', 0),
ST_GeomFromText('LINESTRING(0 1,1 1)', 0)
);
```

## Actual behavior

```text
Frechet, SRID 4326 = 1
Hausdorff, SRID 4326 = 1
Frechet, SRID 0 = 1
```

## Expected behavior

SRID 4326 应走 geodetic distance kernel,并按 SRS 长度单位返回结果。MySQL 8.3.0 对两个 4326 查询均返回 `111319.49079326246`,SRID 0 控制仍返回 `1`。

Reference: https://dev.mysql.com/doc/refman/8.0/en/spatial-relation-functions-object-shapes.html

## Stability and controls

- 常量表达式各重复 3 次,结果稳定。
- 使用两个 `geometry srid 4326` typed columns 存储相同 LineString 后再次计算,MO 仍返回 `1`,MySQL 仍返回 `111319.49079326246`。
- SRID 0 平面场景 MO 与 MySQL 均为 1。
- `ST_Distance`、`ST_Length` 已对 SRID 4326 分派到测地内核,说明离散距离是漏接 SRID 分派,而不是系统统一采用角度单位。

## Evidence and code analysis

- Exact main commit: https://github.com/matrixorigin/matrixone/commit/e7bb0572235ec4bac81eb098eb0ad8900f0065ab
- SQL wrappers decode geometry but never inspect type SRID: https://github.com/matrixorigin/matrixone/blob/e7bb0572235ec4bac81eb098eb0ad8900f0065ab/pkg/sql/plan/function/func_binary.go#L9728-L9784
- Both core algorithms use planar `math.Hypot`: https://github.com/matrixorigin/matrixone/blob/e7bb0572235ec4bac81eb098eb0ad8900f0065ab/pkg/geo/discrete.go#L26-L76
- Existing SRID-aware distance dispatch for comparison: https://github.com/matrixorigin/matrixone/blob/e7bb0572235ec4bac81eb098eb0ad8900f0065ab/pkg/sql/plan/function/func_binary.go#L10114-L10144

## Regression coverage

修复时应覆盖 SRID 0/4326 的 LineString,赤道/高纬度/反经线、参数交换、typed columns、GEOMETRY32、越界经纬度,以及与 `ST_Distance` 的单位一致性。

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.