[MDEV-13535] Query on MyISAM table corrupts the table Created: 2017-08-15  Updated: 2017-08-17  Resolved: 2017-08-17

Status: Closed
Project: MariaDB Server
Component/s: Storage Engine - MyISAM
Affects Version/s: 10.2.4, 10.2.7, 10.2
Fix Version/s: 10.2.8

Type: Bug Priority: Major
Reporter: Larry Loreman Assignee: Sergei Golubchik
Resolution: Fixed Votes: 0
Labels: myisam
Environment:

Red Hat Linux 6.9
Linux hostname 2.6.32-696.6.3.el6.x86_64 #1 SMP Fri Jun 30 13:24:18 EDT 2017 x86_64 x86_64 x86_64 GNU/Linux


Attachments: HTML File MyISAM_bug     File bug-mdev-13535.test     File pn_for_debugging.dump.gz    

 Description   

This sample query corrupts MyISAM table.

select * from pn_assigned where
	((pnmin<='2135760' and pnmax>='2135760')
	   or (pnmin<='2135790' and pnmax>='2135790')
	   or (pnmin>='2135760' and pnmax<='2135790')) order by pnmin



 Comments   
Comment by Alice Sherepa [ 2017-08-16 ]

Thanks for the report!
Reproducible on MariaDB >=10.2.4

little bit smaller test case:

CREATE TABLE `pn` (
  `pnmin` int,
  `pnmax` int,
  UNIQUE KEY `pnmin` (`pnmin`),
  UNIQUE KEY `pnmax` (`pnmax`)
) ENGINE=MyISAM;
 
INSERT INTO `pn` VALUES (2135738,2135764),(1800,1899),(1700,1799),(1600,1699),(1500,1599),(1400,1499),(1300,1399),(1200,1299),(2549984,2549985),(7755146,7755146),(3945,3945),(3946,3946),(3947,3947);
 
select * from pn where pnmin='2135738';
 
select * from pn where ((pnmin<='2135760' and pnmax>='2135760')
or (pnmin<='2135790' and pnmax>='2135790')
or (pnmin>='2135760' and pnmax<='2135790')) ;
 
select * from pn where pnmin='2135738';

MariaDB [test]> select * from pn where pnmin='2135738';
+---------+---------+
| pnmin   | pnmax   |
+---------+---------+
| 2135738 | 2135764 |
+---------+---------+
1 row in set (0.00 sec)
 
MariaDB [test]> select * from pn where ((pnmin<='2135760' and pnmax>='2135760')
    -> or (pnmin<='2135790' and pnmax>='2135790')
    -> or (pnmin>='2135760' and pnmax<='2135790')) ;
+---------+---------+
| pnmin   | pnmax   |
+---------+---------+
| 2135738 | 2135764 |
+---------+---------+
1 row in set (0.00 sec)
 
MariaDB [test]> select * from pn where pnmin='2135738';
+---------+-------+
| pnmin   | pnmax |
+---------+-------+
| 2135738 |  NULL |
+---------+-------+
1 row in set (0.00 sec)
 
MariaDB [test]> flush tables;
Query OK, 0 rows affected (0.00 sec)
 
MariaDB [test]> select * from pn where pnmin='2135738';
+---------+---------+
| pnmin   | pnmax   |
+---------+---------+
| 2135738 | 2135764 |
+---------+---------+
1 row in set (0.00 sec)

Comment by Elena Stepanova [ 2017-08-16 ]

alice, is there more to it than just the test case? Configuration options, something system-specific?

MariaDB [test]> select * from pn where ((pnmin<='2135760' and pnmax>='2135760')
    -> or (pnmin<='2135790' and pnmax>='2135790')
    -> or (pnmin>='2135760' and pnmax<='2135790')) ;
+---------+---------+
| pnmin   | pnmax   |
+---------+---------+
| 2135738 | 2135764 |
+---------+---------+
1 row in set (0.00 sec)
 
MariaDB [test]>  
MariaDB [test]> select * from pn where pnmin='2135738';
+---------+---------+
| pnmin   | pnmax   |
+---------+---------+
| 2135738 | 2135764 |
+---------+---------+
1 row in set (0.00 sec)

MariaDB [test]> select @@version;
+----------------+
| @@version      |
+----------------+
| 10.2.7-MariaDB |
+----------------+
1 row in set (0.00 sec)

Comment by Alice Sherepa [ 2017-08-16 ]

I used default options. reduced test case fails on 10.2.4, but not on 10.2.7.
test with more data gives wrong results on both. Please find test attached. bug-mdev-13535.test

Comment by Elena Stepanova [ 2017-08-16 ]

The failure appeared in 10.2 tree with this commit

commit cff144a8ea47be2db8aace52cc282f4d2e0d7aaa
Author: Sergei Golubchik
Date:   Sat Feb 4 19:17:42 2017 +0100
 
    cleanup: handler::key_read
    
    * rename to "keyread" (to avoid conflicts with tokudb),
    * change from bool to uint and store the keyread index number there
    * provide a bool accessor to check if keyread is enabled

Generated at Thu Feb 08 08:06:20 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.