Skip to content

[Bug]: MBRWithin treats boundary coverage as strict within #28192

Closed

Description

@Ariznawlll

Description

MBRWithin 与 MBRCoveredBy 当前调用完全相同的包含判定,导致位于另一个 MBR 边界上的点同时满足两者。Within 要求第一个 MBR 的内部位于第二个 MBR 的内部;仅被边界覆盖时应由 MBRCoveredBy 表达。

这会让依赖 MBRWithin 排除边界对象的空间过滤返回额外行。

Environment

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

Steps to reproduce

SELECT
  MBRWithin(
    ST_GeomFromText('POINT(0 0)'),
    ST_GeomFromText('POLYGON((0 0,4 0,4 4,0 4,0 0))')
  ) AS on_boundary_within,
  MBRCoveredBy(
    ST_GeomFromText('POINT(0 0)'),
    ST_GeomFromText('POLYGON((0 0,4 0,4 4,0 4,0 0))')
  ) AS on_boundary_covered_by;

SELECT
  MBRWithin(
    ST_GeomFromText('POINT(2 2)'),
    ST_GeomFromText('POLYGON((0 0,4 0,4 4,0 4,0 0))')
  ) AS interior_within;

Actual behavior

on_boundary_within = 1
on_boundary_covered_by = 1
interior_within = 1

Expected behavior

on_boundary_within = 0
on_boundary_covered_by = 1
interior_within = 1

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

Stability and controls

  • 边界点、内部点场景各重复 3 次,结果稳定。
  • 常量表达式、表列扫描以及创建 R-tree 空间索引后的查询均得到相同错误结果。
  • MBRCoveredBy 对边界点返回 1,符合其包含边界的语义;问题集中在 MBRWithin 的严格性。
  • 576 组 Point/LineString/Polygon MBR 配对、共 5,184 个谓词差分中,此差异可稳定归类到退化 MBR 的边界包含场景。

Evidence and code analysis

  • Exact main commit: e7bb057
  • bboxContains uses inclusive comparisons:
    func bboxContains(a, b geo.BBox) bool {
    return a.MinX <= b.MinX && a.MinY <= b.MinY && a.MaxX >= b.MaxX && a.MaxY >= b.MaxY
    }
  • MBRWithin and MBRCoveredBy are aliases of the same predicate:
    func MBRWithin(ivecs []*vector.Vector, result vector.FunctionResultWrapper, proc *process.Process, length int, selectList *FunctionSelectList) error {
    return mbrBinary("MBRWithin", func(a, b geo.BBox) bool { return bboxContains(b, a) })(ivecs, result, proc, length, selectList)
    }
    func MBRCoveredBy(ivecs []*vector.Vector, result vector.FunctionResultWrapper, proc *process.Process, length int, selectList *FunctionSelectList) error {
    return mbrBinary("MBRCoveredBy", func(a, b geo.BBox) bool { return bboxContains(b, a) })(ivecs, result, proc, length, selectList)
    }

MBRWithin 与 MBRCoveredBy 没有独立实现,两者都反向调用含 <=/>= 的 bboxContains,因此无法区分内部包含与边界覆盖。

Regression coverage

修复时应覆盖 Point/LineString/Polygon 的 MBR 位于内部、边界、角点、完全相等、部分重叠和不相交场景,并同时断言 Within/CoveredBy 与 Contains/Covers 的对偶关系;覆盖常量、表列和空间索引路径。

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.

    MBRWithin/MBRContains now require closed-box coverage plus intersecting relative interiors, so an interior point is within while a boundary-only point is not. MBRCoveredBy/MBRCovers retain inclusive boundary coverage. This also repairs the shared boundary distinction implicated by #28190.

    The change adds evaluator tests across 0D/1D/2D MBRs and public SQL constant/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. Ariznawlll commented on Sep 14, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    原问题验证

    • MBRWithin 与 MBRCoveredBy 已区分严格内部和边界覆盖。

    Happy Path 覆盖

    • 内部点 MBRWithin=1,边界点 MBRCoveredBy=1。

    Unhappy Path 覆盖

    • 边界点 MBRWithin=0,避免把 covered-by 当作 within。

    白盒验证

    回归测试

    测试证据

    • 独立环境三轮输出字节一致;服务日志未见 panic/hang,测试后已清理服务。

    测试结论

    测试通过。

  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