Skip to content

Commit 96252c1

Browse files
author
mronstrom@mysql.com
committed
Bug #10901
Analyze table corrupts the state on data_file_length, records, index_file_length... by writing the shared state when there is an updated internal state due to inserts or deletes Fixed by synching the shared state with the internal state before writing it to disk Added test cases of 2 error cases and a normal case in new analyze test case
1 parent 7bd3dd7 commit 96252c1

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed

BitKeeper/etc/logging_ok

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ monty@tik.
104104
monty@tik.mysql.fi
105105
monty@tramp.mysql.fi
106106
monty@work.mysql.com
107+
mronstrom@mysql.com
107108
mwagner@cash.mwagner.org
108109
mwagner@evoq.mwagner.org
109110
mwagner@here.mwagner.org

myisam/mi_check.c

+6
Original file line numberDiff line numberDiff line change
@@ -3623,6 +3623,12 @@ int update_state_info(MI_CHECK *param, MI_INFO *info,uint update)
36233623
if (!share->state.create_time)
36243624
share->state.create_time=share->state.check_time;
36253625
}
3626+
/*
3627+
When tables are locked we haven't synched the share state and the
3628+
real state for a while so we better do it here before synching
3629+
the share state to disk.
3630+
*/
3631+
share->state.state= *info->state;
36263632
if (mi_state_info_write(share->kfile,&share->state,1+2))
36273633
goto err;
36283634
share->changed=0;

mysql-test/r/analyze.result

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
create table t1 (a bigint);
2+
lock tables t1 write;
3+
insert into t1 values(0);
4+
analyze table t1;
5+
Table Op Msg_type Msg_text
6+
test.t1 analyze status OK
7+
unlock tables;
8+
check table t1;
9+
Table Op Msg_type Msg_text
10+
test.t1 check status OK
11+
drop table t1;
12+
create table t1 (a bigint);
13+
insert into t1 values(0);
14+
lock tables t1 write;
15+
delete from t1;
16+
analyze table t1;
17+
Table Op Msg_type Msg_text
18+
test.t1 analyze status OK
19+
unlock tables;
20+
check table t1;
21+
Table Op Msg_type Msg_text
22+
test.t1 check status OK
23+
drop table t1;
24+
create table t1 (a bigint);
25+
insert into t1 values(0);
26+
analyze table t1;
27+
Table Op Msg_type Msg_text
28+
test.t1 analyze status OK
29+
check table t1;
30+
Table Op Msg_type Msg_text
31+
test.t1 check status OK
32+
drop table t1;

mysql-test/t/analyze.test

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#
2+
# Bug #10901 Analyze Table on new table destroys table
3+
# This is minimal test case to get error
4+
# The problem was that analyze table wrote the shared state to the file and this
5+
# didn't include the inserts while locked. A check was needed to ensure that
6+
# state information was not updated when executing analyze table for a locked table.
7+
# The analyze table had to be within locks and check table had to be after unlocking
8+
# since then it brings the wrong state from disk rather than from the currently
9+
# correct internal state. The insert is needed since it changes the file state,
10+
# number of records.
11+
# The fix is to synchronise the state of the shared state and the current state before
12+
# calling mi_state_info_write
13+
#
14+
create table t1 (a bigint);
15+
lock tables t1 write;
16+
insert into t1 values(0);
17+
analyze table t1;
18+
unlock tables;
19+
check table t1;
20+
21+
drop table t1;
22+
23+
create table t1 (a bigint);
24+
insert into t1 values(0);
25+
lock tables t1 write;
26+
delete from t1;
27+
analyze table t1;
28+
unlock tables;
29+
check table t1;
30+
31+
drop table t1;
32+
33+
create table t1 (a bigint);
34+
insert into t1 values(0);
35+
analyze table t1;
36+
check table t1;
37+
38+
drop table t1;
39+

0 commit comments

Comments
 (0)