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

bug: Query result set error,Involving primary key #988

Closed
2 of 3 tasks
shangyanwen opened this issue Nov 23, 2022 · 5 comments
Closed
2 of 3 tasks

bug: Query result set error,Involving primary key #988

shangyanwen opened this issue Nov 23, 2022 · 5 comments
Assignees
Labels
A-bug Something isn't working

Comments

@shangyanwen
Copy link
Contributor

Have you read the Contributing Guidelines on issues?

Please confirm if bug report does NOT exists already ?

  • I confirm there is no existing issue for this

Describe the problem

mysql> SELECT count(id) FROM t1 where id<1000;
+-----------+
| count(id) |
+-----------+
|       999 |
+-----------+

Expected behavior

MySQL(innodb) results:

mysql> SELECT count(id) FROM t1 where id<1000;
+-----------+
| count(id) |
+-----------+
|       992 |
+-----------+

How To Reproduce

CREATE TABLE t1 (id BIGINT NOT NULL PRIMARY KEY auto_increment, pad1 BLOB, pad2 BLOB, pad3 BLOB, int_col INT NOT NULL DEFAULT 0);

INSERT INTO t1 SELECT NULL, RANDOM_BYTES(1024), RANDOM_BYTES(1024), RANDOM_BYTES(1024), 0 FROM dual;
INSERT INTO t1 SELECT NULL, RANDOM_BYTES(1024), RANDOM_BYTES(1024), RANDOM_BYTES(1024), 0 FROM t1 a JOIN t1 b JOIN t1 c;
INSERT INTO t1 SELECT NULL, RANDOM_BYTES(1024), RANDOM_BYTES(1024), RANDOM_BYTES(1024), 0 FROM t1 a JOIN t1 b JOIN t1 c;
INSERT INTO t1 SELECT NULL, RANDOM_BYTES(1024), RANDOM_BYTES(1024), RANDOM_BYTES(1024), 0 FROM t1 a JOIN t1 b JOIN t1 c;
SELECT count(id) FROM t1 where id<1000;

Environment

root@ub01:/stonedb57/install/bin# ./mysql --version
./mysql  Ver 14.14 Distrib 5.7.36-StoneDB, for Linux (x86_64) using  EditLine wrapper

#notes:v1.0.1

Are you interested in submitting a PR to solve the problem?

  • Yes, I will!
@shangyanwen shangyanwen added the A-bug Something isn't working label Nov 23, 2022
@shangyanwen shangyanwen changed the title bug: bug: Query result set error,Results are inconsistent with innodb Nov 23, 2022
@shangyanwen shangyanwen changed the title bug: Query result set error,Results are inconsistent with innodb bug: Query result set error,Involving primary key ,Results are inconsistent with innodb Nov 29, 2022
@shangyanwen shangyanwen changed the title bug: Query result set error,Involving primary key ,Results are inconsistent with innodb bug: Query result set error,Involving primary key Nov 29, 2022
@adofsauron
Copy link
Collaborator

ACK

@adofsauron
Copy link
Collaborator

adofsauron commented Nov 30, 2022

Compare INNODB query results:

INNODB:

mysql> SELECT id FROM t1 where id < 1000 limit 20;
+----+
| id |
+----+
|  1 |
|  2 |
|  3 |
|  4 |
|  5 |
|  6 |
|  7 |
|  8 |
|  9 |
| 10 |
| 18 |
| 19 |
| 20 |
| 21 |
| 22 |
| 23 |
| 24 |
| 25 |
| 26 |
| 27 |
+----+
20 rows in set (0.00 sec)

tianmu:

mysql> SELECT id FROM t1 where id < 1000 limit 20;
+----+
| id |
+----+
|  1 |
|  2 |
|  3 |
|  4 |
|  5 |
|  6 |
|  7 |
|  8 |
|  9 |
| 10 |
| 11 |
| 12 |
| 13 |
| 14 |
| 15 |
| 16 |
| 17 |
| 18 |
| 19 |
| 20 |
+----+
20 rows in set (0.00 sec)

@adofsauron
Copy link
Collaborator

The reason is that mysql has an incremental lock policy, which is innodb_autoinc_lock_mode

ref: https://dev.mysql.com/doc/refman/5.7/en/innodb-auto-increment-handling.html

When innodb_autoinc_lock_mode is set to 0, INNODB autoincrement is increased to 1, the same result as TIANMU

mysql> set global innodb_autoinc_lock_mode=0;
ERROR 1238 (HY000): Variable 'innodb_autoinc_lock_mode' is a read only variable
mysql> show global variables like 'innodb_autoinc_lock_mode';
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id:    2
Current database: d51

+--------------------------+-------+
| Variable_name            | Value |
+--------------------------+-------+
| innodb_autoinc_lock_mode | 0     |
+--------------------------+-------+
1 row in set (0.01 sec)

mysql> 
mysql> 
mysql> drop table t1;
Query OK, 0 rows affected (0.01 sec)

mysql> CREATE TABLE t1 (id BIGINT NOT NULL PRIMARY KEY auto_increment, pad1 BLOB, pad2 BLOB, pad3 BLOB, int_col INT NOT NULL DEFAULT 0) ENGINE=INNODB AUTO_INCREMENT=1;
Query OK, 0 rows affected (0.00 sec)

mysql> INSERT INTO t1 SELECT NULL, 'abcd', 'abcd', 'abcd', 0 FROM dual;
 NULL, 'abcd', 'abcd', 'abcd', 0 FROM t1 a JOIN t1 b JOIN t1 c;
Query OK, 1 row affected (0.00 sec)
Records: 1  Duplicates: 0  Warnings: 0

mysql> INSERT INTO t1 SELECT NULL, 'abcd', 'abcd', 'abcd', 0 FROM t1 a JOIN t1 b JOIN t1 c;
Query OK, 1 row affected (0.00 sec)
Records: 1  Duplicates: 0  Warnings: 0

mysql> INSERT INTO t1 SELECT NULL, 'abcd', 'abcd', 'abcd', 0 FROM t1 a JOIN t1 b JOIN t1 c;
Query OK, 8 rows affected (0.01 sec)
Records: 8  Duplicates: 0  Warnings: 0

mysql> INSERT INTO t1 SELECT NULL, 'abcd', 'abcd', 'abcd', 0 FROM t1 a JOIN t1 b JOIN t1 c;
Query OK, 1000 rows affected (0.00 sec)
Records: 1000  Duplicates: 0  Warnings: 0

mysql> SELECT id FROM t1 where id<1000 limit 20;
+----+
| id |
+----+
|  1 |
|  2 |
|  3 |
|  4 |
|  5 |
|  6 |
|  7 |
|  8 |
|  9 |
| 10 |
| 11 |
| 12 |
| 13 |
| 14 |
| 15 |
| 16 |
| 17 |
| 18 |
| 19 |
| 20 |
+----+
20 rows in set (0.00 sec)

mysql> SELECT count(id) FROM t1 where id<1000;
+-----------+
| count(id) |
+-----------+
|       999 |
+-----------+
1 row in set (0.00 sec)

mysql> show create table t1\G
*************************** 1. row ***************************
       Table: t1
Create Table: CREATE TABLE `t1` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `pad1` blob,
  `pad2` blob,
  `pad3` blob,
  `int_col` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1011 DEFAULT CHARSET=latin1
1 row in set (0.00 sec)

@adofsauron
Copy link
Collaborator

This is a BUG in the testing process and will not be resolved

@RingsC
Copy link
Contributor

RingsC commented Nov 30, 2022

We close it now, and feel free to reopen.

@RingsC RingsC closed this as completed Nov 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants