Commit e0aadfd4 authored by Sergey Vojtovich's avatar Sergey Vojtovich

BUG#47444 - --myisam_repair_threads>1can result in all

            index cardinalities=1

Parallel repair didn't poroperly update index cardinality
in certain cases.

When myisam_sort_buffer_size is not enough to store all
keys, index cardinality was updated before index was
actually written, when no index statistic is available.

mysql-test/r/myisam.result:
  A test case for BUG#47444.
mysql-test/t/myisam.test:
  A test case for BUG#47444.
storage/myisam/sort.c:
  update_key_parts() must be called after all index
  entries are written, when index statistic is available.
parent b182c9bd
...@@ -2389,4 +2389,23 @@ SELECT * FROM t1, t1 AS a1 WHERE t1.a=1 AND a1.a=1; ...@@ -2389,4 +2389,23 @@ SELECT * FROM t1, t1 AS a1 WHERE t1.a=1 AND a1.a=1;
a a a a
1 1 1 1
DROP TABLE t1; DROP TABLE t1;
#
# BUG#47444 - --myisam_repair_threads>1can result in all index
# cardinalities=1
#
SET myisam_repair_threads=2;
SET myisam_sort_buffer_size=4096;
CREATE TABLE t1(a CHAR(255), KEY(a), KEY(a), KEY(a));
INSERT INTO t1 VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9),(0),(1),(2),(3);
REPAIR TABLE t1;
Table Op Msg_type Msg_text
test.t1 repair status OK
SELECT CARDINALITY FROM INFORMATION_SCHEMA.STATISTICS WHERE TABLE_SCHEMA='test' AND TABLE_NAME='t1';
CARDINALITY
14
14
14
DROP TABLE t1;
SET myisam_sort_buffer_size=@@global.myisam_sort_buffer_size;
SET myisam_repair_threads=@@global.myisam_repair_threads;
End of 5.1 tests End of 5.1 tests
...@@ -1631,4 +1631,18 @@ INSERT INTO t1 VALUES('1'); ...@@ -1631,4 +1631,18 @@ INSERT INTO t1 VALUES('1');
SELECT * FROM t1, t1 AS a1 WHERE t1.a=1 AND a1.a=1; SELECT * FROM t1, t1 AS a1 WHERE t1.a=1 AND a1.a=1;
DROP TABLE t1; DROP TABLE t1;
--echo #
--echo # BUG#47444 - --myisam_repair_threads>1can result in all index
--echo # cardinalities=1
--echo #
SET myisam_repair_threads=2;
SET myisam_sort_buffer_size=4096;
CREATE TABLE t1(a CHAR(255), KEY(a), KEY(a), KEY(a));
INSERT INTO t1 VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9),(0),(1),(2),(3);
REPAIR TABLE t1;
SELECT CARDINALITY FROM INFORMATION_SCHEMA.STATISTICS WHERE TABLE_SCHEMA='test' AND TABLE_NAME='t1';
DROP TABLE t1;
SET myisam_sort_buffer_size=@@global.myisam_sort_buffer_size;
SET myisam_repair_threads=@@global.myisam_repair_threads;
--echo End of 5.1 tests --echo End of 5.1 tests
...@@ -506,7 +506,7 @@ int thr_write_keys(MI_SORT_PARAM *sort_param) ...@@ -506,7 +506,7 @@ int thr_write_keys(MI_SORT_PARAM *sort_param)
for (i= 0, sinfo= sort_param ; for (i= 0, sinfo= sort_param ;
i < sort_info->total_keys ; i < sort_info->total_keys ;
i++, rec_per_key_part+=sinfo->keyinfo->keysegs, sinfo++) i++, sinfo++)
{ {
if (!sinfo->sort_keys) if (!sinfo->sort_keys)
{ {
...@@ -529,11 +529,6 @@ int thr_write_keys(MI_SORT_PARAM *sort_param) ...@@ -529,11 +529,6 @@ int thr_write_keys(MI_SORT_PARAM *sort_param)
flush_ft_buf(sinfo) || flush_pending_blocks(sinfo)) flush_ft_buf(sinfo) || flush_pending_blocks(sinfo))
got_error=1; got_error=1;
} }
if (!got_error && param->testflag & T_STATISTICS)
update_key_parts(sinfo->keyinfo, rec_per_key_part, sinfo->unique,
param->stats_method == MI_STATS_METHOD_IGNORE_NULLS?
sinfo->notnull: NULL,
(ulonglong) info->state->records);
} }
my_free((uchar*) sinfo->sort_keys,MYF(0)); my_free((uchar*) sinfo->sort_keys,MYF(0));
my_free(mi_get_rec_buff_ptr(info, sinfo->rec_buff), my_free(mi_get_rec_buff_ptr(info, sinfo->rec_buff),
...@@ -547,7 +542,7 @@ int thr_write_keys(MI_SORT_PARAM *sort_param) ...@@ -547,7 +542,7 @@ int thr_write_keys(MI_SORT_PARAM *sort_param)
delete_dynamic(&sinfo->buffpek), delete_dynamic(&sinfo->buffpek),
close_cached_file(&sinfo->tempfile), close_cached_file(&sinfo->tempfile),
close_cached_file(&sinfo->tempfile_for_exceptions), close_cached_file(&sinfo->tempfile_for_exceptions),
sinfo++) rec_per_key_part+= sinfo->keyinfo->keysegs, sinfo++)
{ {
if (got_error) if (got_error)
continue; continue;
...@@ -639,6 +634,11 @@ int thr_write_keys(MI_SORT_PARAM *sort_param) ...@@ -639,6 +634,11 @@ int thr_write_keys(MI_SORT_PARAM *sort_param)
got_error=1; got_error=1;
} }
} }
if (!got_error && param->testflag & T_STATISTICS)
update_key_parts(sinfo->keyinfo, rec_per_key_part, sinfo->unique,
param->stats_method == MI_STATS_METHOD_IGNORE_NULLS ?
sinfo->notnull : NULL,
(ulonglong) info->state->records);
} }
my_free((uchar*) mergebuf,MYF(MY_ALLOW_ZERO_PTR)); my_free((uchar*) mergebuf,MYF(MY_ALLOW_ZERO_PTR));
DBUG_RETURN(got_error); DBUG_RETURN(got_error);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment