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

mysql.ComStmtFetch occurs index out of range #30896

Closed
7yyo opened this issue Dec 21, 2021 · 2 comments · Fixed by #31008
Closed

mysql.ComStmtFetch occurs index out of range #30896

7yyo opened this issue Dec 21, 2021 · 2 comments · Fixed by #31008
Assignees
Labels
affects-5.4 This bug affects the 5.4.x(LTS) versions. severity/major sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.

Comments

@7yyo
Copy link
Contributor

7yyo commented Dec 21, 2021

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

   public static void main(String[] args) throws ClassNotFoundException, SQLException {

        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:4000/test?useServerPrepStmts=true&cachePrepStmts=true&useCursorFetch=true", "root", "");

        conn.setAutoCommit(false);
        PreparedStatement ps = conn.prepareStatement(sql);
        ps.setInt(1, 1);
        ps.setFetchSize(1000);
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            System.out.println(rs.getString("id"));
        }
        rs.close();
        ps.close();
        conn.close();
    }
mysql> show create table t;
+-------+------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                               |
+-------+------------------------------------------------------------------------------------------------------------+
| t     | CREATE TABLE `t` (
  `id` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin |
+-------+------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> select * from t;
+------+
| id   |
+------+
|    1 |
|    2 |
+------+
2 rows in set (0.00 sec)

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

1

3. What did you see instead (Required)

Exception in thread "main" java.sql.SQLException: runtime error: index out of range [0] with length 0
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
	at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
	at com.mysql.cj.jdbc.result.ResultSetImpl.next(ResultSetImpl.java:1753)
	at prepared.Prepared.main(Prepared.java:18)

4. What is your TiDB version? (Required)

Master

I guess the panic is caused by this line of code: https://github.com/pingcap/tidb/blob/master/server/conn.go#L2211

@7yyo 7yyo added the type/bug The issue is confirmed as a bug. label Dec 21, 2021
@bb7133
Copy link
Member

bb7133 commented Dec 21, 2021

Very likely that it is introduced by #30285 , @xhebox PTAL.

@github-actions
Copy link

Please check whether the issue should be labeled with 'affects-x.y' or 'fixes-x.y.z', and then remove 'needs-more-info' label.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-5.4 This bug affects the 5.4.x(LTS) versions. severity/major sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants