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

index out of range [0] with length 0 when using prepare plan cache #19192

Closed
ChenPeng2013 opened this issue Aug 13, 2020 · 7 comments · Fixed by #19296
Closed

index out of range [0] with length 0 when using prepare plan cache #19192

ChenPeng2013 opened this issue Aug 13, 2020 · 7 comments · Fixed by #19296
Assignees
Labels
challenge-program priority/P2 The issue has P2 priority. severity/critical sig/execution SIG execution sig/planner SIG: Planner type/bug The issue is confirmed as a bug.

Comments

@ChenPeng2013
Copy link
Contributor

ChenPeng2013 commented Aug 13, 2020

Description

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

new_collations_enabled_on_first_bootstrap = true
prepared-plan-cache.enabled = true

CREATE TABLE `t` (
  `c_int` int(11) DEFAULT NULL,
  `c_int2` int(11) GENERATED ALWAYS AS (`c_int` * 2) STORED,
  `c_str` varchar(40) DEFAULT NULL,
  `c_str2` varchar(40) DEFAULT NULL,
  `c_datetime` datetime DEFAULT NULL,
  `c_datetime2` datetime DEFAULT NULL,
  `c_timestamp` timestamp NULL DEFAULT NULL,
  `c_timestamp2` timestamp NULL DEFAULT NULL,
  `c_double` double DEFAULT NULL,
  `c_double2` double DEFAULT NULL,
  `c_decimal` decimal(12,6) DEFAULT NULL,
  KEY `c_int` (`c_int`),
  KEY `c_int2` (`c_int2`),
  KEY `c_str` (`c_str`),
  KEY `c_int_2` (`c_int`,`c_str`),
  KEY `c_decimal` (`c_decimal`),
  KEY `c_datetime` (`c_datetime`),
  UNIQUE KEY `c_datetime2` (`c_datetime2`,`c_datetime`),
  KEY `c_timestamp2` (`c_timestamp2`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
INSERT INTO `t` (`c_int`, `c_str`, `c_str2`, `c_datetime`, `c_datetime2`, `c_timestamp`, `c_timestamp2`, `c_double`, `c_double2`, `c_decimal`) VALUES (1,'quizzical goldberg','awesome nightingale','2020-05-20 14:06:50','2020-05-21 10:26:58','2020-03-07 13:34:24','2020-01-06 06:32:22',8.120238,93.081973,4.188000),(2,'vibrant moore','mystifying banach','2020-05-05 21:19:18','2020-05-18 19:34:10','2020-02-03 16:00:02','2020-03-24 03:24:59',45.353692,72.942041,8.493000),(5,'vibrant moore','gracious wescoff','2020-03-13 19:59:31','2020-01-13 02:48:57','2020-03-02 16:22:44','2020-04-14 08:43:53',8.698416,88.150439,4.766000),(6,'wizardly wescoff','confident newton','2020-02-06 02:33:38','2020-06-30 01:36:27','2020-06-22 21:57:44','2020-05-19 13:34:38',38.000458,34.614586,7.708000),(7,'hopeful payne','loving antonelli','2020-06-03 18:39:10','2020-01-31 01:28:59','2020-03-17 15:11:55','2020-01-27 16:15:44',76.601025,15.157077,2.327000),(8,'frosty northcutt','crazy engelbart','2020-05-01 18:34:39','2020-02-08 13:09:30','2020-04-17 23:35:29','2020-01-11 13:35:34',61.350777,96.035396,8.166000),(9,'vibrant moore','nostalgic ramanujan','2020-05-29 15:19:55','2020-01-14 07:18:53','2020-04-09 00:17:01','2020-01-19 06:17:37',40.455101,45.393835,7.050000),(10,'funny blackwell','fervent black','2020-06-09 05:57:02','2020-01-30 12:16:00','2020-02-19 20:20:20','2020-03-05 18:40:09',72.813538,96.54546,2.089000),(11,'objective antonelli','inspiring lewin','2020-04-29 08:40:33','2020-01-05 10:44:12','2020-06-06 03:09:58','2020-01-01 05:29:53',34.2709,36.396483,4.910000),(12,'romantic wilbur','intelligent allen','2020-03-17 07:21:10','2020-03-29 08:41:31','2020-03-09 14:41:51','2020-04-20 09:17:40',89.270577,39.561856,5.409000),(13,'stoic galois','flamboyant ritchie','2020-06-13 22:09:30','2020-06-08 19:20:04','2020-06-03 10:14:49','2020-01-09 03:07:06',31.450598,30.61192,1.217000),(15,'reverent yalow','boring ishizaka','2020-01-21 02:05:25','2020-05-07 00:34:24','2020-04-20 21:25:50','2020-05-11 14:47:16',86.941937,37.081463,8.641000);
begin;
update t set c_str = 'goofy ganguly' where c_int = 6 and c_str = 'elated goldberg';
update t set c_str = 'practical blackwell' where c_int = 14 and c_int2 in (27, 3, 16);
update t set c_str = 'romantic turing' where c_int in (16, 9, 21);
update t set c_int = c_int + 10, c_str = 'angry pascal' where c_int in (29, 34);
prepare stmt from "select c_int, c_int2, c_str, c_str2, c_double, c_double2, c_decimal, c_datetime, c_datetime2, c_timestamp, c_timestamp2 from t where c_str = ?";
set @a= 'exciting tesla';
execute stmt using @a;
set@a= 'pensive goldstine';
execute stmt using @a;
insert into t (c_int, c_int2, c_str, c_str2, c_datetime, c_datetime2, c_double, c_double2) values (24, 5, 'focused kepler', 'infallible kowalevski', '2020-01-06 05:29:39', '2020-01-02 12:11:57', 26.587924, 29.212838);
commit;

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

mysql> insert into t (c_int, c_int2, c_str, c_str2, c_datetime, c_datetime2, c_double, c_double2) values (24, 5, 'focused kepler', 'infallible kowalevski', '2020-01-06 05:29:39', '2020-01-02 12:11:57', 26.587924, 29.212838);
ERROR 3105 (HY000): The value specified for generated column 'c_int2' in table 't' is not allowed.
mysql> commit;
Query OK, 0 rows affected (0.00 sec)

3. What did you see instead (Required)

mysql> insert into t (c_int, c_int2, c_str, c_str2, c_datetime, c_datetime2, c_double, c_double2) values (24, 5, 'focused kepler', 'infallible kowalevski', '2020-01-06 05:29:39', '2020-01-02 12:11:57', 26.587924, 29.212838);
ERROR 1105 (HY000): runtime error: index out of range [0] with length 0
mysql> commit;
ERROR 2013 (HY000): Lost connection to MySQL server during query

4. What is your TiDB version? (Required)

Release Version: v4.0.3-62-g3948c7ba7
Edition: Community
Git Commit Hash: 3948c7ba7b5d4a081abf2162b791ab67fe650882
Git Branch: release-4.0
UTC Build Time: 2020-08-12 08:00:18
GoVersion: go1.14.6
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false

SIG slack channel

#sig-exec

Score

  • 300

Mentor

@ChenPeng2013 ChenPeng2013 added the type/bug The issue is confirmed as a bug. label Aug 13, 2020
@ChenPeng2013 ChenPeng2013 changed the title index out of range [0] with length 0 when inserting data on virtual stored column index out of range [0] with length 0 when inserting data on generated column Aug 14, 2020
@liuzix
Copy link
Contributor

liuzix commented Aug 14, 2020

/label sig/execution

@ti-srebot ti-srebot added the sig/execution SIG execution label Aug 14, 2020
@zimulala zimulala added the sig/planner SIG: Planner label Aug 17, 2020
@wjhuang2016
Copy link
Member

Minimal reproduced:

mysql> show create table t1;
+-------+-----------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                            |
+-------+-----------------------------------------------------------------------------------------------------------------------------------------+
| t1    | CREATE TABLE `t1` (
  `a` char(10) DEFAULT NULL,
  `b` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin |
+-------+-----------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> begin;
Query OK, 0 rows affected (0.00 sec)

mysql> prepare stmt from "select a, b from t1 where a=?";
Query OK, 0 rows affected (0.00 sec)

mysql> set @a="aaa";
Query OK, 0 rows affected (0.00 sec)

mysql> execute stmt using @a;
Empty set (0.00 sec)

mysql> insert into t1 values("abc", 3, 5);
ERROR 1105 (HY000): runtime error: index out of range [0] with length 0  

@wjhuang2016 wjhuang2016 changed the title index out of range [0] with length 0 when inserting data on generated column index out of range [0] with length 0 when using prepare plan cache Aug 17, 2020
@bb7133
Copy link
Member

bb7133 commented Aug 17, 2020

PTAL @SunRunAway

@SunRunAway
Copy link
Contributor

@eurekaka PTAL

@SunRunAway SunRunAway assigned eurekaka and unassigned SunRunAway and bb7133 Aug 17, 2020
@SunRunAway
Copy link
Contributor

SunRunAway commented Aug 18, 2020

Besides, tidb-server is needed to be avoided to be killed by this panic.

@sre-bot
Copy link
Contributor

sre-bot commented Oct 9, 2020

Integrity check:
RCA symptom trigger_condition affect_version fix_version fields are empty
@eurekaka
Please comment /info to get template

@ti-srebot
Copy link
Contributor

ti-srebot commented Oct 9, 2020

Please edit this comment to complete the following information

Not a bug

  1. Remove the 'type/bug' label
  2. Add notes to indicate why it is not a bug

Duplicate bug

  1. Add the 'type/duplicate' label
  2. Add the link to the original bug

Bug

Note: Make Sure that 'component', and 'severity' labels are added
Example for how to fill out the template: #20100

1. Root Cause Analysis (RCA)

If a query raises error before storing its plan into session.currentPlan, e.g, error happens in optimizer, then the session.currentPlan is not updated, i.e, it is the plan for the former query, so after returned to dispatch -> SetProcessInfo, the plan is accessed again, while the params have already gone, so panic happens.

2. Symptom

When plan cache is enabled, users may see panic for a query.

3. All Trigger Conditions

  • plan cache is enabled
  • a query may report error in the optimizer stage

4. Workaround (optional)

Disable plan cache.

5. Affected versions

unreleased

6. Fixed versions

v4.0.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
challenge-program priority/P2 The issue has P2 priority. severity/critical sig/execution SIG execution sig/planner SIG: Planner type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.