When the InnoDB record comparison functions were extended for SPATIAL INDEX in MySQL 5.7, the work was suboptimal for multiple reasons:
- The int type was being used, which does not match ulint. This triggers additional -Wconversion in some GCC versions.
- Many functions unnecessarily take an offsets parameter, or a parameter for length, although the size of the minimum bounding rectangle (MBR) is fixed as SPDIMS * 2 * sizeof(double), or 32 bytes. In SPATIAL INDEX records, there always is a 32-byte key followed by either a 4-byte child page number or the PRIMARY KEY value.
- The length parameters were not properly validated. The function cmp_geometry_field() is making an incorrect attempt at checking that the lengths are at least sizeof(double) (8 bytes), even though the function is accessing up to 32 bytes in both MBR.
- Functions that are called from only one compilation unit are defined in another compilation unit, making the code harder to follow and potentially slower to execute.