Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

ST_MakeEnvelope breaks MariaDB and fails on MySQL with SRID 4326 spatial columns

未关闭 适合新手
#247 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
74/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
冷清
技术栈
mariadb, mysql, php
领域
api, backend, databases

调研方向

检查 server/src/Http/Controllers/Internal/v1/LiveController.php 以及 drivers()、vehicles() 和 places() 中的 whereRaw 调用。使用 SRID-4326 空间数据,针对 MySQL 和 MariaDB 运行受影响的 live endpoint 查询;当 bounds 过滤器在两个数据库引擎上都能正常工作且不出现 GIS 错误时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

Summary

LiveController builds the map-viewport spatial filter for the /v1/internal/live/{drivers,vehicles,places} endpoints using MySQL's ST_MakeEnvelope. This breaks the application in two ways:

  1. MariaDB does not implement ST_MakeEnvelope. It is a MySQL-only convenience function (5.7.6+). Calling these endpoints on any MariaDB-backed deployment returns a 500. MariaDB is otherwise a first-class target — recent migrations gate driver-specific branches on in_array(DB::getDriverName(), ['mysql', 'mariadb']) (e.g. 2025_08_28_045009_noramlize_uuid_foreign_key_columns.php, 2025_08_28_054925_create_devices_table.php), and the bundled spatial library (fleetbase/laravel-mysql-spatial) advertises MariaDB support — so this is the one outlier blocking MariaDB.

  2. On MySQL, ST_MakeEnvelope only accepts SRID 0 geometries. Fleetbase's Point, Polygon, and MultiPolygon casts (server/src/Casts/) feed geometries through Utils::createSpatialExpressionFromGeoJson → \Fleetbase\LaravelMysqlSpatial\Types\Geometry::fromJson(...), which emits SRID 4326. Recent migrations such as 2025_10_27_171322_fix_device_column_names.php explicitly normalize positions to ST_SRID(POINT(0, 0), 4326). Mixing a SRID-0 envelope with SRID-4326 column data on MySQL 8 raises ER_GIS_DIFFERENT_SRIDS (3618) or ER_NOT_IMPLEMENTED_FOR_GEOGRAPHIC_SRS (3680) the moment the bounds filter actually meets a populated row, so this is a latent correctness bug on plain MySQL too.

Affected code

server/src/Http/Controllers/Internal/v1/LiveController.php, three identical call sites:

  • drivers() — line 160
  • vehicles() — line 202
  • places() — line 245

Each is:

$query->whereRaw(
    'ST_Within(location, ST_MakeEnvelope(POINT(?, ?), POINT(?, ?)))',
    [$west, $south, $east, $north]
);

User-facing impact

  • Calling GET /v1/internal/live/drivers?bounds[]=…&bounds[]=…&bounds[]=…&bounds[]=… (or the vehicles / places equivalents) returns 500 on any MariaDB deployment, and on MySQL once the spatial column has any SRID-4326 data — which it always does, because the casts and recent migrations write SRID 4326.
  • This is the live map viewport filter used by the console map, so it is the primary spatial query a fresh install will hit.

Repro (documentation references)

  • MariaDB miscellaneous GIS functions reference omits ST_MakeEnvelope: https://mariadb.com/docs/server/reference/sql-statements/geometry-constructors/miscellaneous-gis-functions.
  • MySQL ST_MakeEnvelope documentation states it is defined for SRID 0 only and raises ER_NOT_IMPLEMENTED_FOR_GEOGRAPHIC_SRS / ER_GIS_DIFFERENT_SRIDS on non-zero-SRID inputs.
  • Fleetbase storage SRID is 4326: see Fleetbase\LaravelMysqlSpatial\Types\Geometry::fromJson (used by Utils::createSpatialExpressionFromGeoJson) and the explicit ST_SRID(POINT(0, 0), 4326) in 2025_10_27_171322_fix_device_column_names.php.

Proposed fix

Replace ST_MakeEnvelope(POINT(?, ?), POINT(?, ?)) with an equivalent WKT polygon passed through ST_GeomFromText(?, 4326). This preserves the ST_Within(location, …) form (so a future SPATIAL INDEX on location remains usable), pins the envelope SRID to 4326 to match the column, and runs unchanged on MySQL 8 / 8.4 and MariaDB 10.5+ / 11.x.

PR following this issue.

Environment

  • Repro confirmed by reading current main (commit 9394d4f); call sites unchanged from the lines cited above.
  • Reproduces on any MariaDB version; on MySQL 8.0 / 8.4 with the default cast pipeline writing SRID 4326.
主要语言
PHP
星标
36
派生
69
平均合并
1 天 6 小时
30 天内合并 PR
32

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

fleetbase/fleetops 的其他 Issue

查看 fleetbase/fleetops 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。