matrixorigin / matrixorigin/matrixone

[Compatibility]: INET_NTOA rejects MySQL numeric-convertible values and prepared parameters

Open
#28,892 1 comment 0 reactions 1 assignee Assigned to @XuPeng-SH View on GitHub
area/compatibility kind/bug needs-triage
Dominant language
Go
Stars
1.9k
Forks
311
Avg merge
1d 3h
Merged PRs (30d)
768

Description

## Description

`INET_NTOA` only exposes native integer, floating-point, and decimal overloads in MatrixOne. Values that MySQL converts through its numeric context—such as fractional numeric strings, Boolean, DATE/TIME, JSON numbers, and untyped prepared parameters—are either rejected during binding or fail with a cast error at execution. A single such row aborts the query instead of producing the per-row IPv4 string or NULL that MySQL returns.

## Environment

- MatrixOne branch: `main`
- MatrixOne commit: `0c3a04f390adaf6281fd592a49778ea5b1155e67`
- MatrixOne deployment: local standalone, 1 CN / 1 TN / 1 LogService
- Reference: local MySQL `8.0.45`

## Steps to reproduce

```sql
SELECT INET_NTOA('1.0'), INET_NTOA('1.6'),
INET_NTOA('4294967295.9');

SELECT INET_NTOA(TRUE), INET_NTOA(FALSE);
SELECT INET_NTOA(CAST('2024-01-02' AS DATE)),
INET_NTOA(CAST('00:00:02' AS TIME));
SELECT INET_NTOA(JSON_EXTRACT(CAST('1.6' AS JSON), '$'));

PREPARE p FROM 'SELECT INET_NTOA(?)';
SET @x = 1.6;
EXECUTE p USING @x;
DEALLOCATE PREPARE p;
```

## MatrixOne result

Representative errors are:

```text
ERROR 20203 (HY000): invalid argument cast to int, bad value 1.0
ERROR 20203 (HY000): invalid argument function inet_ntoa, bad value [BOOL]
ERROR 20203 (HY000): invalid argument function inet_ntoa, bad value [DATE]
ERROR 20203 (HY000): invalid argument function inet_ntoa, bad value [JSON]
ERROR 20203 (HY000): invalid argument cast to uint64, bad value 1.6
```

The final error is from the uncast prepared parameter. `INET_NTOA(CAST(? AS DOUBLE))` and `INET_NTOA(CAST(? AS DECIMAL(20,6)))` are usable workarounds.

## MySQL 8.0.45 result

```text
INET_NTOA('1.0') 0.0.0.1
INET_NTOA('1.6') 0.0.0.1
INET_NTOA('4294967295.9') 255.255.255.255
INET_NTOA(TRUE/FALSE) 0.0.0.1 / 0.0.0.0
INET_NTOA(DATE '2024-01-02') 1.52.214.230
INET_NTOA(TIME '00:00:02') 0.0.0.2
INET_NTOA(JSON number 1.6) 0.0.0.2
prepared @x = 1.6 0.0.0.2
```

## Scope and controls

- Literal, VARCHAR-column, prepared, CTAS, and view execution paths were covered; the results reproduce identically in 3/3 runs.
- A VARCHAR table containing `0.4`, `0.5`, `0.6`, positive/negative fractions, and values around `4294967295` is processed row-by-row by MySQL but aborts at the first fractional string in MatrixOne.
- Native DOUBLE, FLOAT, and DECIMAL columns match MySQL, including negative and upper-bound rounding behavior.
- BIT, ENUM, and SET values also match MySQL through existing casts.
- MySQL's constant `CAST(... AS DOUBLE)` path differs from its DOUBLE-column path at exact half values; that MySQL-internal ambiguity is not used as the basis of this report.
- Negative and out-of-range native integer handling fixed for #28215 remains correct.

## Code analysis

The `INET_NTOA` registration in `pkg/sql/plan/function/list_builtIn.go` contains only integer, FLOAT/DOUBLE, and DECIMAL overloads and uses generic fixed-type matching. VARCHAR is selected through an integer cast, which rejects fractional text instead of applying MySQL's function numeric conversion. BOOL, temporal, and JSON inputs have no admitted conversion. An untyped `?` is bound to UINT64, so a later fractional runtime value fails before reaching the real/decimal executor.

## Expected behavior

`INET_NTOA` should accept the same numeric-convertible expression families as MySQL and apply the source type's established numeric conversion before range validation. Prepared parameters should preserve or resolve their runtime numeric domain rather than being fixed to UINT64. The behavior must remain consistent for literals, columns, prepared execution, CTAS, and views.

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.