Commit 8a088f2e authored by serg@serg.mysql.com's avatar serg@serg.mysql.com

optimize table corruption fixed, though more clean fix is desired.

Fix for another optimize bug is undone, as the new one handles both cases.
test added
parent 392cbf9e
...@@ -38,3 +38,7 @@ table type possible_keys key key_len ref rows Extra ...@@ -38,3 +38,7 @@ table type possible_keys key key_len ref rows Extra
t1 ALL NULL NULL NULL NULL 4 t1 ALL NULL NULL NULL NULL 4
Table Op Msg_type Msg_text Table Op Msg_type Msg_text
test.t1 optimize status OK test.t1 optimize status OK
Table Op Msg_type Msg_text
test.t1 optimize status OK
Table Op Msg_type Msg_text
test.t1 check status OK
...@@ -75,6 +75,46 @@ INSERT INTO t1 VALUES (1), (2), (3); ...@@ -75,6 +75,46 @@ INSERT INTO t1 VALUES (1), (2), (3);
OPTIMIZE TABLE t1; OPTIMIZE TABLE t1;
DROP TABLE t1; DROP TABLE t1;
#
# Test of optimize, when only mi_sort_index (but not mi_repair*) is done
# in ha_myisam::repair, and index size is changed (decreased).
#
drop table if exists t1;
create table t1 ( t1 char(255), key(t1(250)));
insert t1 values ('137513751375137513751375137513751375137569516951695169516951695169516951695169');
insert t1 values ('178417841784178417841784178417841784178403420342034203420342034203420342034203');
insert t1 values ('213872387238723872387238723872387238723867376737673767376737673767376737673767');
insert t1 values ('242624262426242624262426242624262426242607890789078907890789078907890789078907');
insert t1 values ('256025602560256025602560256025602560256011701170117011701170117011701170117011');
insert t1 values ('276027602760276027602760276027602760276001610161016101610161016101610161016101');
insert t1 values ('281528152815281528152815281528152815281564956495649564956495649564956495649564');
insert t1 values ('292129212921292129212921292129212921292102100210021002100210021002100210021002');
insert t1 values ('380638063806380638063806380638063806380634483448344834483448344834483448344834');
insert t1 values ('411641164116411641164116411641164116411616301630163016301630163016301630163016');
insert t1 values ('420842084208420842084208420842084208420899889988998899889988998899889988998899');
insert t1 values ('438443844384438443844384438443844384438482448244824482448244824482448244824482');
insert t1 values ('443244324432443244324432443244324432443239613961396139613961396139613961396139');
insert t1 values ('485448544854485448544854485448544854485477847784778477847784778477847784778477');
insert t1 values ('494549454945494549454945494549454945494555275527552755275527552755275527552755');
insert t1 values ('538647864786478647864786478647864786478688918891889188918891889188918891889188');
insert t1 values ('565556555655565556555655565556555655565554845484548454845484548454845484548454');
insert t1 values ('607860786078607860786078607860786078607856665666566656665666566656665666566656');
insert t1 values ('640164016401640164016401640164016401640141274127412741274127412741274127412741');
insert t1 values ('719471947194719471947194719471947194719478717871787178717871787178717871787178');
insert t1 values ('742574257425742574257425742574257425742549604960496049604960496049604960496049');
insert t1 values ('887088708870887088708870887088708870887035963596359635963596359635963596359635');
insert t1 values ('917791779177917791779177917791779177917773857385738573857385738573857385738573');
insert t1 values ('933293329332933293329332933293329332933278987898789878987898789878987898789878');
insert t1 values ('963896389638963896389638963896389638963877807780778077807780778077807780778077');
delete from t1 where t1>'2';
insert t1 values ('70'), ('84'), ('60'), ('20'), ('76'), ('89'), ('49'), ('50'),
('88'), ('61'), ('42'), ('98'), ('39'), ('30'), ('25'), ('66'), ('61'), ('48'),
('80'), ('84'), ('98'), ('19'), ('91'), ('42'), ('47');
optimize table t1;
check table t1;
drop table t1;
# #
# test of myisam with huge number of packed fields # test of myisam with huge number of packed fields
# #
......
...@@ -561,7 +561,6 @@ int ha_myisam::repair(THD *thd, MI_CHECK &param, bool optimize) ...@@ -561,7 +561,6 @@ int ha_myisam::repair(THD *thd, MI_CHECK &param, bool optimize)
} }
if (!optimize || if (!optimize ||
memcmp(file->state, & share->state.state, sizeof(MI_STATUS_INFO)) ||
((file->state->del || share->state.split != file->state->records) && ((file->state->del || share->state.split != file->state->records) &&
(!param.opt_rep_quick || (!param.opt_rep_quick ||
!(share->state.changed & STATE_NOT_OPTIMIZED_KEYS)))) !(share->state.changed & STATE_NOT_OPTIMIZED_KEYS))))
...@@ -618,7 +617,16 @@ int ha_myisam::repair(THD *thd, MI_CHECK &param, bool optimize) ...@@ -618,7 +617,16 @@ int ha_myisam::repair(THD *thd, MI_CHECK &param, bool optimize)
STATE_CRASHED_ON_REPAIR); STATE_CRASHED_ON_REPAIR);
file->update|=HA_STATE_CHANGED | HA_STATE_ROW_CHANGED; file->update|=HA_STATE_CHANGED | HA_STATE_ROW_CHANGED;
} }
file->save_state=file->s->state.state; /* Here we need to make file->save_state and file->s->state.state
equal. Unfortunately, sometime table comes locked here (so
file->save_state represents actual table state), and sometime
unlocked (and actual is file->s->state.state instead). This all
is very confusing, and should be streamlined (TODO).
*/
if (file->state == & file->save_state)
file->s->state.state=file->save_state;
else
file->save_state=file->s->state.state;
if (file->s->base.auto_key) if (file->s->base.auto_key)
update_auto_increment_key(&param, file, 1); update_auto_increment_key(&param, file, 1);
if (optimize_done) if (optimize_done)
......
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