Skip to content

[Bug]: Reading an undefined user variable @x errors instead of returning NULL; SELECT … INTO @var rejected #25123

Closed

Description

@dengn

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

v4.0.0-rc3

Commit ID

8.0.30-MatrixOne-v4.0.0-rc3

Other Environment Information

  • Hardware parameters: N/A
  • OS type: N/A
  • Others: Found by the JDBC 4.2 API conformance probe (driver-level java.sql.* surface, JDBC_COMPAT.md), reduced to a driver-independent SQL repro. MySQL 8.0.30 wire protocol.

Actual Behavior

Two related user-defined-variable gaps. Basic assignment/readback works (SET @x = 5; SELECT @x; → 5), but:

SELECT @never_set;          -- MatrixOne: 20101 internal error: the user variable never_set does not exist
SELECT abs(-5) INTO @o;     -- MatrixOne: 1064 SQL parser error near "@o"

Expected Behavior

In MySQL, referencing a user variable that has never been assigned yields NULL (not an error), and SELECT expr INTO @var is standard syntax:

SELECT @never_set;          -- MySQL: NULL
SELECT abs(-5) INTO @o;     -- MySQL: OK (sets @o = 5)

Steps to Reproduce

SET @x = 5; SELECT @x;      -- works: 5
SELECT @never_set;          -- MySQL: NULL          MatrixOne: 20101 ... the user variable never_set does not exist
SELECT abs(-5) INTO @o;     -- MySQL: OK (@o = 5)    MatrixOne: 1064 SQL parser error near "@o"

Additional information

Impact: breaks JDBC CallableStatement function out-parameters. Connector/J implements {? = call f(?)} by capturing the result into a session variable named @com_mysql_jdbc_outparam_0 and reading it back; on MatrixOne this fails with "the user variable com_mysql_jdbc_outparam_0 does not exist". More generally, any application using @var accumulators or SELECT … INTO @var (a common MySQL idiom) is affected.

Fix: return NULL when reading an unassigned user variable (MySQL semantics), and support SELECT … INTO @var.

Related: the SELECT … INTO @var syntax gap overlaps with #24500 (§2 "SELECT INTO Variable"). The undefined-variable-returns-NULL behavior and the JDBC OUT-parameter impact above are not yet tracked separately.

Background: dengn/php-tester JDBC 4.2 API conformance probe (JDBC_COMPAT.md).

Activity

  1. added
    kind/bug
    on Jun 24, 2026
  2. added
    severity/s1
    on Jun 30, 2026
  3. added this to the MO-202607 milestone on Jun 30, 2026
  4. added
    ai-light
    on Jul 1, 2026
  5. Ariznawlll commented on Jul 3, 2026

    @Ariznawlll
    Collaborator

    Supplemented a stored-procedure variant on latest main (git_version() = 51656deb6).

    The original issue tracks SELECT expr INTO @var being rejected. The same parser gap appears inside a stored procedure when assigning to an OUT parameter:

    drop database if exists mysql_compat_model15_out_min;
    create database mysql_compat_model15_out_min;
    use mysql_compat_model15_out_min;
    
    create table t_routine (id int primary key, v varchar(20));
    insert into t_routine values (1,'a'),(2,'b'),(3,'c');
    
    create procedure p_out_select_into(out p_cnt int)
    'begin select count(*) into p_cnt from t_routine; end';
    call p_out_select_into(@cnt3);
    select @cnt3 as cnt3;

    MySQL equivalent returns:

    cnt3
    3
    

    MO:

    ERROR 1105 (HY000): syntax error ... near " p_cnt from t_routine; end";
    ERROR 20101 (HY000): internal error: the user variable cnt3 does not exist
    
  6. added
    ai-medium
    and removed
    ai-light
    on Jul 3, 2026
  7. removed
    severity/s1
    on Aug 6, 2026
  8. Ariznawlll commented on Aug 20, 2026

    @Ariznawlll
    Collaborator

    测试版本

    • 分支:main
    • commit:d7899e703dfaef428f272c2fc0452813c0b8636c
    • 部署方式:本地 1 CN / 1 TN / 1 Log,MySQL 协议
    • 测试日期:2026-08-20

    原问题验证

    在同一会话执行原始 SQL:

    SET @defined_25123 = 7;
    SELECT @defined_25123;
    SELECT @undefined_25123;
    SELECT ABS(-5) INTO @out_25123;
    SELECT @out_25123;
    SELECT 1;

    连续 3 轮结果均为:已赋值变量返回 7,未赋值变量返回 NULL,SELECT ... INTO @var 写入并返回 5,后续查询返回 1。

    Happy Path 覆盖

    1. 已赋值用户变量读回值保持正确。
    2. SELECT ABS(-5) INTO @out_25123 成功执行,变量值为 5。
    3. 同一会话在 SELECT INTO 后仍可继续执行查询。

    Unhappy Path 覆盖

    1. 读取未赋值用户变量不再返回 internal error,而是按 MySQL 兼容语义返回 NULL。
    2. 测试库在每轮结束后删除,未残留测试对象。

    白盒验证

    不适用:该 issue 的验收目标是客户端可见 SQL 语义,已用黑盒协议验证。

    回归测试

    已加入 MOTR:14_issue_regression.issue_25123_user_variables,执行 --repeat 3,3/3 通过。

    测试证据

    MOTR 输出:total=3 success=3 failed=0;每轮 stmts=10 ok=10 fail=0。

    测试结论

    测试通过。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ai-mediumkind/bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions