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

Query result on partition table wrong when using prepared-pan-cache #15720

Closed
imtbkcat opened this issue Mar 26, 2020 · 0 comments · Fixed by #15697
Closed

Query result on partition table wrong when using prepared-pan-cache #15720

imtbkcat opened this issue Mar 26, 2020 · 0 comments · Fixed by #15697
Labels
severity/critical type/bug The issue is confirmed as a bug.

Comments

@imtbkcat
Copy link

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. What did you do?

Turn on prepare-plan-cache, create table:

CREATE TABLE `sbtest1` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `k` int(11) NOT NULL DEFAULT '0',
  `c` char(120) NOT NULL DEFAULT '',
  `pad` char(60) NOT NULL DEFAULT '',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=61255
PARTITION BY RANGE ( `id` ) (
  PARTITION p0 VALUES LESS THAN (10),
  PARTITION p1 VALUES LESS THAN (30),
  PARTITION p2 VALUES LESS THAN (60),
  PARTITION p3 VALUES LESS THAN (80),
  PARTITION p4 VALUES LESS THAN (MAXVALUE)
)

Then insert some data.

Using JDBC test script:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.PreparedStatement;

public class Main {
    private static final String URL="jdbc:mysql://172.16.5.34:4000/test?useSSL=false&useServerPrepStmts=true&useConfigs=maxPerformance";
    private static final String NAME="root";
    private static final String PASSWORD="";
    public static int[] arr = {9, 33, 59, 20};

    public static void main(String[] args) throws Exception {
        Class.forName("com.mysql.jdbc.Driver");
        Connection conn = DriverManager.getConnection(URL, NAME, PASSWORD);
        String sql = "select count(1) from sbtest1 where id = ?";
        PreparedStatement statement = conn.prepareStatement(sql);
        statement.setInt(1, 9);
        ResultSet rs1 = statement.executeQuery();
        while (rs1.next()) {
            System.out.println(rs1.getString(1));
        }
        statement.setInt(1, 33);
        ResultSet rs2 = statement.executeQuery();
        while (rs2.next()) {
            System.out.println(rs2.getString(1));
        }
        statement.setInt(1, 59);
        ResultSet rs3 = statement.executeQuery();
        while (rs3.next()) {
            System.out.println(rs3.getString(1));
        }
        statement.setInt(1, 20);
        ResultSet rs4 = statement.executeQuery();
        while (rs4.next()) {
            System.out.println(rs4.getString(1));
        }
    }
}

2. What did you expect to see?

1 1 1 1

Since there is data in these partition:

mysql> select k from sbtest1 where id in (9, 33, 59, 20);
+----+
| k  |
+----+
| 51 |
| 50 |
| 50 |
| 51 |
+----+

3. What did you see instead?

1 0 0 0

4. What version of TiDB are you using? (tidb-server -V or run select tidb_version(); on TiDB)

mysql> select tidb_version();
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version()                                                                                                                                                                                                                                                                                          |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v3.0.4
Git Commit Hash: 694e086e7914a8fc0eb601327edb6bcc31d2c7f2
Git Branch: HEAD
UTC Build Time: 2019-10-08 08:13:34
GoVersion: go version go1.12.10 linux/amd64
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
severity/critical type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants