From f2d7609ac0c1af1065400f6a6c8b5295c184f381 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Tue, 7 Aug 2012 01:58:05 +0300 Subject: [PATCH 1/5] Use less memory when growing HEAP tables. See MDEV-436 mysql-test/suite/heap/heap.result: Added test case for MDEV-436 mysql-test/suite/heap/heap.test: Added test case for MDEV-436 storage/heap/hp_block.c: Don't allocate a set of HP_PTRS when not needed. This saves us about 1024 bytes for most allocations. storage/heap/hp_create.c: Made the initial allocation of block sizes depending on min_records and max_records. --- mysql-test/suite/heap/heap.result | 24 ++++++++++++++++++++++++ mysql-test/suite/heap/heap.test | 23 +++++++++++++++++++++++ storage/heap/hp_block.c | 23 ++++++++++++----------- storage/heap/hp_create.c | 23 +++++++++++++++++------ 4 files changed, 76 insertions(+), 17 deletions(-) diff --git a/mysql-test/suite/heap/heap.result b/mysql-test/suite/heap/heap.result index f058c9f9c72..29ebf504e1a 100644 --- a/mysql-test/suite/heap/heap.result +++ b/mysql-test/suite/heap/heap.result @@ -738,3 +738,27 @@ SELECT c2 FROM t1; c2 0 DROP TABLE t1; +CREATE TABLE t1 (a int, index(a)) engine=heap min_rows=10 max_rows=100; +insert into t1 values(1); +select data_length,index_length from information_schema.tables where table_schema="test" and table_name="t1"; +data_length index_length +1600 2400 +drop table t1; +CREATE TABLE t1 (a int, index(a)) engine=heap min_rows=10 max_rows=10000; +insert into t1 values(1); +select data_length,index_length from information_schema.tables where table_schema="test" and table_name="t1"; +data_length index_length +16000 24000 +drop table t1; +CREATE TABLE t1 (a int, index(a)) engine=heap min_rows=3000 max_rows=3000; +insert into t1 values(1); +select data_length,index_length from information_schema.tables where table_schema="test" and table_name="t1"; +data_length index_length +48000 72000 +drop table t1; +CREATE TABLE t1 (a int, index(a)) engine=heap max_rows=4000; +insert into t1 values(1); +select data_length,index_length from information_schema.tables where table_schema="test" and table_name="t1"; +data_length index_length +16000 24000 +drop table t1; diff --git a/mysql-test/suite/heap/heap.test b/mysql-test/suite/heap/heap.test index 7d56425799a..062b48f2c31 100644 --- a/mysql-test/suite/heap/heap.test +++ b/mysql-test/suite/heap/heap.test @@ -485,3 +485,26 @@ INSERT INTO t1 VALUES('', 0); ALTER TABLE t1 MODIFY c1 VARCHAR(101); SELECT c2 FROM t1; DROP TABLE t1; + +# +# Show that MIN_ROWS and MAX_ROWS have an effect on how data_length +# and index_length are allocated. +# This is different for 32 and 64 bit machines as pointer lengths are different +# + +CREATE TABLE t1 (a int, index(a)) engine=heap min_rows=10 max_rows=100; +insert into t1 values(1); +select data_length,index_length from information_schema.tables where table_schema="test" and table_name="t1"; +drop table t1; +CREATE TABLE t1 (a int, index(a)) engine=heap min_rows=10 max_rows=10000; +insert into t1 values(1); +select data_length,index_length from information_schema.tables where table_schema="test" and table_name="t1"; +drop table t1; +CREATE TABLE t1 (a int, index(a)) engine=heap min_rows=3000 max_rows=3000; +insert into t1 values(1); +select data_length,index_length from information_schema.tables where table_schema="test" and table_name="t1"; +drop table t1; +CREATE TABLE t1 (a int, index(a)) engine=heap max_rows=4000; +insert into t1 values(1); +select data_length,index_length from information_schema.tables where table_schema="test" and table_name="t1"; +drop table t1; diff --git a/storage/heap/hp_block.c b/storage/heap/hp_block.c index 90efeeb7924..01978e2b4e8 100644 --- a/storage/heap/hp_block.c +++ b/storage/heap/hp_block.c @@ -64,18 +64,19 @@ int hp_get_new_block(HP_BLOCK *block, size_t *alloc_length) break; /* - Allocate space for leaf block plus space for upper level blocks up to - first level that has a free slot to put the pointer. - In some cases we actually allocate more then we need: - Consider e.g. a situation where we have one level 1 block and one level 0 - block, the level 0 block is full and this function is called. We only - need a leaf block in this case. Nevertheless, we will get here with i=1 - and will also allocate sizeof(HP_PTRS) for non-leaf block and will never - use this space. - This doesn't add much overhead - with current values of sizeof(HP_PTRS) - and my_default_record_cache_size we get about 1/128 unused memory. + Allocate space for leaf block (data) plus space for upper level blocks + up to first level that has a free slot to put the pointer. + If this is a new level, we have to allocate pointers to all future + lower levels. + + For example, for level 0, we allocate data for X rows. + When level 0 is full, we allocate data for HPTRS_IN_NODE + X rows. + Next time we allocate data for X rows. + When level 1 is full, we allocate data for HPTRS_IN_NODE at level 2 and 1 + + X rows at level 0. */ - *alloc_length=sizeof(HP_PTRS)*i+block->records_in_block* block->recbuffer; + *alloc_length= (sizeof(HP_PTRS)* ((i == block->levels) ? i : i - 1) + + block->records_in_block* block->recbuffer); if (!(root=(HP_PTRS*) my_malloc(*alloc_length,MYF(MY_WME)))) return 1; diff --git a/storage/heap/hp_create.c b/storage/heap/hp_create.c index 22ab9b54a85..d170d1abc65 100644 --- a/storage/heap/hp_create.c +++ b/storage/heap/hp_create.c @@ -245,21 +245,32 @@ static void init_block(HP_BLOCK *block, uint reclength, ulong min_records, { uint i,recbuffer,records_in_block; - max_records= max(min_records,max_records); + /* + If not min_records and max_records are given, optimize for 1000 rows + */ + if (!min_records) + min_records= min(1000, max_records); if (!max_records) - max_records= 1000; /* As good as quess as anything */ - recbuffer= (uint) (reclength + sizeof(uchar**) - 1) & ~(sizeof(uchar**) - 1); - records_in_block= max_records / 10; + max_records= max(min_records, 1000); /* We don't want too few records_in_block as otherwise the overhead of of the HP_PTRS block will be too notable */ - records_in_block= min(1000, max_records); + records_in_block= max(1000, min_records); + records_in_block= min(records_in_block, max_records); + /* If big max_records is given, allocate bigger blocks */ + records_in_block= max(records_in_block, max_records / 10); + /* We don't want too few blocks per row either */ if (records_in_block < 10) records_in_block= 10; - /* The + 1 is there to ensure that we get at least 1 row per level */ + recbuffer= (uint) (reclength + sizeof(uchar**) - 1) & ~(sizeof(uchar**) - 1); + /* + Don't allocate more than my_default_record_cache_size per level. + The + 1 is there to ensure that we get at least 1 row per level (for + the exceptional case of very long rows) + */ if (records_in_block*recbuffer > (my_default_record_cache_size-sizeof(HP_PTRS)*HP_MAX_LEVELS)) records_in_block= (my_default_record_cache_size - sizeof(HP_PTRS) * From 1aa6f042dab7a09dd86d96f934faa87df1c005c1 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Wed, 8 Aug 2012 18:04:57 +0300 Subject: [PATCH 2/5] Better test case for MDEV-436 --- mysql-test/suite/heap/heap.result | 32 +++++++++++++++++++++++++++++-- mysql-test/suite/heap/heap.test | 25 ++++++++++++++++++++++-- 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/mysql-test/suite/heap/heap.result b/mysql-test/suite/heap/heap.result index 29ebf504e1a..ae562a0dda1 100644 --- a/mysql-test/suite/heap/heap.result +++ b/mysql-test/suite/heap/heap.result @@ -756,9 +756,37 @@ select data_length,index_length from information_schema.tables where table_schem data_length index_length 48000 72000 drop table t1; -CREATE TABLE t1 (a int, index(a)) engine=heap max_rows=4000; +CREATE TABLE t1 (a int, index(a)) engine=heap max_rows=15000; insert into t1 values(1); select data_length,index_length from information_schema.tables where table_schema="test" and table_name="t1"; data_length index_length -16000 24000 +24000 36000 +drop table t1; +create table t1 (c1 int, index(c1)) engine=heap max_rows=10000; +insert into t1 select rand(100000000); +insert into t1 select rand(100000000) from t1; +insert into t1 select rand(100000000) from t1; +insert into t1 select rand(100000000) from t1; +insert into t1 select rand(100000000) from t1; +insert into t1 select rand(100000000) from t1; +insert into t1 select rand(100000000) from t1; +insert into t1 select rand(100000000) from t1; +insert into t1 select rand(100000000) from t1; +insert into t1 select rand(100000000) from t1; +insert into t1 select rand(100000000) from t1 limit 488; +select data_length,index_length from information_schema.tables where table_schema="test" and table_name="t1"; +data_length index_length +16000 24000 +insert into t1 select rand(100000000) from t1 limit 1; +select data_length,index_length from information_schema.tables where table_schema="test" and table_name="t1"; +data_length index_length +33024 49024 +insert into t1 select rand(100000000) from t1 limit 1000; +select data_length,index_length from information_schema.tables where table_schema="test" and table_name="t1"; +data_length index_length +49024 73024 +insert into t1 select rand(100000000) from t1; +select data_length,index_length from information_schema.tables where table_schema="test" and table_name="t1"; +data_length index_length +81024 121024 drop table t1; diff --git a/mysql-test/suite/heap/heap.test b/mysql-test/suite/heap/heap.test index 062b48f2c31..681d3b422e7 100644 --- a/mysql-test/suite/heap/heap.test +++ b/mysql-test/suite/heap/heap.test @@ -489,7 +489,7 @@ DROP TABLE t1; # # Show that MIN_ROWS and MAX_ROWS have an effect on how data_length # and index_length are allocated. -# This is different for 32 and 64 bit machines as pointer lengths are different +# Result is different for 32 / 64 bit machines as pointer lengths are different # CREATE TABLE t1 (a int, index(a)) engine=heap min_rows=10 max_rows=100; @@ -504,7 +504,28 @@ CREATE TABLE t1 (a int, index(a)) engine=heap min_rows=3000 max_rows=3000; insert into t1 values(1); select data_length,index_length from information_schema.tables where table_schema="test" and table_name="t1"; drop table t1; -CREATE TABLE t1 (a int, index(a)) engine=heap max_rows=4000; +CREATE TABLE t1 (a int, index(a)) engine=heap max_rows=15000; insert into t1 values(1); select data_length,index_length from information_schema.tables where table_schema="test" and table_name="t1"; drop table t1; + +create table t1 (c1 int, index(c1)) engine=heap max_rows=10000; +insert into t1 select rand(100000000); +insert into t1 select rand(100000000) from t1; +insert into t1 select rand(100000000) from t1; +insert into t1 select rand(100000000) from t1; +insert into t1 select rand(100000000) from t1; +insert into t1 select rand(100000000) from t1; +insert into t1 select rand(100000000) from t1; +insert into t1 select rand(100000000) from t1; +insert into t1 select rand(100000000) from t1; +insert into t1 select rand(100000000) from t1; +insert into t1 select rand(100000000) from t1 limit 488; +select data_length,index_length from information_schema.tables where table_schema="test" and table_name="t1"; +insert into t1 select rand(100000000) from t1 limit 1; +select data_length,index_length from information_schema.tables where table_schema="test" and table_name="t1"; +insert into t1 select rand(100000000) from t1 limit 1000; +select data_length,index_length from information_schema.tables where table_schema="test" and table_name="t1"; +insert into t1 select rand(100000000) from t1; +select data_length,index_length from information_schema.tables where table_schema="test" and table_name="t1"; +drop table t1; From cee888acb36141136cdb121a7bb7d53200b14cb6 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Mon, 13 Aug 2012 22:23:28 +0300 Subject: [PATCH 3/5] Fixed compiler warnings (A few of these was bugs) client/mysqldump.c: Slave needs to be initialized with 0 dbug/dbug.c: Removed not existing function plugin/semisync/semisync_master.cc: Fixed compiler warning sql/opt_range.cc: thd needs to be set early as it's used in some error conditions. sql/sql_table.cc: Changed to use uchar* to make array indexing portable storage/innobase/handler/ha_innodb.cc: Removed not used variable storage/maria/ma_delete.c: Fixed compiler warning storage/maria/ma_write.c: Fixed compiler warning --- client/mysqldump.c | 2 +- dbug/dbug.c | 3 --- plugin/semisync/semisync_master.cc | 3 ++- sql/opt_range.cc | 3 +-- sql/sql_table.cc | 9 +++++---- storage/innobase/handler/ha_innodb.cc | 2 +- storage/maria/ma_delete.c | 2 ++ storage/maria/ma_write.c | 2 ++ 8 files changed, 14 insertions(+), 12 deletions(-) diff --git a/client/mysqldump.c b/client/mysqldump.c index 3adbc897c50..32ac3a1ac59 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -4784,7 +4784,7 @@ static int add_slave_statements(void) static int do_show_slave_status(MYSQL *mysql_con) { - MYSQL_RES *slave; + MYSQL_RES *slave= 0; const char *comment_prefix= (opt_slave_data == MYSQL_OPT_SLAVE_DATA_COMMENTED_SQL) ? "-- " : ""; if (mysql_query_with_error_report(mysql_con, &slave, "SHOW SLAVE STATUS")) diff --git a/dbug/dbug.c b/dbug/dbug.c index af0a937ff07..b285b32fa17 100644 --- a/dbug/dbug.c +++ b/dbug/dbug.c @@ -284,9 +284,6 @@ static int DoTrace(CODE_STATE *cs); /* Test to see if file is writable */ #if defined(HAVE_ACCESS) static BOOLEAN Writable(const char *pathname); - /* Change file owner and group */ -static void ChangeOwner(CODE_STATE *cs, char *pathname); - /* Allocate memory for runtime support */ #endif static void DoPrefix(CODE_STATE *cs, uint line); diff --git a/plugin/semisync/semisync_master.cc b/plugin/semisync/semisync_master.cc index 8573c4dcbde..d1b982468d2 100644 --- a/plugin/semisync/semisync_master.cc +++ b/plugin/semisync/semisync_master.cc @@ -1049,10 +1049,11 @@ int ReplSemiSyncMaster::readSlaveReply(NET *net, uint32 server_id, ulong log_file_len = 0; ulong packet_len; int result = -1; - struct timespec start_ts; ulong trc_level = trace_level_; + LINT_INIT_STRUCT(start_ts); + function_enter(kWho); assert((unsigned char)event_buf[1] == kPacketMagicNum); diff --git a/sql/opt_range.cc b/sql/opt_range.cc index da328063e56..add46d148cf 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -2001,7 +2001,7 @@ int QUICK_RANGE_SELECT::init_ror_merged_scan(bool reuse_handler) { handler *save_file= file, *org_file; my_bool org_key_read; - THD *thd; + THD *thd= head->in_use; DBUG_ENTER("QUICK_RANGE_SELECT::init_ror_merged_scan"); in_ror_merged_scan= 1; @@ -2023,7 +2023,6 @@ int QUICK_RANGE_SELECT::init_ror_merged_scan(bool reuse_handler) DBUG_RETURN(0); } - thd= head->in_use; if (!(file= head->file->clone(head->s->normalized_path.str, thd->mem_root))) { /* diff --git a/sql/sql_table.cc b/sql/sql_table.cc index eb4ded0c502..77735853c68 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -1960,8 +1960,9 @@ bool mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists, static uint32 comment_length(THD *thd, uint32 comment_pos, const char **comment_start) { - const char *query= thd->query(); - const char *query_end= query + thd->query_length(); + /* We use uchar * here to make array indexing portable */ + const uchar *query= (uchar*) thd->query(); + const uchar *query_end= (uchar*) query + thd->query_length(); const uchar *const state_map= thd->charset()->state_map; for (; query < query_end; query++) @@ -1975,12 +1976,12 @@ static uint32 comment_length(THD *thd, uint32 comment_pos, state_map[*query] != MY_LEX_LONG_COMMENT || query[1] != '*') return 0; - *comment_start= query; + *comment_start= (char*) query; for (query+= 3; query < query_end; query++) { if (query[-1] == '*' && query[0] == '/') - return query - *comment_start + 1; + return (char*) query - *comment_start + 1; } return 0; } diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 32295c5314f..0ef6f0209f7 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -11703,7 +11703,7 @@ static MYSQL_SYSVAR_ULONG(read_ahead_threshold, srv_read_ahead_threshold, "trigger a readahead.", NULL, NULL, 56, 0, 64, 0); -#ifdef UNIV_DEBUG +#ifdef UNIV_DEBUG_never static MYSQL_SYSVAR_UINT(trx_rseg_n_slots_debug, trx_rseg_n_slots_debug, PLUGIN_VAR_RQCMDARG, "Debug flags for InnoDB to limit TRX_RSEG_N_SLOTS for trx_rsegf_undo_find_free()", diff --git a/storage/maria/ma_delete.c b/storage/maria/ma_delete.c index 069d73b553c..5b8d0e01677 100644 --- a/storage/maria/ma_delete.c +++ b/storage/maria/ma_delete.c @@ -163,6 +163,8 @@ my_bool _ma_ck_delete(MARIA_HA *info, MARIA_KEY *key) MARIA_KEY org_key; DBUG_ENTER("_ma_ck_delete"); + LINT_INIT_STRUCT(org_key); + save_key_data= key->data; if (share->now_transactional) { diff --git a/storage/maria/ma_write.c b/storage/maria/ma_write.c index 74c1a106df2..f1649083105 100644 --- a/storage/maria/ma_write.c +++ b/storage/maria/ma_write.c @@ -478,6 +478,8 @@ static my_bool _ma_ck_write_btree_with_log(MARIA_HA *info, MARIA_KEY *key, my_bool transactional= share->now_transactional; DBUG_ENTER("_ma_ck_write_btree_with_log"); + LINT_INIT_STRUCT(org_key); + if (transactional) { /* Save original value as the key may change */ From b886cac7123bc37d055fecd49d9a30ce0c39da73 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Tue, 14 Aug 2012 19:59:28 +0300 Subject: [PATCH 4/5] Fixed compiler errors Updated test to also work on 32 bit mysql-test/suite/heap/heap.test: Updated test to also work on 32 bit --- mysql-test/suite/heap/heap.test | 8 ++++++++ sql/create_options.cc | 5 ++++- sql/ha_partition.cc | 2 +- sql/item_subselect.cc | 21 +++++++++++++++------ sql/multi_range_read.cc | 2 +- sql/sql_parse.cc | 2 +- sql/sql_select.cc | 3 ++- storage/innobase/log/log0recv.c | 2 +- storage/maria/ha_maria.cc | 2 +- storage/maria/ma_blockrec.c | 2 ++ storage/maria/ma_ft_nlq_search.c | 2 ++ storage/maria/ma_key_recover.c | 7 ++++++- storage/maria/ma_pagecache.c | 1 + storage/maria/ma_search.c | 4 ++++ storage/myisam/ft_nlq_search.c | 1 + storage/xtradb/handler/ha_innodb.cc | 12 ++++++------ storage/xtradb/log/log0recv.c | 2 +- strings/ctype-ucs2.c | 9 +++++++-- 18 files changed, 64 insertions(+), 23 deletions(-) diff --git a/mysql-test/suite/heap/heap.test b/mysql-test/suite/heap/heap.test index 681d3b422e7..6f5046af139 100644 --- a/mysql-test/suite/heap/heap.test +++ b/mysql-test/suite/heap/heap.test @@ -494,18 +494,22 @@ DROP TABLE t1; CREATE TABLE t1 (a int, index(a)) engine=heap min_rows=10 max_rows=100; insert into t1 values(1); +--replace_result 800 1600 1200 2400 select data_length,index_length from information_schema.tables where table_schema="test" and table_name="t1"; drop table t1; CREATE TABLE t1 (a int, index(a)) engine=heap min_rows=10 max_rows=10000; insert into t1 values(1); +--replace_result 8000 16000 12000 24000 select data_length,index_length from information_schema.tables where table_schema="test" and table_name="t1"; drop table t1; CREATE TABLE t1 (a int, index(a)) engine=heap min_rows=3000 max_rows=3000; insert into t1 values(1); +--replace_result 24000 48000 36000 72000 select data_length,index_length from information_schema.tables where table_schema="test" and table_name="t1"; drop table t1; CREATE TABLE t1 (a int, index(a)) engine=heap max_rows=15000; insert into t1 values(1); +--replace_result 12000 24000 18000 36000 select data_length,index_length from information_schema.tables where table_schema="test" and table_name="t1"; drop table t1; @@ -521,11 +525,15 @@ insert into t1 select rand(100000000) from t1; insert into t1 select rand(100000000) from t1; insert into t1 select rand(100000000) from t1; insert into t1 select rand(100000000) from t1 limit 488; +--replace_result 8000 16000 12000 24000 select data_length,index_length from information_schema.tables where table_schema="test" and table_name="t1"; insert into t1 select rand(100000000) from t1 limit 1; +--replace_result 16512 33024 24512 49024 select data_length,index_length from information_schema.tables where table_schema="test" and table_name="t1"; insert into t1 select rand(100000000) from t1 limit 1000; +--replace_result 24512 49024 36512 73024 select data_length,index_length from information_schema.tables where table_schema="test" and table_name="t1"; insert into t1 select rand(100000000) from t1; +--replace_result 40512 81024 60512 121024 select data_length,index_length from information_schema.tables where table_schema="test" and table_name="t1"; drop table t1; diff --git a/sql/create_options.cc b/sql/create_options.cc index 9a6f6b5cf7c..e4881388688 100644 --- a/sql/create_options.cc +++ b/sql/create_options.cc @@ -137,7 +137,10 @@ static bool set_one_value(ha_create_table_option *opt, my_option optp= { opt->name, 1, 0, (uchar **)val, 0, 0, GET_ULL, - REQUIRED_ARG, opt->def_value, opt->min_value, opt->max_value, + REQUIRED_ARG, + (longlong) opt->def_value, + (longlong) opt->min_value, + opt->max_value, 0, (long) opt->block_size, 0}; ulonglong orig_val= strtoull(value->str, NULL, 10); diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index 0d2b4387327..b3f97d35033 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -3837,7 +3837,7 @@ int ha_partition::truncate_partition(Alter_info *alter_info, bool *binlog_stmt) { List_iterator subpart_it(part_elem->subpartitions); - partition_element *sub_elem; + partition_element *sub_elem __attribute__((unused)); uint j= 0, part; do { diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index 49d232d31be..8b9904ea260 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -5167,10 +5167,16 @@ Ordered_key::cmp_keys_by_row_data(ha_rows a, ha_rows b) rowid_a= row_num_to_rowid + a * rowid_length; rowid_b= row_num_to_rowid + b * rowid_length; /* Fetch the rows for comparison. */ - error= tbl->file->ha_rnd_pos(tbl->record[0], rowid_a); - DBUG_ASSERT(!error); - error= tbl->file->ha_rnd_pos(tbl->record[1], rowid_b); - DBUG_ASSERT(!error); + if ((error= tbl->file->ha_rnd_pos(tbl->record[0], rowid_a))) + { + tbl->file->print_error(error, MYF(ME_FATALERROR)); // Sets fatal_error + return 0; + } + if ((error= tbl->file->ha_rnd_pos(tbl->record[1], rowid_b))) + { + tbl->file->print_error(error, MYF(ME_FATALERROR)); // Sets fatal_error + return 0; + } /* Compare the two rows by the corresponding values of the indexed columns. @@ -5245,8 +5251,11 @@ int Ordered_key::cmp_key_with_search_key(rownum_t row_num) uchar *cur_rowid= row_num_to_rowid + row_num * rowid_length; int error, cmp_res; - error= tbl->file->ha_rnd_pos(tbl->record[0], cur_rowid); - DBUG_ASSERT(!error); + if ((error= tbl->file->ha_rnd_pos(tbl->record[0], cur_rowid))) + { + tbl->file->print_error(error, MYF(ME_FATALERROR)); // Sets fatal_error + return 0; + } for (uint i= 0; i < key_column_count; i++) { diff --git a/sql/multi_range_read.cc b/sql/multi_range_read.cc index 7268491c0f4..800602fe9e1 100644 --- a/sql/multi_range_read.cc +++ b/sql/multi_range_read.cc @@ -1404,7 +1404,7 @@ ha_rows DsMrr_impl::dsmrr_info(uint keyno, uint n_ranges, uint rows, uint key_parts, uint *bufsz, uint *flags, COST_VECT *cost) { - ha_rows res; + ha_rows res __attribute__((unused)); uint def_flags= *flags; uint def_bufsz= *bufsz; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 49014db9505..6f157c89ee2 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1325,7 +1325,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, { STATUS_VAR *current_global_status_var; // Big; Don't allocate on stack ulong uptime; - uint length; + uint length __attribute__((unused)); ulonglong queries_per_second1000; char buff[250]; uint buff_len= sizeof(buff); diff --git a/sql/sql_select.cc b/sql/sql_select.cc index da43b4b5e30..165e257d42d 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -6408,7 +6408,8 @@ greedy_search(JOIN *join, uint size_remain; // cardinality of remaining_tables POSITION best_pos; JOIN_TAB *best_table; // the next plan node to be added to the curr QEP - uint n_tables; // ==join->tables or # tables in the sj-mat nest we're optimizing + // ==join->tables or # tables in the sj-mat nest we're optimizing + uint n_tables __attribute__((unused)); DBUG_ENTER("greedy_search"); diff --git a/storage/innobase/log/log0recv.c b/storage/innobase/log/log0recv.c index f9e0fecb6c6..6c55a1badc5 100644 --- a/storage/innobase/log/log0recv.c +++ b/storage/innobase/log/log0recv.c @@ -2900,7 +2900,7 @@ recv_recovery_from_checkpoint_start_func( ib_uint64_t checkpoint_lsn; ib_uint64_t checkpoint_no; ib_uint64_t old_scanned_lsn; - ib_uint64_t group_scanned_lsn; + ib_uint64_t group_scanned_lsn= 0; ib_uint64_t contiguous_lsn; #ifdef UNIV_LOG_ARCHIVE ib_uint64_t archived_lsn; diff --git a/storage/maria/ha_maria.cc b/storage/maria/ha_maria.cc index e763b7e7a37..785fe5d8226 100644 --- a/storage/maria/ha_maria.cc +++ b/storage/maria/ha_maria.cc @@ -235,7 +235,7 @@ static MYSQL_SYSVAR_ULONG(pagecache_age_threshold, "until it is considered aged enough to be downgraded to a warm block. " "This specifies the percentage ratio of that number of hits to the " "total number of blocks in the page cache.", 0, 0, - 300, 100, ~0L, 100); + 300, 100, ~ (ulong) 0L, 100); static MYSQL_SYSVAR_ULONGLONG(pagecache_buffer_size, pagecache_buffer_size, PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY, diff --git a/storage/maria/ma_blockrec.c b/storage/maria/ma_blockrec.c index 02cb01b581c..8e0407c9d7a 100644 --- a/storage/maria/ma_blockrec.c +++ b/storage/maria/ma_blockrec.c @@ -4677,6 +4677,8 @@ int _ma_read_block_record2(MARIA_HA *info, uchar *record, MARIA_ROW *cur_row= &info->cur_row; DBUG_ENTER("_ma_read_block_record2"); + LINT_INIT(blob_buffer); + start_of_data= data; flag= (uint) (uchar) data[0]; cur_null_bytes= share->base.original_null_bytes; diff --git a/storage/maria/ma_ft_nlq_search.c b/storage/maria/ma_ft_nlq_search.c index e57cc135ca1..5c1ab85ef8a 100644 --- a/storage/maria/ma_ft_nlq_search.c +++ b/storage/maria/ma_ft_nlq_search.c @@ -83,6 +83,8 @@ static int walk_and_match(FT_WORD *word, uint32 count, ALL_IN_ONE *aio) #endif DBUG_ENTER("walk_and_match"); + LINT_INIT_STRUCT(subkeys); + word->weight=LWS_FOR_QUERY; _ma_ft_make_key(info, &key, aio->keynr, keybuff, word, 0); diff --git a/storage/maria/ma_key_recover.c b/storage/maria/ma_key_recover.c index 9ff2d954a60..502ac2b8809 100644 --- a/storage/maria/ma_key_recover.c +++ b/storage/maria/ma_key_recover.c @@ -945,7 +945,10 @@ uint _ma_apply_redo_index(MARIA_HA *info, const uchar *header_end= header + head_length; uint page_offset= 0, org_page_length; uint page_length, keypage_header, keynr; - uint max_page_size= share->max_index_block_size, new_page_length= 0; + uint max_page_size= share->max_index_block_size; +#ifndef DBUG_OFF + uint new_page_length= 0; +#endif int result; MARIA_PAGE page; DBUG_ENTER("_ma_apply_redo_index"); @@ -1107,7 +1110,9 @@ uint _ma_apply_redo_index(MARIA_HA *info, DBUG_PRINT("redo", ("org_page_length: %u new_page_length: %u", uint2korr(header), uint2korr(header+2))); DBUG_ASSERT(uint2korr(header) == page_length); +#ifndef DBUG_OFF new_page_length= min(uint2korr(header+2), max_page_size); +#endif header+= 4; break; case KEY_OP_MAX_PAGELENGTH: diff --git a/storage/maria/ma_pagecache.c b/storage/maria/ma_pagecache.c index 2618d6a5b50..6aaccea219f 100644 --- a/storage/maria/ma_pagecache.c +++ b/storage/maria/ma_pagecache.c @@ -3372,6 +3372,7 @@ restart: PAGECACHE_BLOCK_LINK *block; uint status; int page_st; + LINT_INIT(page_st); pagecache_pthread_mutex_lock(&pagecache->cache_lock); if (!pagecache->can_be_used) diff --git a/storage/maria/ma_search.c b/storage/maria/ma_search.c index 3b774fb4283..ccb4bf77717 100644 --- a/storage/maria/ma_search.c +++ b/storage/maria/ma_search.c @@ -439,6 +439,10 @@ int _ma_prefix_search(const MARIA_KEY *key, const MARIA_PAGE *ma_page, const uchar *sort_order= keyinfo->seg->charset->sort_order; DBUG_ENTER("_ma_prefix_search"); + LINT_INIT(seg_len_pack); + LINT_INIT(prefix_len); + LINT_INIT(length); + t_buff[0]=0; /* Avoid bugs */ page_flag= ma_page->flag; nod_flag= ma_page->node; diff --git a/storage/myisam/ft_nlq_search.c b/storage/myisam/ft_nlq_search.c index 5a9468fe007..bafa7064e28 100644 --- a/storage/myisam/ft_nlq_search.c +++ b/storage/myisam/ft_nlq_search.c @@ -81,6 +81,7 @@ static int walk_and_match(FT_WORD *word, uint32 count, ALL_IN_ONE *aio) #error #endif DBUG_ENTER("walk_and_match"); + LINT_INIT_STRUCT(subkeys); word->weight=LWS_FOR_QUERY; diff --git a/storage/xtradb/handler/ha_innodb.cc b/storage/xtradb/handler/ha_innodb.cc index 90f7b990d23..f9068772b0c 100644 --- a/storage/xtradb/handler/ha_innodb.cc +++ b/storage/xtradb/handler/ha_innodb.cc @@ -12387,7 +12387,7 @@ static MYSQL_SYSVAR_BOOL(doublewrite, innobase_use_doublewrite, static MYSQL_SYSVAR_ULONG(io_capacity, srv_io_capacity, PLUGIN_VAR_RQCMDARG, "Number of IOPs the server can do. Tunes the background IO rate", - NULL, NULL, 200, 100, ~0L, 0); + NULL, NULL, 200, 100, ~ (ulong) 0L, 0); static MYSQL_SYSVAR_ULONG(purge_batch_size, srv_purge_batch_size, PLUGIN_VAR_OPCMDARG, @@ -12520,7 +12520,7 @@ static MYSQL_SYSVAR_BOOL(adaptive_flushing, srv_adaptive_flushing, static MYSQL_SYSVAR_ULONG(max_purge_lag, srv_max_purge_lag, PLUGIN_VAR_RQCMDARG, "Desired maximum length of the purge queue (0 = no limit)", - NULL, NULL, 0, 0, ~0L, 0); + NULL, NULL, 0, 0, ~(ulong) 0L, 0); static MYSQL_SYSVAR_BOOL(rollback_on_timeout, innobase_rollback_on_timeout, PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_READONLY, @@ -12624,7 +12624,7 @@ static MYSQL_SYSVAR_ULONG(commit_concurrency, innobase_commit_concurrency, static MYSQL_SYSVAR_ULONG(concurrency_tickets, srv_n_free_tickets_to_enter, PLUGIN_VAR_RQCMDARG, "Number of times a thread is allowed to enter InnoDB within the same SQL query after it has once got the ticket", - NULL, NULL, 500L, 1L, ~0L, 0); + NULL, NULL, 500L, 1L, ~(ulong) 0L, 0); #ifdef EXTENDED_FOR_KILLIDLE #define kill_idle_help_text "If non-zero value, the idle session with transaction which is idle over the value in seconds is killed by InnoDB." @@ -12694,12 +12694,12 @@ static MYSQL_SYSVAR_LONG(open_files, innobase_open_files, static MYSQL_SYSVAR_ULONG(sync_spin_loops, srv_n_spin_wait_rounds, PLUGIN_VAR_RQCMDARG, "Count of spin-loop rounds in InnoDB mutexes (30 by default)", - NULL, NULL, 30L, 0L, ~0L, 0); + NULL, NULL, 30L, 0L, ~ (ulong) 0L, 0); static MYSQL_SYSVAR_ULONG(spin_wait_delay, srv_spin_wait_delay, PLUGIN_VAR_OPCMDARG, "Maximum delay between polling for a spin lock (6 by default)", - NULL, NULL, 6L, 0L, ~0L, 0); + NULL, NULL, 6L, 0L, ~ (ulong) 0L, 0); static MYSQL_SYSVAR_BOOL(thread_concurrency_timer_based, innobase_thread_concurrency_timer_based, @@ -12715,7 +12715,7 @@ static MYSQL_SYSVAR_ULONG(thread_concurrency, srv_thread_concurrency, static MYSQL_SYSVAR_ULONG(thread_sleep_delay, srv_thread_sleep_delay, PLUGIN_VAR_RQCMDARG, "Time of innodb thread sleeping before joining InnoDB queue (usec). Value 0 disable a sleep", - NULL, NULL, 10000L, 0L, ~0L, 0); + NULL, NULL, 10000L, 0L, ~ (ulong) 0L, 0); static MYSQL_SYSVAR_STR(data_file_path, innobase_data_file_path, PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY, diff --git a/storage/xtradb/log/log0recv.c b/storage/xtradb/log/log0recv.c index c4429af5112..a554c576b6d 100644 --- a/storage/xtradb/log/log0recv.c +++ b/storage/xtradb/log/log0recv.c @@ -2980,7 +2980,7 @@ recv_recovery_from_checkpoint_start_func( ib_uint64_t checkpoint_lsn; ib_uint64_t checkpoint_no; ib_uint64_t old_scanned_lsn; - ib_uint64_t group_scanned_lsn; + ib_uint64_t group_scanned_lsn= 0; ib_uint64_t contiguous_lsn; #ifdef UNIV_LOG_ARCHIVE ib_uint64_t archived_lsn; diff --git a/strings/ctype-ucs2.c b/strings/ctype-ucs2.c index 83ea3739f4c..52eaece5528 100644 --- a/strings/ctype-ucs2.c +++ b/strings/ctype-ucs2.c @@ -2317,13 +2317,18 @@ void my_fill_utf32(CHARSET_INFO *cs, char *s, size_t slen, int fill) { char buf[10]; +#ifndef DBUG_OFF uint buflen; +#endif char *e= s + slen; DBUG_ASSERT((slen % 4) == 0); - buflen= cs->cset->wc_mb(cs, (my_wc_t) fill, (uchar*) buf, - (uchar*) buf + sizeof(buf)); +#ifndef DBUG_OFF + buflen= +#endif + cs->cset->wc_mb(cs, (my_wc_t) fill, (uchar*) buf, + (uchar*) buf + sizeof(buf)); DBUG_ASSERT(buflen == 4); while (s < e) { From dd8bd2e4c38a3e052b48ba8704e8a7aa89affd74 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Wed, 15 Aug 2012 09:34:18 +0300 Subject: [PATCH 5/5] Fixed compiler warnings sql/item_subselect.cc: Added purecov info sql/sql_select.cc: Added cast storage/innobase/handler/ha_innodb.cc: Added cast storage/xtradb/btr/btr0btr.c: Added buf_block_get_frame_fast() to avoid compiler warning storage/xtradb/handler/ha_innodb.cc: Added cast storage/xtradb/include/buf0buf.h: Innodb has buf_block_get_frame(block) defined as (block)->frame. Didn't want to do a big change to break xtradb as it may use block_get_frame() differently, so I mad this quick hack to patch one compiler warning. --- configure.cmake | 4 ++-- sql/item_subselect.cc | 6 ++++++ sql/sql_select.cc | 2 +- storage/innobase/handler/ha_innodb.cc | 7 ++++--- storage/xtradb/btr/btr0btr.c | 2 +- storage/xtradb/handler/ha_innodb.cc | 7 ++++--- storage/xtradb/include/buf0buf.h | 2 ++ 7 files changed, 20 insertions(+), 10 deletions(-) diff --git a/configure.cmake b/configure.cmake index 1fb5fc920f6..05fa80e852f 100644 --- a/configure.cmake +++ b/configure.cmake @@ -56,10 +56,10 @@ ENDIF() # Always enable -Wall for gnu C/C++ IF(CMAKE_COMPILER_IS_GNUCXX) - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-unused-parameter") + SET(CMAKE_CXX_FLAGS "-Wall ${CMAKE_CXX_FLAGS} -Wno-unused-parameter") ENDIF() IF(CMAKE_COMPILER_IS_GNUCC) - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") + SET(CMAKE_C_FLAGS "-Wall ${CMAKE_C_FLAGS}") ENDIF() diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index 8b9904ea260..cedc4ccb834 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -5169,13 +5169,17 @@ Ordered_key::cmp_keys_by_row_data(ha_rows a, ha_rows b) /* Fetch the rows for comparison. */ if ((error= tbl->file->ha_rnd_pos(tbl->record[0], rowid_a))) { + /* purecov: begin inspected */ tbl->file->print_error(error, MYF(ME_FATALERROR)); // Sets fatal_error return 0; + /* purecov: end */ } if ((error= tbl->file->ha_rnd_pos(tbl->record[1], rowid_b))) { + /* purecov: begin inspected */ tbl->file->print_error(error, MYF(ME_FATALERROR)); // Sets fatal_error return 0; + /* purecov: end */ } /* Compare the two rows by the corresponding values of the indexed @@ -5253,8 +5257,10 @@ int Ordered_key::cmp_key_with_search_key(rownum_t row_num) if ((error= tbl->file->ha_rnd_pos(tbl->record[0], cur_rowid))) { + /* purecov: begin inspected */ tbl->file->print_error(error, MYF(ME_FATALERROR)); // Sets fatal_error return 0; + /* purecov: end */ } for (uint i= 0; i < key_column_count; i++) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 165e257d42d..720b4e418d7 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -6657,7 +6657,7 @@ double JOIN::get_examined_rows() while ((tab= next_breadth_first_tab(this, tab))) { prev_fanout *= prev_tab->records_read; - examined_rows+= tab->get_examined_rows() * prev_fanout; + examined_rows+= (ha_rows) (tab->get_examined_rows() * prev_fanout); prev_tab= tab; } return examined_rows; diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index a39aef0794a..474c157fbc7 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -8418,9 +8418,10 @@ ha_innobase::info_low( } else if (rec_per_key > 1) { rec_per_key = - k_rec_per_key * - (double)rec_per_key / - n_rows; + (ha_rows) + (k_rec_per_key * + (double)rec_per_key / + n_rows); } key_info->rec_per_key[k++]= diff --git a/storage/xtradb/btr/btr0btr.c b/storage/xtradb/btr/btr0btr.c index 1fa6df44f7c..d4a0ef5ec60 100644 --- a/storage/xtradb/btr/btr0btr.c +++ b/storage/xtradb/btr/btr0btr.c @@ -61,7 +61,7 @@ btr_corruption_report( buf_block_get_zip_size(block), BUF_PAGE_PRINT_NO_CRASH); } - buf_page_print(buf_block_get_frame(block), 0, 0); + buf_page_print(buf_block_get_frame_fast(block), 0, 0); } #ifdef UNIV_BLOB_DEBUG diff --git a/storage/xtradb/handler/ha_innodb.cc b/storage/xtradb/handler/ha_innodb.cc index f9068772b0c..8aed19aad3e 100644 --- a/storage/xtradb/handler/ha_innodb.cc +++ b/storage/xtradb/handler/ha_innodb.cc @@ -9281,9 +9281,10 @@ ha_innobase::info_low( } else if (rec_per_key > 1) { rec_per_key = - k_rec_per_key * - (double)rec_per_key / - n_rows; + (ha_rows) + (k_rec_per_key * + (double)rec_per_key / + n_rows); } key_info->rec_per_key[k++]= diff --git a/storage/xtradb/include/buf0buf.h b/storage/xtradb/include/buf0buf.h index 7502942d681..5f8220de18d 100644 --- a/storage/xtradb/include/buf0buf.h +++ b/storage/xtradb/include/buf0buf.h @@ -1063,8 +1063,10 @@ buf_block_get_frame( /*================*/ const buf_block_t* block) /*!< in: pointer to the control block */ __attribute__((pure)); +# define buf_block_get_frame_fast(block) buf_block_get_frame(block) #else /* UNIV_DEBUG */ # define buf_block_get_frame(block) (block ? (block)->frame : 0) +# define buf_block_get_frame_fast(block) (block)->frame #endif /* UNIV_DEBUG */ /*********************************************************************//** Gets the space id of a block.