Bug #47444 --myisam_repair_threads>1can result in all index cardinalities=1
Submitted: 18 Sep 18:27
Reporter: Shawn Green
Status: Verified
Category:Server: MyISAM Severity:S2 (Serious)
Version:5.1.37, 5.1.38 OS:Any
Assigned to: Target Version:
Tags: myisam, myisam_repair_threads
Triage: Needs Triage: D2 (Serious) / R6 (Needs Assessment) / E6 (Needs Assessment)

[18 Sep 18:27] Shawn Green
Description:
This is a split/continuation of bug #18874. This new bug was created to keep the
additional research and patch to repair this extension of bug #18847 separate and
distinct from that previous effort. 
~~~
When filling a truncated table with data and --myisam-repair-threads>1, then all indexes
on that table will not get cardinality values, they will all be =1. 

Running ANALYZE TABLE will not fix this problem with the index statistics. Only CHECK
TABLE will resolve the problem. 

How to repeat:
        drop table if exists `t2`,t1;

CREATE TABLE `t2` (
`c1` int(11) NOT NULL,
`c2` int(11) NOT NULL,
`c3` int(11) NOT NULL,
`c4` int(11) NOT NULL,
`c5` int(11) NOT NULL,
`c6` int(11) NOT NULL,
`c7` int(11) NOT NULL,
`c8` int(11) NOT NULL,
`c9` int(11) NOT NULL,
`c10` int(11) NOT NULL,
`c11` int(11) NOT NULL,
`c12` int(11) NOT NULL,
`c13` int(11) NOT NULL,
`c14` int(11) NOT NULL,
`c15` varchar(50) NOT NULL,
`c16` int(11) NOT NULL,
`c17` int(11) NOT NULL,
`c18` int(11) NOT NULL,
`c19` int(11) NOT NULL,
`c20` int(11) NOT NULL,
KEY `ix1_2` (`c1`,`c2`),
KEY `ix20_2` (`c20`,`c2`),
KEY `IX6_5` (`c6`,`c5`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

create table t1 like `t2`;
alter table t1 disable keys;

insert into t1 values(
rand()*100000,
rand()*100000,
rand()*100000,
rand()*100000,
rand()*100000,
rand()*100000,
rand()*100000,
rand()*100000,
rand()*100000,
rand()*100000,
rand()*100000,
rand()*100000,
rand()*100000,
rand()*100000,
rand()*100000,
rand()*100000,
rand()*100000,
rand()*100000,
rand()*100000,
rand()*100000);
insert into t1 select * from t1;
insert into t1 select * from t1;
select count(*) from t1;
insert into t1 select rand()*100000,
rand()*100000,
rand()*100000,
rand()*100000,
rand()*100000,
rand()*100000,
rand()*100000,
rand()*100000,
rand()*100000,
rand()*100000,
rand()*100000,
rand()*100000,
rand()*100000,
rand()*100000,
rand()*100000,
rand()*100000,
rand()*100000,
rand()*100000,
rand()*100000,
rand()*100000 from t1 a,t1 b,t1 c,t1 d,t1 f,t1 g,t1 h,t1 i,t1 j,t1 k;

insert into `t2` select * from t1;
show indexes from `t2`;
truncate `t2`;
insert into `t2` select * from t1;
show indexes from `t2`;

Notes:
1) The original test case only tested for the explicit REPAIR TABLE. It did not test for
the behavior of filling an empty table (implicitly using a similar code path).

2) The original test case for bug #18874 only tested a new, single-column table using a
single index. 

3) The cardinality in my test case is correct for the initial load of data (first SHOW
INDEX) to the table but is incorrect following the truncate and reload if
myisam_repair_threads > 1 (second SHOW INDEX).

Suggested fix:
Need to finish the repairs to handle --myisam-repair-thread values > 1 started with bug
#18874.