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

TiDB throw error when explain a complex sql #23839

Closed
windtalker opened this issue Apr 2, 2021 · 3 comments · Fixed by #23844
Closed

TiDB throw error when explain a complex sql #23839

windtalker opened this issue Apr 2, 2021 · 3 comments · Fixed by #23844
Assignees
Labels
severity/major sig/planner SIG: Planner type/bug The issue is confirmed as a bug.

Comments

@windtalker
Copy link
Contributor

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

mysql> show create table bb;
+-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
+-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| BB    | CREATE TABLE `BB` (
  `col_int` int(11) DEFAULT NULL,
  `col_varchar_10` varchar(10) DEFAULT NULL,
  `pk` int(11) NOT NULL AUTO_INCREMENT,
  `col_int_not_null` int(11) NOT NULL,
  `col_decimal` decimal(10,0) DEFAULT NULL,
  `col_datetime` datetime DEFAULT NULL,
  `col_decimal_not_null` decimal(10,0) NOT NULL,
  `col_datetime_not_null` datetime NOT NULL,
  `col_varchar_10_not_null` varchar(10) NOT NULL,
  PRIMARY KEY (`pk`) /*T![clustered_index] CLUSTERED */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=2000001 |
+-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> explain SELECT OUTR . col2 AS X FROM (SELECT INNR . col1 as col1, SUM( INNR . col2 ) as col2 FROM (SELECT INNR . `col_int_not_null` + 1 as col1, INNR . `pk` as col2 FROM BB AS INNR) AS INNR GROUP BY col1) AS OUTR2 INNER JOIN (SELECT INNR . col1 as col1, MAX( INNR . col2 ) as col2 FROM (SELECT INNR . `col_int_not_null` + 1 as col1, INNR . `pk` as col2 FROM BB AS INNR) AS INNR GROUP BY col1) AS OUTR ON OUTR2.col1 = OUTR.col1 GROUP BY OUTR . col1, OUTR2 . col1 HAVING X <> 'b';
ERROR 1105 (HY000): runtime error: index out of range [-1]

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

the query plan

3. What did you see instead (Required)

runtime error

4. What is your TiDB version? (Required)

mysql> select tidb_version();
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version()                                                                                                                                                                                                                                                                                                            |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v4.0.0-beta.2-2548-ge2a296144
Edition: Community
Git Commit Hash: e2a296144097273d97f31001cbfbdafde975769e
Git Branch: master
UTC Build Time: 2021-04-01 17:02:46
GoVersion: go1.13
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
@windtalker windtalker added the type/bug The issue is confirmed as a bug. label Apr 2, 2021
@xuyifangreeneyes
Copy link
Contributor

/assign

@xuyifangreeneyes
Copy link
Contributor

a simplified case:

mysql> CREATE TABLE `BB` (
    ->   `pk` int(11) NOT NULL AUTO_INCREMENT,
    ->   `col_int_not_null` int NOT NULL,
    ->   PRIMARY KEY (`pk`)
    -> );
Query OK, 0 rows affected (0.01 sec)

mysql> EXPLAIN
    -> SELECT OUTR . col2 AS X
    -> FROM
    ->   BB AS OUTR2
    -> INNER JOIN
    ->   (SELECT col_int_not_null AS col1,
    ->           pk AS col2
    ->    FROM BB) AS OUTR ON OUTR2.col_int_not_null = OUTR.col1
    -> GROUP BY OUTR2.col_int_not_null;
ERROR 1105 (HY000): runtime error: index out of range [-1]

@ti-srebot
Copy link
Contributor

Please edit this comment or add a new 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) (optional)

2. Symptom (optional)

3. All Trigger Conditions (optional)

4. Workaround (optional)

5. Affected versions

6. Fixed versions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
severity/major 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.

4 participants