Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

insert's SET opration or VALUES_LIST doesn't support the subquery correctly #30626

Open
JZuming opened this issue Dec 10, 2021 · 5 comments
Open
Labels
affects-6.0 severity/moderate sig/planner SIG: Planner type/bug The issue is confirmed as a bug.

Comments

@JZuming
Copy link

JZuming commented Dec 10, 2021

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

Setup the environment:

tiup playground --db.binpath /path/to/latest/tidb-server &
mysql -h "127.0.0.1" -u root -P 4000 -D testdb < mysql_bk.sql

mysql_bk.sql:
mysql_bk.sql.txt

Test case

mysql -h "127.0.0.1" -u root -P 4000 -D testdb
mysql> start transaction;
mysql> insert into t_cvooz values
(81, case when trim('p9u_9c') <= (
    select
        'vnsgnd' as c0
      from
        (t_ljlaub as ref_3
          cross join t_ljlaub as ref_4
        )
    ) then 87 else 26 end
  , 44.67, 60, null);
mysql> commit;

2. What did you expect to see? (Required)

The connection will not be lost.

3. What did you see instead (Required)

The test case made the connection lost.

ERROR 1105 (HY000): runtime error: index out of range [0] with length 0
ERROR 2013 (HY000): Lost connection to MySQL server during query
No connection. Trying to reconnect...
Connection id:    377
Current database: testdb

4. What is your TiDB version? (Required)

Release Version: v5.4.0-alpha-360-gb6c45af75
Edition: Community
Git Commit Hash: b6c45af75abf25e62f515c5cadaa329dfd675304
Git Branch: master
UTC Build Time: 2021-12-09 08:29:55
GoVersion: go1.16
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
@JZuming JZuming added the type/bug The issue is confirmed as a bug. label Dec 10, 2021
@JZuming
Copy link
Author

JZuming commented Dec 10, 2021

The log of the server:

