[MDEV-28200] Rows just inserted sometimes not returned by select afterwards Created: 2022-03-30  Updated: 2022-08-01  Resolved: 2022-08-01

Status: Closed
Project: MariaDB Server
Component/s: Storage Engine - InnoDB
Affects Version/s: 10.4.22
Fix Version/s: 10.3.35, 10.4.25, 10.5.16, 10.6.8, 10.7.4, 10.8.3, 10.9.1

Type: Bug Priority: Major
Reporter: Martijn Assignee: Marko Mäkelä
Resolution: Duplicate Votes: 0
Labels: None
Environment:

Linux


Issue Links:
Duplicate
duplicates MDEV-20605 Awaken transaction can miss inserted ... Closed

 Description   

We have a relative simple InnoDB table with a primary key (integer; sequence number is generated by our client application) and a unique key (across several fields), that looks something like this:

CREATE TABLE `test` (
  `id` int(10) unsigned NOT NULL,
  `fieldA` char(3) NOT NULL,
  `fieldB` smallint(5) unsigned NOT NULL,
  `fieldC` smallint(5) unsigned NOT NULL,
  `fieldD` int(10) unsigned NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `idx_unique` (`fieldA`,`fieldB`,`fieldC`)
) ENGINE=InnoDB DEFAULT;

A client then inserts some records into the table:

START TRANSACTION;
INSERT INTO test VALUES (1, 'abc', 10, 10, 0), (2, 'def', 20, 20, 0), (3, 'ghi', 30, 30, 0);
COMMIT;

Some time later (between 0 and 30 seconds) the client performs a select, using the same still open MariaDB-connection (with no active transaction):

SELECT id FROM test WHERE 
    (fieldA = 'abc' AND fieldB = 10 AND fieldC = 10)
  OR
    (fieldA = 'def' AND fieldB = 20 AND fieldC = 20)
  OR
    (fieldA = 'ghi' AND fieldB = 30 AND fieldC = 30)

And sometimes gets only 2 rows returned, instead of the expected 3.

Sometimes, the SELECT returns the correct number of rows, but the exact same SELECT immediately after returns the incorrect number of rows.

Rows are never updated and are only deleted once a day during a nightly batch run.
The table contains around 60 million rows with anywhere between 300.000 and 1.000.000 new rows (spread across the day) and deleted rows (at night) each day.

The problem happens a couple of times a week, for almost two years now (ever since we migrated the table from MyISAM to InnoDB). We believe it happens more frequent when the table is under high load (which seems plausible, because it appears to be a race condition of some sorts)

We're currently running MariaDB 10.4.22, but the problem also occurred with older 10.4.x versions.

Unfortunately we haven't been able to create a reproducible test case. This probably isn't the most helpful issue description. We're happy gather and provide more details if needed.



 Comments   
Comment by Marko Mäkelä [ 2022-03-30 ]

tgm, does CHECK TABLE report any errors? Can you repeat the mismatches after disabling the change buffer (MDEV-27734)?

MDEV-27746 and MDEV-20605 were fixed after the 10.4.22 release and might explain this.

Comment by Martijn [ 2022-03-31 ]

Interesting. The table checks out OK, no errors.

I've disabled the change buffer and will report back in a week with the results (or earlier, if it still happens).

Comment by Martijn [ 2022-04-01 ]

Unfortunately turning off the change buffer did not help. The same problem occurred twice today.

Comment by Martijn [ 2022-06-29 ]

We've upgraded from MariaDB 10.4.22 to 10.6.5. I'll update this thread if the bug still exists (or not).

Comment by Martijn [ 2022-07-19 ]

We have not had a single occurrence of this bug since upgrading to MariaDB 10.6. So I think it is safe to say the bug is in 10.4 and not 10.6.

Comment by Marko Mäkelä [ 2022-08-01 ]

Let us for now assume that this was a duplicate of MDEV-20605.

Generated at Thu Feb 08 09:58:52 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.