From b30446c85dbf0fd402a7833e1042bc13be7fece2 Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Wed, 11 Mar 2020 13:46:57 +0300 Subject: [PATCH 1/4] Fix compile warning: It was: implicit conversion from 'ha_rows' (aka 'unsigned long long') to 'double' changes value from 18446744073709551615 to 18446744073709551616 Follow what JOIN::get_examined_rows() does for similar code. --- sql/sql_select.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 2358615affc..647dee80188 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -4267,7 +4267,7 @@ make_join_statistics(JOIN *join, List &tables_list, for (i= 0; i < join->table_count ; i++) if (double rr= join->best_positions[i].records_read) records= COST_MULT(records, rr); - ha_rows rows= records > HA_ROWS_MAX ? HA_ROWS_MAX : (ha_rows) records; + ha_rows rows= records > (double) HA_ROWS_MAX ? HA_ROWS_MAX : (ha_rows) records; set_if_smaller(rows, unit->select_limit_cnt); join->select_lex->increase_derived_records(rows); } From 3ab33c6c929ca615e73465f638a96bdec74adfcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Wed, 11 Mar 2020 14:27:16 +0200 Subject: [PATCH 2/4] Cleanup: clang-10 -Wmisleading-indentation Also, remove some trailing white space and add missing static qualifier to free_annotate_event(). --- client/mysqlbinlog.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc index 979b82463b0..a88c93516b5 100644 --- a/client/mysqlbinlog.cc +++ b/client/mysqlbinlog.cc @@ -1,6 +1,6 @@ /* Copyright (c) 2000, 2014, Oracle and/or its affiliates. - Copyright (c) 2009, 2014, MariaDB + Copyright (c) 2009, 2020, MariaDB This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -151,7 +151,7 @@ enum Exit_status { */ static Annotate_rows_log_event *annotate_event= NULL; -void free_annotate_event() +static void free_annotate_event() { if (annotate_event) { @@ -854,7 +854,7 @@ static bool print_row_event(PRINT_EVENT_INFO *print_event_info, Log_event *ev, print_event_info->m_table_map_ignored.get_table(table_id); bool skip_event= (ignored_map != NULL); - /* + /* end of statement check: i) destroy/free ignored maps ii) if skip event @@ -865,21 +865,21 @@ static bool print_row_event(PRINT_EVENT_INFO *print_event_info, Log_event *ev, */ if (is_stmt_end) { - /* + /* Now is safe to clear ignored map (clear_tables will also delete original table map events stored in the map). */ if (print_event_info->m_table_map_ignored.count() > 0) print_event_info->m_table_map_ignored.clear_tables(); - /* + /* If there is a kept Annotate event and all corresponding rbr-events were filtered away, the Annotate event was not freed and it is just the time to do it. */ - free_annotate_event(); + free_annotate_event(); - /* + /* One needs to take into account an event that gets filtered but was last event in the statement. If this is the case, previous rows events that were written into From df88e7cefaa7dcffdc52359b73a1087e8569e000 Mon Sep 17 00:00:00 2001 From: Eugene Kosov Date: Wed, 11 Mar 2020 16:27:37 +0300 Subject: [PATCH 3/4] fix typedef-related warning and cleanup using namespace std --- storage/innobase/btr/btr0defragment.cc | 3 +++ storage/innobase/include/buf0buf.h | 4 ++-- storage/innobase/include/page0types.h | 4 +--- storage/innobase/page/page0zip.cc | 3 --- storage/innobase/row/row0mysql.cc | 2 +- storage/xtradb/include/buf0buf.h | 4 ++-- 6 files changed, 9 insertions(+), 11 deletions(-) diff --git a/storage/innobase/btr/btr0defragment.cc b/storage/innobase/btr/btr0defragment.cc index 070f6a9cc0a..f679f22dfe4 100644 --- a/storage/innobase/btr/btr0defragment.cc +++ b/storage/innobase/btr/btr0defragment.cc @@ -38,6 +38,9 @@ Modified 30/07/2014 Jan Lindström jan.lindstrom@mariadb.com #include +using std::list; +using std::min; + /* When there's no work, either because defragment is disabled, or because no query is submitted, thread checks state every BTR_DEFRAGMENT_SLEEP_IN_USECS.*/ #define BTR_DEFRAGMENT_SLEEP_IN_USECS 1000000 diff --git a/storage/innobase/include/buf0buf.h b/storage/innobase/include/buf0buf.h index bcb2252e7dc..b6ad0b85b19 100644 --- a/storage/innobase/include/buf0buf.h +++ b/storage/innobase/include/buf0buf.h @@ -1504,7 +1504,7 @@ buf_page_encrypt_before_write( NOTE! The definition appears here only for other modules of this directory (buf) to see it. Do not use from outside! */ -typedef struct { +struct buf_tmp_buffer_t { private: int32 reserved; /*!< true if this slot is reserved */ @@ -1534,7 +1534,7 @@ public: return !my_atomic_fas32_explicit(&reserved, true, MY_MEMORY_ORDER_RELAXED); } -} buf_tmp_buffer_t; +}; /** The common buffer control block structure for compressed and uncompressed frames */ diff --git a/storage/innobase/include/page0types.h b/storage/innobase/include/page0types.h index cba2d7a7a8b..3f7a653f8f8 100644 --- a/storage/innobase/include/page0types.h +++ b/storage/innobase/include/page0types.h @@ -26,8 +26,6 @@ Created 2/2/1994 Heikki Tuuri #ifndef page0types_h #define page0types_h -using namespace std; - #include #include "univ.i" @@ -110,7 +108,7 @@ struct page_zip_stat_t { }; /** Compression statistics types */ -typedef map page_zip_stat_per_index_t; +typedef std::map page_zip_stat_per_index_t; /** Statistics on compression, indexed by page_zip_des_t::ssize - 1 */ extern page_zip_stat_t page_zip_stat[PAGE_ZIP_SSIZE_MAX]; diff --git a/storage/innobase/page/page0zip.cc b/storage/innobase/page/page0zip.cc index 233ccaa6a90..1b0fcea326a 100644 --- a/storage/innobase/page/page0zip.cc +++ b/storage/innobase/page/page0zip.cc @@ -28,9 +28,6 @@ Created June 2005 by Marko Makela // First include (the generated) my_config.h, to get correct platform defines. #include "my_config.h" -#include -using namespace std; - #define THIS_MODULE #include "page0zip.h" #ifdef UNIV_NONINL diff --git a/storage/innobase/row/row0mysql.cc b/storage/innobase/row/row0mysql.cc index 55befe42b13..7df9629294a 100644 --- a/storage/innobase/row/row0mysql.cc +++ b/storage/innobase/row/row0mysql.cc @@ -807,7 +807,7 @@ row_create_prebuilt( temp_index->fields[i].fixed_len; } } - srch_key_len = max(srch_key_len,temp_len); + srch_key_len = std::max(srch_key_len,temp_len); } ut_a(srch_key_len <= MAX_SRCH_KEY_VAL_BUFFER); diff --git a/storage/xtradb/include/buf0buf.h b/storage/xtradb/include/buf0buf.h index e8a82f2e3e4..39fceeef384 100644 --- a/storage/xtradb/include/buf0buf.h +++ b/storage/xtradb/include/buf0buf.h @@ -1528,7 +1528,7 @@ buf_page_encrypt_before_write( NOTE! The definition appears here only for other modules of this directory (buf) to see it. Do not use from outside! */ -typedef struct { +struct buf_tmp_buffer_t { private: int32 reserved; /*!< true if this slot is reserved */ @@ -1558,7 +1558,7 @@ public: return !my_atomic_fas32_explicit(&reserved, true, MY_MEMORY_ORDER_RELAXED); } -} buf_tmp_buffer_t; +}; /** The common buffer control block structure for compressed and uncompressed frames */ From 7f36300df56da317a46aff1f58b6cdc0e5727cf6 Mon Sep 17 00:00:00 2001 From: Eugene Kosov Date: Wed, 11 Mar 2020 16:40:34 +0300 Subject: [PATCH 4/4] MDEV-21918 improve page_zip_verify_checksum() actually, page_zip_verify_checksum() generally allows all-zeroes checksums because our CRC32 checksum is something like crc_1 ^ crc_2 ^ crc_3 Also, all zeroes page is considered correct. As a side effect fix nasty reinterpret_cast<> UB Also, since c0f47a4a5842 innodb_checksum_algorithm=full_crc32 exists which computes CRC32 in one go (without bitwise arithmetic) --- storage/innobase/page/page0zip.cc | 39 +++++++++++++------------------ storage/xtradb/page/page0zip.cc | 39 +++++++++++++------------------ 2 files changed, 32 insertions(+), 46 deletions(-) diff --git a/storage/innobase/page/page0zip.cc b/storage/innobase/page/page0zip.cc index 1b0fcea326a..6f1c19799b5 100644 --- a/storage/innobase/page/page0zip.cc +++ b/storage/innobase/page/page0zip.cc @@ -4918,35 +4918,28 @@ page_zip_verify_checksum( ib_uint32_t crc32 = 0 /* silence bogus warning */; ib_uint32_t innodb = 0 /* silence bogus warning */; - stored = static_cast(mach_read_from_4( - static_cast(data) + FIL_PAGE_SPACE_OR_CHKSUM)); - -#if FIL_PAGE_LSN % 8 -#error "FIL_PAGE_LSN must be 64 bit aligned" -#endif - - /* Check if page is empty */ - if (stored == 0 - && *reinterpret_cast(static_cast( - data) - + FIL_PAGE_LSN) == 0) { - /* make sure that the page is really empty */ - for (ulint i = 0; i < size; i++) { - if (*((const char*) data + i) != 0) { - return(FALSE); - } - } - /* Empty page */ - return(TRUE); - } - const srv_checksum_algorithm_t curr_algo = static_cast(srv_checksum_algorithm); if (curr_algo == SRV_CHECKSUM_ALGORITHM_NONE) { - return(TRUE); + return true; } + bool all_zeroes = true; + for (size_t i = 0; i < size; i++) { + if (static_cast(data)[i] != 0) { + all_zeroes = false; + break; + } + } + + if (all_zeroes) { + return true; + } + + stored = static_cast(mach_read_from_4( + static_cast(data) + FIL_PAGE_SPACE_OR_CHKSUM)); + calc = static_cast(page_zip_calc_checksum( data, size, curr_algo)); diff --git a/storage/xtradb/page/page0zip.cc b/storage/xtradb/page/page0zip.cc index 0c7f9b6feff..d85594c5ce3 100644 --- a/storage/xtradb/page/page0zip.cc +++ b/storage/xtradb/page/page0zip.cc @@ -4927,35 +4927,28 @@ page_zip_verify_checksum( ib_uint32_t crc32 = 0 /* silence bogus warning */; ib_uint32_t innodb = 0 /* silence bogus warning */; - stored = static_cast(mach_read_from_4( - static_cast(data) + FIL_PAGE_SPACE_OR_CHKSUM)); - -#if FIL_PAGE_LSN % 8 -#error "FIL_PAGE_LSN must be 64 bit aligned" -#endif - - /* Check if page is empty */ - if (stored == 0 - && *reinterpret_cast(static_cast( - data) - + FIL_PAGE_LSN) == 0) { - /* make sure that the page is really empty */ - for (ulint i = 0; i < size; i++) { - if (*((const char*) data + i) != 0) { - return(FALSE); - } - } - /* Empty page */ - return(TRUE); - } - const srv_checksum_algorithm_t curr_algo = static_cast(srv_checksum_algorithm); if (curr_algo == SRV_CHECKSUM_ALGORITHM_NONE) { - return(TRUE); + return true; } + bool all_zeroes = true; + for (size_t i = 0; i < size; i++) { + if (static_cast(data)[i] != 0) { + all_zeroes = false; + break; + } + } + + if (all_zeroes) { + return true; + } + + stored = static_cast(mach_read_from_4( + static_cast(data) + FIL_PAGE_SPACE_OR_CHKSUM)); + calc = static_cast(page_zip_calc_checksum( data, size, curr_algo));