[2021/12/10 10:21:31.177 +00:00] [ERROR] [conn.go:1019] ["connection running loop panic"] [conn=377] [lastSQL="insert into t_cvooz values \n(81, case when trim('p9u_9c') <= ( \n select \n 'vnsgnd' as c0\n from \n (t_ljlaub as ref_3\n cross join t_ljlaub as ref_4\n )\n ) then 87 else 26 end\n , 44.67, 60, null)"] [err="runtime error: index out of range [0] with length 0"] [stack="goroutine 140333 [running]:\ngithub.com/pingcap/tidb/server.(*clientConn).Run.func1(0x41d7210, 0xc000e6d740, 0xc00239edc0)\n\t/home/zuming/tidb/server/conn.go:1017 +0xf5\npanic(0x3a611e0, 0xc00349a258)\n\t/usr/local/go/src/runtime/panic.go:965 +0x1b9\ngithub.com/pingcap/tidb/executor.(*ExecStmt).Exec.func1(0xc000e5ea90, 0xc0020f8a08, 0xc0020f89e8)\n\t/home/zuming/tidb/executor/adapter.go:343 +0x4d4\npanic(0x3a611e0, 0xc00349a258)\n\t/usr/local/go/src/runtime/panic.go:965 +0x1b9\ngithub.com/pingcap/tidb/util/chunk.(*Column).GetString(...)\n\t/home/zuming/tidb/util/chunk/column.go:565\ngithub.com/pingcap/tidb/util/chunk.Row.GetString(...)\n\t/home/zuming/tidb/util/chunk/row.go:73\ngithub.com/pingcap/tidb/expression.(*Column).EvalString(0xc001b40dc0, 0x4221678, 0xc000172c00, 0xc001a466e0, 0x0, 0xc00277a211, 0x6, 0x0, 0x0, 0x0)\n\t/home/zuming/tidb/expression/column.go:421 +0x2b5\ngithub.com/pingcap/tidb/expression.CompareStringWithCollationInfo(0x4221678, 0xc000172c00, 0x424d288, 0xc001972600, 0x424d130, 0xc001b40dc0, 0xc001a466e0, 0x0, 0xc001a466e0, 0x0, ...)\n\t/home/zuming/tidb/expression/builtin_compare.go:2799 +0xea\ngithub.com/pingcap/tidb/expression.(*builtinLEStringSig).evalInt(0xc0014adb80, 0xc001a466e0, 0x0, 0x0, 0x0, 0x0, 0x8)\n\t/home/zuming/tidb/expression/builtin_compare.go:1983 +0xd0\ngithub.com/pingcap/tidb/expression.(*ScalarFunction).EvalInt(0xc001a46640, 0x4221678, 0xc000172c00, 0xc001a466e0, 0x0, 0x0, 0xc0020f7ee8, 0x11f31ea, 0x3856d60)\n\t/home/zuming/tidb/expression/scalar_function.go:397 +0xf6\ngithub.com/pingcap/tidb/expression.(*builtinCaseWhenIntSig).evalInt(0xc0014adc30, 0xc001a466e0, 0x0, 0x0, 0x0, 0x0, 0x8)\n\t/home/zuming/tidb/expression/builtin_control.go:293 +0xae\ngithub.com/pingcap/tidb/expression.(*ScalarFunction).EvalInt(0xc001a46690, 0x4221678, 0xc000172c00, 0xc001a466e0, 0x0, 0x0, 0x0, 0x0, 0x0)\n\t/home/zuming/tidb/expression/scalar_function.go:397 +0xf6\ngithub.com/pingcap/tidb/expression.(*ScalarFunction).Eval(0xc001a46690, 0xc001a466e0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)\n\t/home/zuming/tidb/expression/scalar_function.go:350 +0x2a6\ngithub.com/pingcap/tidb/executor.(*InsertValues).evalRow(0xc000922680, 0x41d7210, 0xc0029b0000, 0xc00085ceb0, 0x5, 0x5, 0x0, 0x12387ec, 0x18, 0x36fe260, ...)\n\t/home/zuming/tidb/executor/insert_common.go:350 +0x1c2\ngithub.com/pingcap/tidb/executor.insertRows(0x41d7210, 0xc0029b0000, 0x41afc88, 0xc001ee7560, 0x39d9a40, 0xc00186d4e0)\n\t/home/zuming/tidb/executor/insert_common.go:245 +0x223\ngithub.com/pingcap/tidb/executor.(*InsertExec).Next(0xc001ee7560, 0x41d7210, 0xc001c07e30, 0xc001a46820, 0x0, 0xc0020f84e0)\n\t/home/zuming/tidb/executor/insert.go:313 +0x92\ngithub.com/pingcap/tidb/executor.Next(0x41d7210, 0xc001c07e30, 0x41dc4e0, 0xc001ee7560, 0xc001a46820, 0x0, 0x0)\n\t/home/zuming/tidb/executor/executor.go:286 +0x2de\ngithub.com/pingcap/tidb/executor.(*ExecStmt).handleNoDelayExecutor(0xc000e5ea90, 0x41d7210, 0xc001c07e30, 0x41dc4e0, 0xc001ee7560, 0x0, 0x0, 0x0, 0x0)\n\t/home/zuming/tidb/executor/adapter.go:594 +0x33c\ngithub.com/pingcap/tidb/executor.(*ExecStmt).handlePessimisticDML(0xc000e5ea90, 0x41d7210, 0xc001c07e30, 0x41dc4e0, 0xc001ee7560, 0xc064e86aca95b6f8, 0x16f72d6e45e)\n\t/home/zuming/tidb/executor/adapter.go:613 +0x188\ngithub.com/pingcap/tidb/executor.(*ExecStmt).handleNoDelay(0xc000e5ea90, 0x41d7210, 0xc001c07e30, 0x41dc4e0, 0xc001ee7560, 0x5e27301, 0x41d7201, 0x0, 0x0, 0x0, ...)\n\t/home/zuming/tidb/executor/adapter.go:468 +0x155\ngithub.com/pingcap/tidb/executor.(*ExecStmt).Exec(0xc000e5ea90, 0x41d7210, 0xc001c07e30, 0x0, 0x0, 0x0, 0x0)\n\t/home/zuming/tidb/executor/adapter.go:419 +0x707\ngithub.com/pingcap/tidb/session.runStmt(0x41d7210, 0xc002c959b0, 0xc000172c00, 0x41ede20, 0xc000e5ea90, 0x0, 0x0, 0x0, 0x0)\n\t/home/zuming/tidb/session/session.go:1696 +0x37f\ngithub.com/pingcap/tidb/session.(*session).ExecuteStmt(0xc000172c00, 0x41d7210, 0xc002c959b0, 0x41f5688, 0xc001257040, 0x0, 0x0, 0x0, 0x0)\n\t/home/zuming/tidb/session/session.go:1580 +0xab1\ngithub.com/pingcap/tidb/server.(*TiDBContext).ExecuteStmt(0xc0025a8840, 0x41d7210, 0xc002c959b0, 0x41f5688, 0xc001257040, 0xc001764300, 0x41d"]

@zhouqiang-cl
Copy link
Contributor

@wshwsh12 PTAL

@wshwsh12
Copy link
Contributor

Minimal reproduction step:

create table t(a int, b int);
insert into
    t
values
    (
        81,
        (
            select
                (
                    SELECT
                        '1' AS `c0`
                    WHERE
                        '1' >= `subq_0`.`c0`
                ) as `c1`
            FROM
                (
                    SELECT
                        '1' AS `c0`
                ) AS `subq_0`
        )
    );
ERROR 1105 (HY000): runtime error: index out of range [0] with length 0

@winoros winoros changed the title The connection was lost because of "index out of range" insert's SET opration or VALUES_LIST doesn't support the subquery correctly Dec 23, 2021
@winoros
Copy link
Member

winoros commented Dec 23, 2021

This is something also related with #11414. That one would make this issue easy to have a final correct solution.

@winoros
Copy link
Member

winoros commented Mar 21, 2022

Since we've thrown error to make sure that it would not panic.
We downgrade the severity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-6.0 severity/moderate sig/planner SIG: Planner type/bug The issue is confirmed as a bug.
Projects
None yet
Development

No branches or pull requests

6 participants