Bug #100048 Select returns an unexpected result
Submitted: 30 Jun 2020 11:04 Modified: 30 Jun 2020 13:03
Reporter: lyp tennyson Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: InnoDB storage engine Severity:S3 (Non-critical)
Version:8.0.20 OS:Linux
Assigned to: CPU Architecture:Any

[30 Jun 2020 11:04] lyp tennyson
Description:
Select returns an unexpected result.

How to repeat:
Establish two sessions with client to MySQL server, naming SessionA, SessionB respectively.

Execute SQLs in the following order:

1. on SessionA
  mysql> create table t1 (a int primary key);
  Query OK, 0 rows affected (0.01 sec)

  mysql> insert into t1 values (1);
  Query OK, 1 row affected (0.00 sec)

  mysql> set autocommit=0;
  Query OK, 0 rows affected (0.00 sec)

  mysql> select * from t1;
  +---+
  | a |
  +---+
  | 1 |
  +---+
  1 row in set (0.00 sec)

2. on SessionB
  mysql> update t1 set a=2 where a=1;
  Query OK, 1 row affected (0.00 sec)
  Rows matched: 1  Changed: 1  Warnings: 0

  mysql> select * from t1;
  +---+
  | a |
  +---+
  | 2 |
  +---+
  1 row in set (0.00 sec)

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

  mysql> update t1 set a=4 where a=2;
  Query OK, 1 row affected (0.00 sec)
  Rows matched: 1  Changed: 1  Warnings: 0

  mysql> select * from t1;
  +---+
  | a |
  +---+
  | 4 |
  +---+
  1 row in set (0.00 sec)

3. on SessionA
  mysql> update t1 set a=3 where a=2;
  # Now the session pending, no output

4. on SessionB
  mysql> rollback;
  Query OK, 0 rows affected (0.00 sec)

  mysql> select * from t1;
  +---+
  | a |
  +---+
  | 2 |
  +---+
  1 row in set (0.00 sec)

5. on SessionA
  # Now the pending sql returns
  #mysql> update t1 set a=3 where a=2;
  Query OK, 1 row affected (5.52 sec)
  Rows matched: 1  Changed: 1  Warnings: 0

  mysql> select * from t1;
  +---+
  | a |
  +---+
  | 1 |
  | 3 |
  +---+
  2 rows in set (0.00 sec)

  ## Here, 'select * from t1' returns two records, why?

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

  mysql> select * from t1;
  +---+
  | a |
  +---+
  | 3 |
  +---+
  1 row in set (0.00 sec)

Suggested fix:
In the step 5,  'select * from t1' firstly returns two records,

and after committed, one record is returned.

This is very puzzling.
[30 Jun 2020 13:03] MySQL Verification Team
Hi Mr. tennyson,

Thank you for your bug report.

However, this is not a bug.

Your test case clearly proves that InnoDB Storage Engine works properly and that isolation levels are correctly observed. Innodb SE is a MVCC engine and this is exactly how MVCC engine should function.

Not a bug.