Skip to content

[Bug]: FLOOR parses NULL VARCHAR rows as empty strings #28486

Closed

Description

@Ariznawlll

Is there an existing issue for the same bug?

  • I have checked open and closed issues.

No existing issue was found for FLOOR evaluating a NULL character value as an empty string.

Branch Name

main

Commit ID

f0c31cd4b830be32442cf329e0a3fb08aa9c16c3

Other Environment Information

  • Local standalone MatrixOne built from the commit above
  • Reference: MySQL 8.3.0

Actual Behavior

FLOOR() does not preserve NULL when its resolved input type is VARCHAR. It appends a NULL result, then continues and attempts to parse the NULL row's empty payload as a floating-point number:

SELECT FLOOR(CAST(NULL AS CHAR));
-- MatrixOne: strconv.ParseFloat: parsing "": invalid syntax
-- MySQL: NULL

The same error aborts a query when a VARCHAR column contains a NULL row:

CREATE TABLE src(id INT PRIMARY KEY, s VARCHAR(20));
INSERT INTO src VALUES (1,'1.9'),(2,NULL),(3,'-1.1');
SELECT id,FLOOR(s) FROM src ORDER BY id;
-- MatrixOne: strconv.ParseFloat: parsing "": invalid syntax
-- MySQL: (1,1), (2,NULL), (3,-2)

As a consequence, CTAS over the expression also aborts and does not create its target table. Filtering NULL rows before evaluation or guarding them with CASE avoids the error. An untyped FLOOR(NULL) and a prepared NULL parameter both return NULL, so the defect is specific to the VARCHAR execution overload.

Each constant, single-row column, mixed-vector, guarded, prepared, and CTAS form was executed three times with the same result. The source table and connection remain healthy after every error.

Expected Behavior

FLOOR() must propagate NULL for character expressions just as it does for numeric expressions. A NULL row must not be passed to strconv.ParseFloat, and valid rows in the same vector must remain queryable.

Steps to Reproduce

DROP DATABASE IF EXISTS codex_floor_varchar_null;
CREATE DATABASE codex_floor_varchar_null;
USE codex_floor_varchar_null;

SELECT FLOOR(NULL);                 -- NULL control
SELECT FLOOR(CAST(NULL AS CHAR));   -- error

CREATE TABLE src(id INT PRIMARY KEY, s VARCHAR(20));
INSERT INTO src VALUES (1,'1.9'),(2,NULL),(3,'-1.1');

SELECT id,FLOOR(s) FROM src WHERE id=1;        -- (1,1)
SELECT id,FLOOR(s) FROM src WHERE id=2;        -- error
SELECT id,FLOOR(s) FROM src ORDER BY id;       -- error
SELECT id,FLOOR(s) FROM src WHERE s IS NOT NULL ORDER BY id; -- works

CREATE TABLE copied AS SELECT id,FLOOR(s) AS v FROM src; -- error

Root Cause

FloorStr in pkg/sql/plan/function/func_binary.go builds the result NULL bitmap correctly. In the WithAnyNullValue loop, however, the rsNull.Contains(i) branch appends a NULL but does not continue. Execution then calls GetStrValue(i) and strconv.ParseFloat for the same NULL row, whose payload is an empty byte slice. The comparable generic unary helpers skip NULL rows before invoking their scalar callbacks.

