Skip to content

[Bug]: MBRTouches returns true for equal points and contained point MBRs #28190

Closed

Description

@Ariznawlll

Description

MBRTouches 把任意零面积交集都当作 MBR 接触,未排除一个退化 MBR 完全位于另一个 MBR 内部或两个退化 MBR 相等的情形。因此相同点、以及矩形内部的点都会错误返回 1。

Environment

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

Steps to reproduce

SELECT MBRTouches(ST_GeomFromText('POINT(0 0)'), ST_GeomFromText('POINT(0 0)'));

SELECT MBRTouches(
  ST_GeomFromText('POINT(2 2)'),
  ST_GeomFromText('POLYGON((0 0,4 0,4 4,0 4,0 0))')
);

-- boundary control
SELECT MBRTouches(
  ST_GeomFromText('POINT(0 2)'),
  ST_GeomFromText('POLYGON((0 0,4 0,4 4,0 4,0 0))')
);

Actual behavior

equal points          = 1
point inside rectangle = 1
point on boundary      = 1

Expected behavior

equal points          = 0
point inside rectangle = 0
point on boundary      = 1

MySQL 8.3.0 对相同输入返回上述 expected result。

Stability and controls

  • 三个场景各重复 3 次,结果稳定。
  • 两个矩形仅共享一条边时,MO 与 MySQL 都返回 1。
  • 常量表达式、表列扫描以及创建 R-tree 空间索引后的查询均可复现。
  • 576 组 MBR 配对中观察到相同模式;其他 MBR 谓词的结果用于交叉验证。

Evidence and code analysis

  • Exact main commit: e7bb057
  • Current bboxTouches implementation:
    func bboxTouches(a, b geo.BBox) bool {
    ix1, iy1 := math.Max(a.MinX, b.MinX), math.Max(a.MinY, b.MinY)
    ix2, iy2 := math.Min(a.MaxX, b.MaxX), math.Min(a.MaxY, b.MaxY)
    if ix1 > ix2 || iy1 > iy2 {
    return false
    }
    // Intersect, but only along an edge or at a point (zero-area intersection).
    return ix1 == ix2 || iy1 == iy2
    }

实现只计算两个包围盒交集,并以 ix1 == ix2 || iy1 == iy2 判断接触。点的 MBR 本身在两个维度上都是零宽度,所以相同点或内部点的交集天然满足该条件,即使它们没有“内部不相交且边界相交”的 touches 关系。

Regression coverage

修复时应加入 Point-Point、Point-Line MBR、Point-Polygon MBR、退化 LineString MBR、边/角接触矩形、内部包含、完全相等和不相交场景;覆盖参数交换、表列与空间索引路径。

Activity

  1. added this to the MO-202609 milestone on Sep 5, 2026
  2. added
    kind/bug
    on Sep 5, 2026
  3. added theissue type on Sep 5, 2026
  4. self-assigned this
    on Sep 5, 2026
  5. XuPeng-SH commented on Sep 13, 2026

    @XuPeng-SH
    Contributor

    Fix is submitted in PR #28811.

    The predicate now treats MBRTouches as MBR intersection without relative-interior intersection. This removes the false positives for equal points and points strictly inside an area, while preserving true boundary contact. The same change separates MBRContains/MBRWithin from inclusive MBRCovers/MBRCoveredBy; MBROverlaps keeps its previous coverage behavior.

    Coverage includes the reported point cases, point/line/area dimensions, boundary and equality controls, inverse/symmetry properties, plus public SQL constant and table-column regressions. Focused and full function-package UT, go vet, and incremental golangci-lint passed. Local BVT was not run because the configured host has an unrelated active MatrixOne service; PR CI is running.

  6. added a commit that references this issue on Sep 13, 2026
    4d18bee
  7. XuPeng-SH commented on Sep 14, 2026

    @XuPeng-SH
    Contributor

    已由已合并的 PR #28811 完成修复并验证:MBRTouches 的退化 MBR 判定及相关 MBR 谓词回归已覆盖。关闭为 completed。

  8. added 3 commits that reference this issue on Sep 17, 2026
    2d5ee55
    54699c5
    ad63ad8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions