From 38a72a162a29029ea2af78ae112d98ce59209a12 Mon Sep 17 00:00:00 2001 From: "vva@eagle.mysql.r18.ru" <> Date: Fri, 20 Feb 2004 00:33:16 +0400 Subject: [PATCH] fixed for BUG #2719 "Heap tables status shows wrong or missing data" --- heap/hp_delete.c | 7 +++- heap/hp_write.c | 3 ++ mysql-test/r/show_check.result | 74 ++++++++++++++++++++++++++++++++++ mysql-test/t/show_check.test | 54 +++++++++++++++++++++++++ 4 files changed, 137 insertions(+), 1 deletion(-) diff --git a/heap/hp_delete.c b/heap/hp_delete.c index 73e431e6e66..89d685b7d0b 100644 --- a/heap/hp_delete.c +++ b/heap/hp_delete.c @@ -67,6 +67,8 @@ int hp_rb_delete_key(HP_INFO *info, register HP_KEYDEF *keyinfo, const byte *record, byte *recpos, int flag) { heap_rb_param custom_arg; + uint old_allocated; + int res; if (flag) info->last_pos= NULL; /* For heap_rnext/heap_rprev */ @@ -74,7 +76,10 @@ int hp_rb_delete_key(HP_INFO *info, register HP_KEYDEF *keyinfo, custom_arg.keyseg= keyinfo->seg; custom_arg.key_length= hp_rb_make_key(keyinfo, info->recbuf, record, recpos); custom_arg.search_flag= SEARCH_SAME; - return tree_delete(&keyinfo->rb_tree, info->recbuf, &custom_arg); + old_allocated= keyinfo->rb_tree.allocated; + res= tree_delete(&keyinfo->rb_tree, info->recbuf, &custom_arg); + info->s->index_length+= (keyinfo->rb_tree.allocated-old_allocated); + return res; } /* Remove one key from hash-table */ diff --git a/heap/hp_write.c b/heap/hp_write.c index f92d8caa633..3b0ec76d616 100644 --- a/heap/hp_write.c +++ b/heap/hp_write.c @@ -99,6 +99,7 @@ int hp_rb_write_key(HP_INFO *info, HP_KEYDEF *keyinfo, const byte *record, byte *recpos) { heap_rb_param custom_arg; + uint old_allocated; info->last_pos= NULL; /* For heap_rnext/heap_rprev */ custom_arg.keyseg= keyinfo->seg; @@ -113,12 +114,14 @@ int hp_rb_write_key(HP_INFO *info, HP_KEYDEF *keyinfo, const byte *record, custom_arg.search_flag= SEARCH_SAME; keyinfo->rb_tree.flag= 0; } + old_allocated= keyinfo->rb_tree.allocated; if (!tree_insert(&keyinfo->rb_tree, (void*)info->recbuf, custom_arg.key_length, &custom_arg)) { my_errno= HA_ERR_FOUND_DUPP_KEY; return 1; } + info->s->index_length+= (keyinfo->rb_tree.allocated-old_allocated); return 0; } diff --git a/mysql-test/r/show_check.result b/mysql-test/r/show_check.result index 235c6cd0ecf..2dc715f238f 100644 --- a/mysql-test/r/show_check.result +++ b/mysql-test/r/show_check.result @@ -313,3 +313,77 @@ table CREATE TABLE `table` ( ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE `table`; SET sql_quote_show_create=ON; +select @@max_heap_table_size; +@@max_heap_table_size +1047552 +CREATE TABLE t1 ( +a int(11) default NULL, +KEY a TYPE BTREE (a) +) ENGINE=HEAP; +CREATE TABLE t2 ( +b int(11) default NULL, +index(b) +) ENGINE=HEAP; +CREATE TABLE t3 ( +a int(11) default NULL, +b int(11) default NULL, +KEY a TYPE BTREE (a), +index(b) +) ENGINE=HEAP; +insert into t1 values (1),(2); +insert into t2 values (1),(2); +insert into t3 values (1,1),(2,2); +show table status; +Name Type Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment +t1 HEAP Fixed 2 5 39904 249415 42 0 NULL NULL NULL NULL latin1_swedish_ci NULL +t2 HEAP Fixed 2 5 39904 249415 39904 0 NULL NULL NULL NULL latin1_swedish_ci NULL +t3 HEAP Fixed 2 9 33072 248103 22090 0 NULL NULL NULL NULL latin1_swedish_ci NULL +insert into t1 values (3),(4); +insert into t2 values (3),(4); +insert into t3 values (3,3),(4,4); +show table status; +Name Type Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment +t1 HEAP Fixed 4 5 39904 249415 84 0 NULL NULL NULL NULL latin1_swedish_ci NULL +t2 HEAP Fixed 4 5 39904 249415 39904 0 NULL NULL NULL NULL latin1_swedish_ci NULL +t3 HEAP Fixed 4 9 33072 248103 22132 0 NULL NULL NULL NULL latin1_swedish_ci NULL +insert into t1 values (5); +insert into t2 values (5); +insert into t3 values (5,5); +show table status; +Name Type Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment +t1 HEAP Fixed 5 5 39904 249415 105 0 NULL NULL NULL NULL latin1_swedish_ci NULL +t2 HEAP Fixed 5 5 39904 249415 39904 0 NULL NULL NULL NULL latin1_swedish_ci NULL +t3 HEAP Fixed 5 9 33072 248103 22153 0 NULL NULL NULL NULL latin1_swedish_ci NULL +delete from t1 where a=3; +delete from t2 where b=3; +delete from t3 where a=3; +show table status; +Name Type Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment +t1 HEAP Fixed 4 5 39904 249415 105 5 NULL NULL NULL NULL latin1_swedish_ci NULL +t2 HEAP Fixed 4 5 39904 249415 39904 5 NULL NULL NULL NULL latin1_swedish_ci NULL +t3 HEAP Fixed 4 9 33072 248103 22153 9 NULL NULL NULL NULL latin1_swedish_ci NULL +delete from t1; +delete from t2; +delete from t3; +show table status; +Name Type Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment +t1 HEAP Fixed 0 5 0 249415 0 0 NULL NULL NULL NULL latin1_swedish_ci NULL +t2 HEAP Fixed 0 5 0 249415 0 0 NULL NULL NULL NULL latin1_swedish_ci NULL +t3 HEAP Fixed 0 9 0 248103 0 0 NULL NULL NULL NULL latin1_swedish_ci NULL +insert into t1 values (5); +insert into t2 values (5); +insert into t3 values (5,5); +show table status; +Name Type Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment +t1 HEAP Fixed 1 5 39904 249415 21 0 NULL NULL NULL NULL latin1_swedish_ci NULL +t2 HEAP Fixed 1 5 39904 249415 39904 0 NULL NULL NULL NULL latin1_swedish_ci NULL +t3 HEAP Fixed 1 9 33072 248103 22069 0 NULL NULL NULL NULL latin1_swedish_ci NULL +delete from t1 where a=5; +delete from t2 where b=5; +delete from t3 where a=5; +show table status; +Name Type Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment +t1 HEAP Fixed 0 5 39904 249415 21 5 NULL NULL NULL NULL latin1_swedish_ci NULL +t2 HEAP Fixed 0 5 39904 249415 39904 5 NULL NULL NULL NULL latin1_swedish_ci NULL +t3 HEAP Fixed 0 9 33072 248103 22069 9 NULL NULL NULL NULL latin1_swedish_ci NULL +drop table t1, t2, t3; diff --git a/mysql-test/t/show_check.test b/mysql-test/t/show_check.test index 1d64cfd2105..935e472c4a1 100644 --- a/mysql-test/t/show_check.test +++ b/mysql-test/t/show_check.test @@ -182,3 +182,57 @@ SHOW CREATE TABLE `table`; DROP TABLE `table`; SET sql_quote_show_create=ON; + +# +# Test for bug #2719 "Heap tables status shows wrong or missing data." +# + +select @@max_heap_table_size; + +CREATE TABLE t1 ( + a int(11) default NULL, + KEY a TYPE BTREE (a) +) ENGINE=HEAP; + +CREATE TABLE t2 ( + b int(11) default NULL, + index(b) +) ENGINE=HEAP; + +CREATE TABLE t3 ( + a int(11) default NULL, + b int(11) default NULL, + KEY a TYPE BTREE (a), + index(b) +) ENGINE=HEAP; + +insert into t1 values (1),(2); +insert into t2 values (1),(2); +insert into t3 values (1,1),(2,2); +show table status; +insert into t1 values (3),(4); +insert into t2 values (3),(4); +insert into t3 values (3,3),(4,4); +show table status; +insert into t1 values (5); +insert into t2 values (5); +insert into t3 values (5,5); +show table status; +delete from t1 where a=3; +delete from t2 where b=3; +delete from t3 where a=3; +show table status; +delete from t1; +delete from t2; +delete from t3; +show table status; +insert into t1 values (5); +insert into t2 values (5); +insert into t3 values (5,5); +show table status; +delete from t1 where a=5; +delete from t2 where b=5; +delete from t3 where a=5; +show table status; + +drop table t1, t2, t3;