Activity

  1. added this to the MO-202609 milestone on Sep 9, 2026
  2. added theissue type on Sep 9, 2026
  3. added a commit that references this issue on Sep 9, 2026
    d3794ea
  4. Lundomn commented on Sep 9, 2026

    @Lundomn
    Contributor

    转测 QA(对应已合并 PR #28510):

    • PR:fix: preserve NULL VARCHAR values in FLOOR #28510
    • 修复范围:修复 FLOOR/FloorStr 处理 NULL VARCHAR 行时继续解析空字符串的问题,改用现有 unary string-to-fixed 模板,确保输入 NULL 与 CASE 选择掩码正确传播;非 NULL 解析及原有错误行为保持不变。
    • 根因/影响:NULL 行被追加 NULL 结果后仍继续解析空 VARCHAR payload,导致行语义错误;影响字符串到定点数转换的 FLOOR 路径及相关向量/掩码场景。
    • QA 请覆盖:typed NULL、混合向量中首/中/尾 NULL、全 NULL 向量、CASE 掩码、非法非 NULL 字符串错误行为、常量 decimal places、SQL PREPARE、CTAS,以及结果行数和行对应关系。
    • 已有验证:mo-cgo-test 定向用例及所属包覆盖率通过,FloorStr 覆盖率 100%;go vet(pkg/sql/plan/function)通过;原生 mo-tester BVT func_math_string_numeric 连续 2 次 16/16 通过;git diff --check 通过。
    • 建议环境:最新 main,至少验证单 CN/TN/LogService 的 MySQL 协议路径;如条件允许补充多 CN/Proxy 路径,确认 NULL 行传播和 PREPARE/CTAS 行为一致。
    • 预期:原始 NULL VARCHAR 输入保持 NULL,不产生空字符串解析错误;混合/CASE 向量保持行数、顺序和掩码对应;非法非 NULL 输入仍返回原错误。

    请 QA 完成上述验收后反馈通过/失败及覆盖范围;通过后由 QA 关闭 Issue #28486,失败或需补测时保持 open。

  5. removed their assignment
    on Sep 9, 2026
  6. slyunnn commented on Sep 10, 2026

    @slyunnn

    Regression and extended verification for #28486 (2026-09-10)

    Verification Environment

    • MatrixOne source: local origin/main at 2a6fe7f61358e846a20aafba3b50903a61608682 — test(hakeeper): cover empty target removal through checker (#28481).
    • The running mo-service binary was rebuilt from that commit and restarted before verification; mo-service -version reported 2a6fe7f613.
    • Topology: 2 CN / 1 TN / 1 Log service / Proxy.
    • Tested endpoints: Proxy 127.0.0.1:6001, CN1 127.0.0.1:16001, and CN2 127.0.0.1:16002; each accepted a fresh MySQL connection and SELECT 1.
    • Client protocol: MySQL wire protocol through the mysql client and MOTR. SQL prepared coverage uses PREPARE / EXECUTE.
    • Related fix: d3794ea96498e4ff1847ebbca6857a230ddfcd39, merged by #28510, fix(function): preserve NULL VARCHAR values in FLOOR.

    What Was Covered

    • OK — Original FLOOR(CAST(NULL AS CHAR)) returned NULL, alongside the FLOOR(NULL) control, through Proxy 6001, CN1 16001, and CN2 16002.
    • OK — Mixed VARCHAR vectors with NULL in the first, middle, and last positions preserved values, order, row count, and NULL correspondence.
    • OK — All-NULL input and CASE selection-mask paths returned NULL only for selected NULL rows.
    • OK — SQL PREPARE / EXECUTE with a typed NULL parameter returned NULL.
    • OK — CTAS retained all five rows and their expected NULL, 1, and -2 results.
    • OK — The numeric two-argument control FLOOR(123.342, 1) returned 123.3.
    • OK — Malformed non-NULL character inputs retained the expected ERROR 1105 / strconv.ParseFloat failure.
    • OK — Exact-head CGo unit tests TestFloorStrSkipsNullAndMaskedRows and TestFloorStrDecimalPlacesMustBeConstant passed.
    • OK — MOTR recording and replay passed at 19/19 statements through Proxy 6001, CN1 16001, and CN2 16002.
    • Not covered — A public SQL success case for FLOOR(CAST('1.29' AS CHAR), 1): the current SQL resolver rejects that VARCHAR two-argument form with ERROR 20203; the constant-decimal-place behavior of the internal FloorStr overload is directly covered by the exact-head unit test above.

    Findings

    FLOOR now propagates NULL VARCHAR rows before parsing, so they no longer reach strconv.ParseFloat as empty payloads. Non-NULL malformed strings still return their original parse error.

    MOTR / BVT Coverage

    • Existing product BVT: test/distributed/cases/function/func_math_floor_varchar_null.test.
    • Independent MOTR branch: test/issue-28486-floor-null-varchar.
    • Source commit: 416f403ea54417fea080078dadcb53879139698b, test: add MOTR regression for #28486.
    • Case: suites/14_issue_regression/t/issue_28486_floor_null_varchar.test and its recorded result file.
    • Daily aggregation: matrixorigin/motr#155, cherry-pick commit 1c6db07123661c26a51ffa5d9a3c850bc4cc3e8b.
    • The direct SQL scenarios ran in parallel across the three endpoints using endpoint-specific databases. MOTR replay was serial because the fixed test database belongs to one shared cluster; setup and teardown prevent DDL races.
    • No large-data regression is needed: this defect is deterministic per-row NULL propagation and does not depend on row count, block/batch boundaries, memory/spill, concurrency, skew, network transfer, or resource scale.

    Final Conclusion

    Fixed. The original reproduction and required extended coverage passed on the rebuilt latest origin/main runtime through the complete 2 CN / 1 TN / 1 Log service / Proxy topology. No additional large-data regression is required.

  7. added 3 commits that reference this issue on Sep 17, 2026
    db64270
    4b674af
    e0a8032
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions