diff options
80 files changed, 726 insertions, 682 deletions
diff --git a/extra/mariabackup/backup_mysql.cc b/extra/mariabackup/backup_mysql.cc index 847340e6dc7..6c13079a8fc 100644 --- a/extra/mariabackup/backup_mysql.cc +++ b/extra/mariabackup/backup_mysql.cc @@ -505,7 +505,8 @@ get_mysql_vars(MYSQL *connection) } if (page_zip_level_var != NULL) { - page_zip_level = strtoul(page_zip_level_var, &endptr, 10); + page_zip_level = static_cast<uint>(strtoul(page_zip_level_var, + &endptr, 10)); ut_ad(*endptr == 0); } diff --git a/extra/mariabackup/crc/crc-intel-pclmul.c b/extra/mariabackup/crc/crc-intel-pclmul.c index cf4f3ef4380..032802c1823 100644 --- a/extra/mariabackup/crc/crc-intel-pclmul.c +++ b/extra/mariabackup/crc/crc-intel-pclmul.c @@ -358,7 +358,7 @@ crc32_reflected_less_than_16 (u32 *pcrc, const byte *inbuf, size_t inlen, else { data = ((const struct u16_unaligned_s *)inbuf)->a; - data |= inbuf[2] << 16; + data |= ((u32) inbuf[2]) << 16; data ^= crc; data <<= 8; crc >>= 24; diff --git a/extra/mariabackup/xtrabackup.cc b/extra/mariabackup/xtrabackup.cc index aac87c61742..f3f216226aa 100644 --- a/extra/mariabackup/xtrabackup.cc +++ b/extra/mariabackup/xtrabackup.cc @@ -242,11 +242,6 @@ static char* innobase_ignored_opt; char* innobase_data_home_dir; char* innobase_data_file_path; -my_bool innobase_use_doublewrite; -my_bool innobase_file_per_table; -my_bool innobase_rollback_on_timeout; -my_bool innobase_create_status_file; - /* The following counter is used to convey information to InnoDB about server activity: in selects it is not sensible to call srv_active_wake_master_thread after each fetch or search, we only do @@ -1236,8 +1231,8 @@ struct my_option xb_server_options[] = &innobase_data_home_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"innodb_doublewrite", OPT_INNODB_DOUBLEWRITE, "Enable InnoDB doublewrite buffer during --prepare.", - (G_PTR*) &innobase_use_doublewrite, - (G_PTR*) &innobase_use_doublewrite, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, + (G_PTR*) &srv_use_doublewrite_buf, + (G_PTR*) &srv_use_doublewrite_buf, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"innodb_io_capacity", OPT_INNODB_IO_CAPACITY, "Number of IOPs the server can do. Tunes the background IO rate", (G_PTR*) &srv_io_capacity, (G_PTR*) &srv_io_capacity, @@ -1256,8 +1251,8 @@ struct my_option xb_server_options[] = 1, 0}, {"innodb_file_per_table", OPT_INNODB_FILE_PER_TABLE, "Stores each InnoDB table to an .ibd file in the database dir.", - (G_PTR*) &innobase_file_per_table, - (G_PTR*) &innobase_file_per_table, 0, GET_BOOL, NO_ARG, + (G_PTR*) &srv_file_per_table, + (G_PTR*) &srv_file_per_table, 0, GET_BOOL, NO_ARG, FALSE, 0, 0, 0, 0, 0}, {"innodb_flush_method", OPT_INNODB_FLUSH_METHOD, @@ -1528,9 +1523,9 @@ static int prepare_export() outf= popen(cmdline,"r"); if (!outf) goto end; - + char outline[FN_REFLEN]; - while(fgets(outline, sizeof(outline)-1, outf)) + while (fgets(outline, FN_REFLEN - 1, outf)) fprintf(stderr,"%s",outline); err = pclose(outf); @@ -1887,14 +1882,7 @@ static bool innodb_init_param() srv_n_read_io_threads = (ulint) innobase_read_io_threads; srv_n_write_io_threads = (ulint) innobase_write_io_threads; - srv_use_doublewrite_buf = (ibool) innobase_use_doublewrite; - - row_rollback_on_timeout = (ibool) innobase_rollback_on_timeout; - - srv_file_per_table = (my_bool) innobase_file_per_table; - srv_max_n_open_files = ULINT_UNDEFINED - 5; - srv_innodb_status = (ibool) innobase_create_status_file; srv_print_verbose_log = verbose ? 2 : 1; @@ -2770,7 +2758,7 @@ static os_thread_ret_t DECLARE_THREAD(log_copying_thread)(void*) for (;;) { os_event_reset(log_copying_stop); os_event_wait_time_low(log_copying_stop, - xtrabackup_log_copy_interval * 1000ULL, + xtrabackup_log_copy_interval * 1000U, 0); if (xtrabackup_copy_logfile()) { break; @@ -3764,26 +3752,23 @@ xb_filters_free() } } -/*********************************************************************** +#ifdef RLIMIT_NOFILE +/** Set the open files limit. Based on set_max_open_files(). - +@param max_file_limit requested open files limit @return the resulting open files limit. May be less or more than the requested value. */ -static uint -xb_set_max_open_files( -/*==================*/ - uint max_file_limit) /*!<in: open files limit */ +static ulong xb_set_max_open_files(rlim_t max_file_limit) { -#if defined(RLIMIT_NOFILE) struct rlimit rlimit; - uint old_cur; + rlim_t old_cur; if (getrlimit(RLIMIT_NOFILE, &rlimit)) { goto end; } - old_cur = (uint) rlimit.rlim_cur; + old_cur = rlimit.rlim_cur; if (rlimit.rlim_cur == RLIM_INFINITY) { @@ -3799,8 +3784,8 @@ xb_set_max_open_files( rlimit.rlim_cur = rlimit.rlim_max = max_file_limit; if (setrlimit(RLIMIT_NOFILE, &rlimit)) { - - max_file_limit = old_cur; /* Use original value */ + /* Use original value */ + max_file_limit = static_cast<ulong>(old_cur); } else { rlimit.rlim_cur = 0; /* Safety if next call fails */ @@ -3810,16 +3795,16 @@ xb_set_max_open_files( if (rlimit.rlim_cur) { /* If call didn't fail */ - max_file_limit = (uint) rlimit.rlim_cur; + max_file_limit = rlimit.rlim_cur; } } end: - return(max_file_limit); + return static_cast<ulong>(max_file_limit); +} #else - return(0); +# define xb_set_max_open_files(x) 0 #endif -} static void stop_backup_threads() { @@ -3950,8 +3935,8 @@ static bool xtrabackup_backup_func() } msg("cd to %s", mysql_real_data_home); encryption_plugin_backup_init(mysql_connection); - msg("open files limit requested %u, set to %u", - (uint) xb_open_files_limit, + msg("open files limit requested %lu, set to %lu", + xb_open_files_limit, xb_set_max_open_files(xb_open_files_limit)); mysql_data_home= mysql_data_home_buff; @@ -4515,10 +4500,11 @@ xb_space_create_file( fprintf(stderr, "zip_size = " ULINTPF "\n", zip_size); #ifdef UNIV_DEBUG - page_zip.m_start = + page_zip.m_start = 0; #endif /* UNIV_DEBUG */ - page_zip.m_end = page_zip.m_nonempty = - page_zip.n_blobs = 0; + page_zip.m_end = 0; + page_zip.m_nonempty = 0; + page_zip.n_blobs = 0; buf_flush_init_for_writing(NULL, page, &page_zip, false); @@ -6197,10 +6183,10 @@ static int main_low(char** argv) incremental_lsn); } - if (xtrabackup_export && innobase_file_per_table == FALSE) { + if (xtrabackup_export && !srv_file_per_table) { msg("mariabackup: auto-enabling --innodb-file-per-table due to " "the --export option"); - innobase_file_per_table = TRUE; + srv_file_per_table = TRUE; } /* cannot execute both for now */ diff --git a/libmysqld/libmysql.c b/libmysqld/libmysql.c index 22514acf3f0..476630d77bc 100644 --- a/libmysqld/libmysql.c +++ b/libmysqld/libmysql.c @@ -4226,7 +4226,7 @@ static int stmt_fetch_row(MYSQL_STMT *stmt, uchar *row) (*my_bind->fetch_result)(my_bind, field, &row); truncation_count+= *my_bind->error; } - if (!((bit<<=1) & 255)) + if (!(bit= (uchar) (bit << 1))) { bit= 1; /* To next uchar */ null_ptr++; @@ -4426,7 +4426,7 @@ static void stmt_update_metadata(MYSQL_STMT *stmt, MYSQL_ROWS *data) if (!(*null_ptr & bit)) (*my_bind->skip_result)(my_bind, field, &row); DBUG_ASSERT(row <= row_end); - if (!((bit<<=1) & 255)) + if (!(bit= (uchar) (bit << 1))) { bit= 1; /* To next uchar */ null_ptr++; diff --git a/storage/innobase/btr/btr0btr.cc b/storage/innobase/btr/btr0btr.cc index a06a7bd4013..651b9dc6efe 100644 --- a/storage/innobase/btr/btr0btr.cc +++ b/storage/innobase/btr/btr0btr.cc @@ -1777,7 +1777,7 @@ void btr_set_instant(buf_block_t* root, const dict_index_t& index, mtr_t* mtr) ut_ad(!memcmp(supremum, "supremum", 8)); mtr->write<2>(*root, page_type, FIL_PAGE_TYPE_INSTANT); ut_ad(i <= PAGE_NO_DIRECTION); - i |= index.n_core_fields << 3; + i |= static_cast<uint16_t>(index.n_core_fields << 3); mtr->write<2>(*root, PAGE_HEADER + PAGE_INSTANT + root->frame, i); break; diff --git a/storage/innobase/btr/btr0bulk.cc b/storage/innobase/btr/btr0bulk.cc index 1171de544a7..9873f30aa45 100644 --- a/storage/innobase/btr/btr0bulk.cc +++ b/storage/innobase/btr/btr0bulk.cc @@ -372,7 +372,7 @@ inline void PageBulk::finishPage() { uint16_t offset= mach_read_from_2(PAGE_NEW_INFIMUM - REC_NEXT + m_page); ut_ad(offset >= PAGE_NEW_SUPREMUM - PAGE_NEW_INFIMUM); - offset += PAGE_NEW_INFIMUM; + offset= static_cast<uint16_t>(offset + PAGE_NEW_INFIMUM); /* Set owner & dir. */ do { @@ -395,8 +395,9 @@ inline void PageBulk::finishPage() count= 0; } - uint16_t next= (mach_read_from_2(m_page + offset - REC_NEXT) + offset) & - (srv_page_size - 1); + uint16_t next= static_cast<uint16_t> + ((mach_read_from_2(m_page + offset - REC_NEXT) + offset) & + (srv_page_size - 1)); ut_ad(next); offset= next; } diff --git a/storage/innobase/btr/btr0cur.cc b/storage/innobase/btr/btr0cur.cc index adda8bca94c..55ddbdc14ee 100644 --- a/storage/innobase/btr/btr0cur.cc +++ b/storage/innobase/btr/btr0cur.cc @@ -698,8 +698,8 @@ bool btr_cur_instant_root_init(dict_index_t* index, const page_t* page) index root pages of ROW_FORMAT=COMPACT or ROW_FORMAT=DYNAMIC when instant ADD COLUMN is not used. */ ut_ad(!page_is_comp(page) || !page_get_instant(page)); - index->n_core_null_bytes = UT_BITS_IN_BYTES( - unsigned(index->n_nullable)); + index->n_core_null_bytes = static_cast<uint8_t>( + UT_BITS_IN_BYTES(unsigned(index->n_nullable))); return false; case FIL_PAGE_TYPE_INSTANT: break; @@ -718,7 +718,7 @@ bool btr_cur_instant_root_init(dict_index_t* index, const page_t* page) return true; } - index->n_core_fields = n; + index->n_core_fields = n & dict_index_t::MAX_N_FIELDS; const rec_t* infimum = page_get_infimum_rec(page); const rec_t* supremum = page_get_supremum_rec(page); @@ -734,8 +734,8 @@ bool btr_cur_instant_root_init(dict_index_t* index, const page_t* page) ut_ad(!index->is_dummy); ut_d(index->is_dummy = true); - index->n_core_null_bytes = UT_BITS_IN_BYTES( - index->get_n_nullable(n)); + index->n_core_null_bytes = static_cast<uint8_t>( + UT_BITS_IN_BYTES(index->get_n_nullable(n))); ut_d(index->is_dummy = false); return false; } @@ -4116,7 +4116,7 @@ void btr_cur_upd_rec_in_place(rec_t *rec, const dict_index_t *index, byte* info_bits = &rec[-REC_NEW_INFO_BITS]; const bool flip_del_mark = (*info_bits ^ update->info_bits) & REC_INFO_DELETED_FLAG; - *info_bits &= ~REC_INFO_BITS_MASK; + *info_bits &= byte(~REC_INFO_BITS_MASK); *info_bits |= update->info_bits; if (flip_del_mark) { @@ -5290,7 +5290,7 @@ void btr_rec_set_deleted(buf_block_t *block, rec_t *rec, mtr_t *mtr) byte *b= &rec[-REC_NEW_INFO_BITS]; const byte v= flag ? (*b | REC_INFO_DELETED_FLAG) - : (*b & ~REC_INFO_DELETED_FLAG); + : (*b & byte(~REC_INFO_DELETED_FLAG)); if (*b == v); else if (UNIV_LIKELY_NULL(block->page.zip.data)) { @@ -5306,7 +5306,7 @@ void btr_rec_set_deleted(buf_block_t *block, rec_t *rec, mtr_t *mtr) byte *b= &rec[-REC_OLD_INFO_BITS]; const byte v = flag ? (*b | REC_INFO_DELETED_FLAG) - : (*b & ~REC_INFO_DELETED_FLAG); + : (*b & byte(~REC_INFO_DELETED_FLAG)); mtr->write<1,mtr_t::OPT>(*block, b, v); } } @@ -6676,11 +6676,12 @@ btr_estimate_number_of_different_key_vals( n_pages = S < I? min(I,L) : I */ if (index->stat_index_size > 1) { - n_sample_pages = (srv_stats_transient_sample_pages < index->stat_index_size) ? - ut_min(index->stat_index_size, - static_cast<ulint>(log2(index->stat_index_size)*double(srv_stats_transient_sample_pages))) + n_sample_pages = (srv_stats_transient_sample_pages < index->stat_index_size) + ? ut_min(index->stat_index_size, + static_cast<ulint>( + log2(double(index->stat_index_size)) + * double(srv_stats_transient_sample_pages))) : index->stat_index_size; - } } @@ -6977,13 +6978,11 @@ btr_cur_disown_inherited_fields( const upd_t* update, /*!< in: update vector */ mtr_t* mtr) /*!< in/out: mini-transaction */ { - ulint i; - ut_ad(rec_offs_validate(rec, index, offsets)); ut_ad(!rec_offs_comp(offsets) || !rec_get_node_ptr_flag(rec)); ut_ad(rec_offs_any_extern(offsets)); - for (i = 0; i < rec_offs_n_fields(offsets); i++) { + for (uint16_t i = 0; i < rec_offs_n_fields(offsets); i++) { if (rec_offs_nth_extern(offsets, i) && !upd_get_field_by_field_no(update, i, false)) { btr_cur_set_ownership_of_extern_field( diff --git a/storage/innobase/btr/btr0sea.cc b/storage/innobase/btr/btr0sea.cc index 05294568a6e..562a59f7628 100644 --- a/storage/innobase/btr/btr0sea.cc +++ b/storage/innobase/btr/btr0sea.cc @@ -457,7 +457,6 @@ btr_search_info_update_hash( btr_cur_t* cursor) { dict_index_t* index = cursor->index; - ulint n_unique; int cmp; ut_ad(!btr_search_own_any(RW_LOCK_S)); @@ -470,7 +469,7 @@ btr_search_info_update_hash( return; } - n_unique = dict_index_get_n_unique_in_tree(index); + uint16_t n_unique = dict_index_get_n_unique_in_tree(index); if (info->n_hash_potential == 0) { @@ -512,16 +511,13 @@ set_new_recomm: cmp = ut_pair_cmp(cursor->up_match, cursor->up_bytes, cursor->low_match, cursor->low_bytes); - if (cmp == 0) { - info->n_hash_potential = 0; + info->left_side = cmp >= 0; + info->n_hash_potential = cmp != 0; + if (cmp == 0) { /* For extra safety, we set some sensible values here */ - info->n_fields = 1; info->n_bytes = 0; - - info->left_side = TRUE; - } else if (cmp > 0) { info->n_hash_potential = 1; @@ -532,31 +528,31 @@ set_new_recomm: } else if (cursor->low_match < cursor->up_match) { - info->n_fields = cursor->low_match + 1; + info->n_fields = static_cast<uint16_t>( + cursor->low_match + 1); info->n_bytes = 0; } else { - info->n_fields = cursor->low_match; - info->n_bytes = cursor->low_bytes + 1; + info->n_fields = static_cast<uint16_t>( + cursor->low_match); + info->n_bytes = static_cast<uint16_t>( + cursor->low_bytes + 1); } - - info->left_side = TRUE; } else { - info->n_hash_potential = 1; - if (cursor->low_match >= n_unique) { info->n_fields = n_unique; info->n_bytes = 0; } else if (cursor->low_match > cursor->up_match) { - info->n_fields = cursor->up_match + 1; + info->n_fields = static_cast<uint16_t>( + cursor->up_match + 1); info->n_bytes = 0; } else { - info->n_fields = cursor->up_match; - info->n_bytes = cursor->up_bytes + 1; + info->n_fields = static_cast<uint16_t>( + cursor->up_match); + info->n_bytes = static_cast<uint16_t>( + cursor->up_bytes + 1); } - - info->left_side = FALSE; } } @@ -1348,9 +1344,9 @@ btr_search_build_page_hash_index( dict_index_t* index, buf_block_t* block, rw_lock_t* ahi_latch, - ulint n_fields, - ulint n_bytes, - ibool left_side) + uint16_t n_fields, + uint16_t n_bytes, + bool left_side) { const rec_t* rec; const rec_t* next_rec; @@ -1438,7 +1434,7 @@ btr_search_build_page_hash_index( btr_search_get_n_fields(n_fields, n_bytes), &heap); ut_ad(page_rec_is_supremum(rec) - || n_fields + (n_bytes > 0) == rec_offs_n_fields(offsets)); + || n_fields == rec_offs_n_fields(offsets) - (n_bytes > 0)); fold = rec_fold(rec, offsets, n_fields, n_bytes, index->id); @@ -1516,9 +1512,9 @@ btr_search_build_page_hash_index( block->n_hash_helps = 0; - block->curr_n_fields = unsigned(n_fields); - block->curr_n_bytes = unsigned(n_bytes); - block->curr_left_side = unsigned(left_side); + block->curr_n_fields = n_fields & dict_index_t::MAX_N_FIELDS; + block->curr_n_bytes = n_bytes & ((1U << 15) - 1); + block->curr_left_side = left_side; block->index = index; for (i = 0; i < n_cached; i++) { @@ -1633,9 +1629,9 @@ btr_search_move_or_delete_hash_entries( rw_lock_s_lock(ahi_latch); if (block->index) { - ulint n_fields = block->curr_n_fields; - ulint n_bytes = block->curr_n_bytes; - ibool left_side = block->curr_left_side; + uint16_t n_fields = block->curr_n_fields; + uint16_t n_bytes = block->curr_n_bytes; + bool left_side = block->curr_left_side; new_block->n_fields = block->curr_n_fields; new_block->n_bytes = block->curr_n_bytes; diff --git a/storage/innobase/buf/buf0lru.cc b/storage/innobase/buf/buf0lru.cc index 8f59d0c5668..f76d939d410 100644 --- a/storage/innobase/buf/buf0lru.cc +++ b/storage/innobase/buf/buf0lru.cc @@ -1292,7 +1292,8 @@ buf_LRU_add_block_low( UT_LIST_ADD_FIRST(buf_pool->LRU, bpage); - bpage->freed_page_clock = buf_pool->freed_page_clock; + bpage->freed_page_clock = buf_pool->freed_page_clock + & ((1U << 31) - 1); } else { #ifdef UNIV_LRU_DEBUG /* buf_pool->LRU_old must be the first item in the LRU list diff --git a/storage/innobase/data/data0data.cc b/storage/innobase/data/data0data.cc index 7cc9c2bc09e..af2ea0fd198 100644 --- a/storage/innobase/data/data0data.cc +++ b/storage/innobase/data/data0data.cc @@ -637,10 +637,11 @@ dtuple_convert_big_rec( stored externally */ n_fields = 0; - ulint longest_i; + uint16_t longest_i; + ulint longest; const bool mblob = entry->is_alter_metadata(); - ut_ad(entry->n_fields >= index->first_user_field() + mblob); + ut_ad(entry->n_fields - mblob >= index->first_user_field()); ut_ad(entry->n_fields - mblob <= index->n_fields); if (mblob) { @@ -666,8 +667,9 @@ dtuple_convert_big_rec( dict_index_get_n_fields(index), zip_size)) { longest_i = 0; - for (ulint i = index->first_user_field(), longest = 0; - i + mblob < entry->n_fields; i++) { + longest = 0; + for (uint16_t i = index->first_user_field(); + i < entry->n_fields - mblob; i++) { ulint savings; dfield = dtuple_get_nth_field(entry, i + mblob); @@ -766,7 +768,7 @@ ext_write: DEBUG_SYNC_C("ib_mv_nonupdated_column_offpage"); upd_field_t upd_field; - upd_field.field_no = unsigned(longest_i); + upd_field.field_no = longest_i; upd_field.orig_len = 0; upd_field.exp = NULL; upd_field.old_v_val = NULL; diff --git a/storage/innobase/dict/dict0boot.cc b/storage/innobase/dict/dict0boot.cc index a68d8c2c0ba..79a3adc7aa6 100644 --- a/storage/innobase/dict/dict0boot.cc +++ b/storage/innobase/dict/dict0boot.cc @@ -312,8 +312,8 @@ dict_boot(void) index, mach_read_from_4(dict_hdr + DICT_HDR_TABLES)); ut_a(error == DB_SUCCESS); ut_ad(!table->is_instant()); - table->indexes.start->n_core_null_bytes = UT_BITS_IN_BYTES( - unsigned(table->indexes.start->n_nullable)); + table->indexes.start->n_core_null_bytes = static_cast<uint8_t>( + UT_BITS_IN_BYTES(unsigned(table->indexes.start->n_nullable))); /*-------------------------*/ index = dict_mem_index_create(table, "ID_IND", DICT_UNIQUE, 1); @@ -354,8 +354,8 @@ dict_boot(void) index, mach_read_from_4(dict_hdr + DICT_HDR_COLUMNS)); ut_a(error == DB_SUCCESS); ut_ad(!table->is_instant()); - table->indexes.start->n_core_null_bytes = UT_BITS_IN_BYTES( - unsigned(table->indexes.start->n_nullable)); + table->indexes.start->n_core_null_bytes = static_cast<uint8_t>( + UT_BITS_IN_BYTES(unsigned(table->indexes.start->n_nullable))); /*-------------------------*/ table = dict_mem_table_create("SYS_INDEXES", fil_system.sys_space, @@ -397,8 +397,8 @@ dict_boot(void) index, mach_read_from_4(dict_hdr + DICT_HDR_INDEXES)); ut_a(error == DB_SUCCESS); ut_ad(!table->is_instant()); - table->indexes.start->n_core_null_bytes = UT_BITS_IN_BYTES( - unsigned(table->indexes.start->n_nullable)); + table->indexes.start->n_core_null_bytes = static_cast<uint8_t>( + UT_BITS_IN_BYTES(unsigned(table->indexes.start->n_nullable))); /*-------------------------*/ table = dict_mem_table_create("SYS_FIELDS", fil_system.sys_space, @@ -426,8 +426,8 @@ dict_boot(void) index, mach_read_from_4(dict_hdr + DICT_HDR_FIELDS)); ut_a(error == DB_SUCCESS); ut_ad(!table->is_instant()); - table->indexes.start->n_core_null_bytes = UT_BITS_IN_BYTES( - unsigned(table->indexes.start->n_nullable)); + table->indexes.start->n_core_null_bytes = static_cast<uint8_t>( + UT_BITS_IN_BYTES(unsigned(table->indexes.start->n_nullable))); mtr_commit(&mtr); diff --git a/storage/innobase/dict/dict0crea.cc b/storage/innobase/dict/dict0crea.cc index 392fefd7ebd..f7bd584129d 100644 --- a/storage/innobase/dict/dict0crea.cc +++ b/storage/innobase/dict/dict0crea.cc @@ -1260,8 +1260,8 @@ dict_create_index_step( ? dict_index_t::NO_CORE_NULL_BYTES : UT_BITS_IN_BYTES( unsigned(node->index->n_nullable)))); - node->index->n_core_null_bytes = UT_BITS_IN_BYTES( - unsigned(node->index->n_nullable)); + node->index->n_core_null_bytes = static_cast<uint8_t>( + UT_BITS_IN_BYTES(unsigned(node->index->n_nullable))); node->state = INDEX_CREATE_INDEX_TREE; } diff --git a/storage/innobase/dict/dict0dict.cc b/storage/innobase/dict/dict0dict.cc index c1cc6ca1096..86ce341f25a 100644 --- a/storage/innobase/dict/dict0dict.cc +++ b/storage/innobase/dict/dict0dict.cc @@ -848,7 +848,10 @@ is_unaccessible: if (trylock ? mdl_context->try_acquire_lock(&request) : mdl_context->acquire_lock(&request, - global_system_variables.lock_wait_timeout)) + /* FIXME: use compatible type, and maybe + remove this parameter altogether! */ + static_cast<double>(global_system_variables + .lock_wait_timeout))) { *mdl= nullptr; if (trylock) @@ -1991,8 +1994,8 @@ dict_index_add_to_cache( new_index = (index->type & DICT_FTS) ? dict_index_build_internal_fts(index) : dict_index_build_internal_non_clust(index); - new_index->n_core_null_bytes = UT_BITS_IN_BYTES( - unsigned(new_index->n_nullable)); + new_index->n_core_null_bytes = static_cast<uint8_t>( + UT_BITS_IN_BYTES(unsigned(new_index->n_nullable))); } /* Set the n_fields value in new_index to the actual defined @@ -2288,12 +2291,14 @@ dict_index_add_col( field = dict_index_get_nth_field(index, unsigned(index->n_def) - 1); field->col = col; - field->fixed_len = static_cast<unsigned int>( + field->fixed_len = static_cast<uint16_t>( dict_col_get_fixed_size( - col, dict_table_is_comp(table))); + col, dict_table_is_comp(table))) + & ((1U << 10) - 1); if (prefix_len && field->fixed_len > prefix_len) { - field->fixed_len = (unsigned int) prefix_len; + field->fixed_len = static_cast<uint16_t>(prefix_len) + & ((1U << 10) - 1); } /* Long fixed-length fields that need external storage are treated as @@ -2469,7 +2474,8 @@ dict_index_build_internal_clust( new_index->n_uniq = new_index->n_def; } else { /* Also the row id is needed to identify the entry */ - new_index->n_uniq = 1 + unsigned(new_index->n_def); + new_index->n_uniq = unsigned(new_index->n_def + 1) + & dict_index_t::MAX_N_FIELDS; } new_index->trx_id_offset = 0; @@ -2519,7 +2525,8 @@ dict_index_build_internal_clust( can theoretically occur. Check for it. */ fixed_size += new_index->trx_id_offset; - new_index->trx_id_offset = unsigned(fixed_size); + new_index->trx_id_offset = static_cast<unsigned>(fixed_size) + & ((1U << 12) - 1); if (new_index->trx_id_offset != fixed_size) { /* Overflow. Pretend that this is a @@ -2569,7 +2576,8 @@ dict_index_build_internal_clust( new_index->n_core_null_bytes = table->supports_instant() ? dict_index_t::NO_CORE_NULL_BYTES - : UT_BITS_IN_BYTES(unsigned(new_index->n_nullable)); + : static_cast<uint8_t>( + UT_BITS_IN_BYTES(unsigned(new_index->n_nullable))); new_index->cached = TRUE; return(new_index); @@ -4332,7 +4340,8 @@ dict_set_merge_threshold_list_debug( index != NULL; index = UT_LIST_GET_NEXT(indexes, index)) { rw_lock_x_lock(dict_index_get_lock(index)); - index->merge_threshold = merge_threshold_all; + index->merge_threshold = merge_threshold_all + & ((1U << 6) - 1); rw_lock_x_unlock(dict_index_get_lock(index)); } } diff --git a/storage/innobase/dict/dict0load.cc b/storage/innobase/dict/dict0load.cc index 4e258e0c324..f193cec5aa8 100644 --- a/storage/innobase/dict/dict0load.cc +++ b/storage/innobase/dict/dict0load.cc @@ -528,7 +528,6 @@ dict_process_sys_foreign_rec( { ulint len; const byte* field; - ulint n_fields_and_type; if (rec_get_deleted_flag(rec, 0)) { return("delete-marked record in SYS_FOREIGN"); @@ -586,10 +585,10 @@ err_len: if (len != 4) { goto err_len; } - n_fields_and_type = mach_read_from_4(field); + uint32_t n_fields_and_type = mach_read_from_4(field); - foreign->type = (unsigned int) (n_fields_and_type >> 24); - foreign->n_fields = (unsigned int) (n_fields_and_type & 0x3FFUL); + foreign->type = n_fields_and_type >> 24 & ((1U << 6) - 1); + foreign->n_fields = n_fields_and_type & dict_index_t::MAX_N_FIELDS; return(NULL); } @@ -2097,7 +2096,7 @@ err_len: sys_field->name = mem_heap_strdupl( heap, (const char*) field, len); - sys_field->prefix_len = prefix_len; + sys_field->prefix_len = prefix_len & ((1U << 12) - 1); *pos = position; } @@ -2326,7 +2325,7 @@ err_len: (*index)->id = id; (*index)->page = mach_read_from_4(field); ut_ad((*index)->page); - (*index)->merge_threshold = merge_threshold; + (*index)->merge_threshold = merge_threshold & ((1U << 6) - 1); return(NULL); } @@ -2693,10 +2692,12 @@ dict_get_and_save_data_dir_path( if (const char* p = table->space ? table->space->chain.start->name : NULL) { - table->flags |= (1 << DICT_TF_POS_DATA_DIR); + table->flags |= 1 << DICT_TF_POS_DATA_DIR + & ((1U << DICT_TF_BITS) - 1); dict_save_data_dir_path(table, p); } else if (char* path = dict_get_first_path(table->space_id)) { - table->flags |= (1 << DICT_TF_POS_DATA_DIR); + table->flags |= 1 << DICT_TF_POS_DATA_DIR + & ((1U << DICT_TF_BITS) - 1); dict_save_data_dir_path(table, path); ut_free(path); } @@ -2706,7 +2707,8 @@ dict_get_and_save_data_dir_path( unset the flag. This does not change SYS_DATAFILES or SYS_TABLES or FSP_FLAGS on the header page of the tablespace, but it makes dict_table_t consistent. */ - table->flags &= ~DICT_TF_MASK_DATA_DIR; + table->flags &= ~DICT_TF_MASK_DATA_DIR + & ((1U << DICT_TF_BITS) - 1); } if (!dict_mutex_own) { @@ -3373,7 +3375,6 @@ dict_load_foreign( const rec_t* rec; const byte* field; ulint len; - ulint n_fields_and_type; mtr_t mtr; dict_table_t* for_table; dict_table_t* ref_table; @@ -3447,7 +3448,7 @@ dict_load_foreign( foreign = dict_mem_foreign_create(); - n_fields_and_type = mach_read_from_4( + uint32_t n_fields_and_type = mach_read_from_4( rec_get_nth_field_old( rec, DICT_FLD__SYS_FOREIGN__N_COLS, &len)); @@ -3455,8 +3456,8 @@ dict_load_foreign( /* We store the type in the bits 24..29 of n_fields_and_type. */ - foreign->type = (unsigned int) (n_fields_and_type >> 24); - foreign->n_fields = (unsigned int) (n_fields_and_type & 0x3FFUL); + foreign->type = (n_fields_and_type >> 24) & ((1U << 6) - 1); + foreign->n_fields = n_fields_and_type & dict_index_t::MAX_N_FIELDS; foreign->id = mem_heap_strdupl(foreign->heap, id, id_len); diff --git a/storage/innobase/dict/dict0mem.cc b/storage/innobase/dict/dict0mem.cc index 4cd7d3cbf3b..1b13e8fab0c 100644 --- a/storage/innobase/dict/dict0mem.cc +++ b/storage/innobase/dict/dict0mem.cc @@ -2,7 +2,7 @@ Copyright (c) 1996, 2018, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2012, Facebook Inc. -Copyright (c) 2013, 2019, MariaDB Corporation. +Copyright (c) 2013, 2020, MariaDB Corporation. 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 the Free Software @@ -162,15 +162,21 @@ dict_mem_table_create( ut_d(table->magic_n = DICT_TABLE_MAGIC_N); - table->flags = (unsigned int) flags; - table->flags2 = (unsigned int) flags2; + table->flags = static_cast<unsigned>(flags) + & ((1U << DICT_TF_BITS) - 1); + table->flags2 = static_cast<unsigned>(flags2) + & ((1U << DICT_TF2_BITS) - 1); table->name.m_name = mem_strdup(name); table->is_system_db = dict_mem_table_is_system(table->name.m_name); table->space = space; table->space_id = space ? space->id : ULINT_UNDEFINED; - table->n_t_cols = unsigned(n_cols + DATA_N_SYS_COLS); - table->n_v_cols = (unsigned int) (n_v_cols); - table->n_cols = unsigned(table->n_t_cols - table->n_v_cols); + table->n_t_cols = static_cast<unsigned>(n_cols + DATA_N_SYS_COLS) + & dict_index_t::MAX_N_FIELDS; + table->n_v_cols = static_cast<unsigned>(n_v_cols) + & dict_index_t::MAX_N_FIELDS; + table->n_cols = static_cast<unsigned>( + table->n_t_cols - table->n_v_cols) + & dict_index_t::MAX_N_FIELDS; table->cols = static_cast<dict_col_t*>( mem_heap_alloc(heap, table->n_cols * sizeof(dict_col_t))); @@ -336,11 +342,11 @@ dict_mem_table_add_col( switch (prtype & DATA_VERSIONED) { case DATA_VERS_START: ut_ad(!table->vers_start); - table->vers_start = i; + table->vers_start = i & dict_index_t::MAX_N_FIELDS; break; case DATA_VERS_END: ut_ad(!table->vers_end); - table->vers_end = i; + table->vers_end = i & dict_index_t::MAX_N_FIELDS; } } @@ -401,7 +407,7 @@ dict_mem_table_add_v_col( v_col = &table->v_cols[i]; dict_mem_fill_column_struct(&v_col->m_col, pos, mtype, prtype, len); - v_col->v_pos = i; + v_col->v_pos = i & dict_index_t::MAX_N_FIELDS; if (num_base != 0) { v_col->base_col = static_cast<dict_col_t**>(mem_heap_zalloc( @@ -706,15 +712,16 @@ dict_mem_fill_column_struct( { unsigned mbminlen, mbmaxlen; - column->ind = (unsigned int) col_pos; + column->ind = static_cast<unsigned>(col_pos) + & dict_index_t::MAX_N_FIELDS; column->ord_part = 0; column->max_prefix = 0; - column->mtype = (unsigned int) mtype; - column->prtype = (unsigned int) prtype; - column->len = (unsigned int) col_len; + column->mtype = static_cast<uint8_t>(mtype); + column->prtype = static_cast<unsigned>(prtype); + column->len = static_cast<uint16_t>(col_len); dtype_get_mblen(mtype, prtype, &mbminlen, &mbmaxlen); - column->mbminlen = mbminlen; - column->mbmaxlen = mbmaxlen; + column->mbminlen = mbminlen & 7; + column->mbmaxlen = mbmaxlen & 7; column->def_val.data = NULL; column->def_val.len = UNIV_SQL_DEFAULT; ut_ad(!column->is_dropped()); @@ -1043,7 +1050,7 @@ dict_mem_index_add_field( field = dict_index_get_nth_field(index, unsigned(index->n_def) - 1); field->name = name; - field->prefix_len = (unsigned int) prefix_len; + field->prefix_len = prefix_len & ((1U << 12) - 1); } /**********************************************************************//** @@ -1159,8 +1166,10 @@ inline void dict_index_t::reconstruct_fields() { DBUG_ASSERT(is_primary()); - n_fields += table->instant->n_dropped; - n_def += table->instant->n_dropped; + n_fields = (n_fields + table->instant->n_dropped) + & dict_index_t::MAX_N_FIELDS; + n_def = (n_def + table->instant->n_dropped) + & dict_index_t::MAX_N_FIELDS; const unsigned n_first = first_user_field(); @@ -1179,7 +1188,8 @@ inline void dict_index_t::reconstruct_fields() if (c.is_dropped()) { f.col = &table->instant->dropped[j++]; DBUG_ASSERT(f.col->is_dropped()); - f.fixed_len = dict_col_get_fixed_size(f.col, comp); + f.fixed_len = dict_col_get_fixed_size(f.col, comp) + & ((1U << 10) - 1); } else { DBUG_ASSERT(!c.is_not_null()); const auto old = std::find_if( diff --git a/storage/innobase/fil/fil0fil.cc b/storage/innobase/fil/fil0fil.cc index 8e029737441..d7c3fb5cb69 100644 --- a/storage/innobase/fil/fil0fil.cc +++ b/storage/innobase/fil/fil0fil.cc @@ -1855,7 +1855,7 @@ inline void mtr_t::log_file_op(mfile_type_t type, ulint space_id, } else { - *log_ptr= type | static_cast<byte>(end + len + new_len - &log_ptr[1]); + *log_ptr= static_cast<byte>(type | (end + len + new_len - &log_ptr[1])); ut_ad(*log_ptr & 15); } @@ -2828,10 +2828,11 @@ err_exit: page_zip_set_size(&page_zip, zip_size); page_zip.data = page + srv_page_size; #ifdef UNIV_DEBUG - page_zip.m_start = + page_zip.m_start = 0; #endif /* UNIV_DEBUG */ - page_zip.m_end = page_zip.m_nonempty = - page_zip.n_blobs = 0; + page_zip.m_end = 0; + page_zip.m_nonempty = 0; + page_zip.n_blobs = 0; buf_flush_init_for_writing(NULL, page, &page_zip, false); diff --git a/storage/innobase/fsp/fsp0fsp.cc b/storage/innobase/fsp/fsp0fsp.cc index f9fdc4f3af3..a4c1530d55e 100644 --- a/storage/innobase/fsp/fsp0fsp.cc +++ b/storage/innobase/fsp/fsp0fsp.cc @@ -271,14 +271,15 @@ fseg_mark_page_used(fseg_inode_t *seg_inode, buf_block_t *iblock, ut_ad(mach_read_from_4(seg_inode + FSEG_MAGIC_N) == FSEG_MAGIC_N_VALUE); ut_ad(!memcmp(seg_inode + FSEG_ID, descr + XDES_ID, 4)); - const uint16_t xoffset= XDES_FLST_NODE + uint16_t(descr - xdes->frame); + const uint16_t xoffset= uint16_t(descr - xdes->frame + XDES_FLST_NODE); const uint16_t ioffset= uint16_t(seg_inode - iblock->frame); if (!xdes_get_n_used(descr)) { /* We move the extent from the free list to the NOT_FULL list */ - flst_remove(iblock, FSEG_FREE + ioffset, xdes, xoffset, mtr); - flst_add_last(iblock, FSEG_NOT_FULL + ioffset, xdes, xoffset, mtr); + flst_remove(iblock, uint16_t(FSEG_FREE + ioffset), xdes, xoffset, mtr); + flst_add_last(iblock, uint16_t(FSEG_NOT_FULL + ioffset), + xdes, xoffset, mtr); } ut_ad(xdes_is_free(descr, page % FSP_EXTENT_SIZE)); @@ -292,8 +293,8 @@ fseg_mark_page_used(fseg_inode_t *seg_inode, buf_block_t *iblock, if (xdes_is_full(descr)) { /* We move the extent from the NOT_FULL list to the FULL list */ - flst_remove(iblock, FSEG_NOT_FULL + ioffset, xdes, xoffset, mtr); - flst_add_last(iblock, FSEG_FULL + ioffset, xdes, xoffset, mtr); + flst_remove(iblock, uint16_t(FSEG_NOT_FULL + ioffset), xdes, xoffset, mtr); + flst_add_last(iblock, uint16_t(FSEG_FULL + ioffset), xdes, xoffset, mtr); mtr->write<4>(*iblock, seg_inode + FSEG_NOT_FULL_N_USED, not_full_n_used - FSP_EXTENT_SIZE); } @@ -920,8 +921,8 @@ fsp_fill_free_list( fil_block_check_type(*xdes, FIL_PAGE_TYPE_XDES, mtr); } xdes_init(*xdes, descr, mtr); - const uint16_t xoffset= XDES_FLST_NODE - + uint16_t(descr - xdes->frame); + const uint16_t xoffset= static_cast<uint16_t>( + descr - xdes->frame + XDES_FLST_NODE); if (UNIV_UNLIKELY(init_xdes)) { @@ -1004,9 +1005,9 @@ fsp_alloc_free_extent( mtr); } - flst_remove(header, FSP_HEADER_OFFSET + FSP_FREE, - desc_block, uint16_t(descr - desc_block->frame) - + XDES_FLST_NODE, mtr); + flst_remove(header, FSP_HEADER_OFFSET + FSP_FREE, desc_block, + static_cast<uint16_t>( + descr - desc_block->frame + XDES_FLST_NODE), mtr); space->free_len--; *xdes = desc_block; @@ -1034,8 +1035,8 @@ fsp_alloc_from_free_frag(buf_block_t *header, buf_block_t *xdes, xdes_t *descr, if (xdes_is_full(descr)) { /* The fragment is full: move it to another list */ - const uint16_t xoffset= XDES_FLST_NODE - + uint16_t(descr - xdes->frame); + const uint16_t xoffset= static_cast<uint16_t>( + descr - xdes->frame + XDES_FLST_NODE); flst_remove(header, FSP_HEADER_OFFSET + FSP_FREE_FRAG, xdes, xoffset, mtr); xdes_set_state(*xdes, descr, XDES_FULL_FRAG, mtr); @@ -1141,8 +1142,9 @@ fsp_alloc_free_page( xdes_set_state(*xdes, descr, XDES_FREE_FRAG, mtr); flst_add_last(block, FSP_HEADER_OFFSET + FSP_FREE_FRAG, - xdes, XDES_FLST_NODE - + uint16_t(descr - xdes->frame), mtr); + xdes, static_cast<uint16_t>( + descr - xdes->frame + + XDES_FLST_NODE), mtr); } else { descr = xdes_lst_get_descriptor(space, first, &xdes, mtr); @@ -1262,7 +1264,8 @@ static void fsp_free_page(fil_space_t* space, page_no_t offset, mtr_t* mtr) frag_n_used = mach_read_from_4(FSP_HEADER_OFFSET + FSP_FRAG_N_USED + header->frame); - const uint16_t xoffset= XDES_FLST_NODE + uint16_t(descr - xdes->frame); + const uint16_t xoffset= static_cast<uint16_t>(descr - xdes->frame + + XDES_FLST_NODE); if (state == XDES_FULL_FRAG) { /* The fragment was full: move it to another list */ @@ -1306,7 +1309,8 @@ static void fsp_free_extent(fil_space_t* space, page_no_t offset, mtr_t* mtr) xdes_init(*xdes, descr, mtr); flst_add_last(block, FSP_HEADER_OFFSET + FSP_FREE, - xdes, XDES_FLST_NODE + uint16_t(descr - xdes->frame), mtr); + xdes, static_cast<uint16_t>(descr - xdes->frame + + XDES_FLST_NODE), mtr); space->free_len++; } @@ -1913,10 +1917,11 @@ fseg_fill_free_list( == FSEG_MAGIC_N_VALUE); mtr->write<8>(*xdes, descr + XDES_ID, seg_id); - flst_add_last(iblock, FSEG_FREE - + uint16_t(inode - iblock->frame), - xdes, XDES_FLST_NODE - + uint16_t(descr - xdes->frame), mtr); + flst_add_last(iblock, + static_cast<uint16_t>(inode - iblock->frame + + FSEG_FREE), xdes, + static_cast<uint16_t>(descr - xdes->frame + + XDES_FLST_NODE), mtr); hint += FSP_EXTENT_SIZE; } } @@ -1967,10 +1972,11 @@ fseg_alloc_free_extent( xdes_set_state(**xdes, descr, XDES_FSEG, mtr); mtr->write<8,mtr_t::OPT>(**xdes, descr + XDES_ID, seg_id); - flst_add_last(iblock, FSEG_FREE - + uint16_t(inode - iblock->frame), - *xdes, XDES_FLST_NODE - + uint16_t(descr - (*xdes)->frame), mtr); + flst_add_last(iblock, + static_cast<uint16_t>(inode - iblock->frame + + FSEG_FREE), *xdes, + static_cast<uint16_t>(descr - (*xdes)->frame + + XDES_FLST_NODE), mtr); /* Try to fill the segment free list */ fseg_fill_free_list(inode, iblock, space, @@ -2076,10 +2082,11 @@ take_hinted_page: xdes_set_state(*xdes, ret_descr, XDES_FSEG, mtr); mtr->write<8,mtr_t::OPT>(*xdes, ret_descr + XDES_ID, seg_id); - flst_add_last(iblock, FSEG_FREE - + uint16_t(seg_inode - iblock->frame), - xdes, XDES_FLST_NODE - + uint16_t(ret_descr - xdes->frame), mtr); + flst_add_last(iblock, + static_cast<uint16_t>(seg_inode - iblock->frame + + FSEG_FREE), xdes, + static_cast<uint16_t>(ret_descr - xdes->frame + + XDES_FLST_NODE), mtr); /* Try to fill the segment free list */ fseg_fill_free_list(seg_inode, iblock, space, @@ -2566,14 +2573,16 @@ fseg_free_page_low( byte* p_not_full = seg_inode + FSEG_NOT_FULL_N_USED; uint32_t not_full_n_used = mach_read_from_4(p_not_full); - const uint16_t xoffset= XDES_FLST_NODE + uint16_t(descr - xdes->frame); + const uint16_t xoffset= uint16_t(descr - xdes->frame + XDES_FLST_NODE); const uint16_t ioffset= uint16_t(seg_inode - iblock->frame); if (xdes_is_full(descr)) { /* The fragment is full: move it to another list */ - flst_remove(iblock, FSEG_FULL + ioffset, xdes, xoffset, mtr); - flst_add_last(iblock, FSEG_NOT_FULL + ioffset, xdes, xoffset, - mtr); + flst_remove(iblock, static_cast<uint16_t>(FSEG_FULL + ioffset), + xdes, xoffset, mtr); + flst_add_last(iblock, static_cast<uint16_t>(FSEG_NOT_FULL + + ioffset), + xdes, xoffset, mtr); not_full_n_used += FSP_EXTENT_SIZE - 1; } else { ut_a(not_full_n_used > 0); @@ -2588,8 +2597,9 @@ fseg_free_page_low( if (!xdes_get_n_used(descr)) { /* The extent has become free: free it to space */ - flst_remove(iblock, FSEG_NOT_FULL + ioffset, xdes, xoffset, - mtr); + flst_remove(iblock, static_cast<uint16_t>(FSEG_NOT_FULL + + ioffset), + xdes, xoffset, mtr); fsp_free_extent(space, offset, mtr); } } @@ -2717,17 +2727,19 @@ fseg_free_extent( } #endif /* BTR_CUR_HASH_ADAPT */ - const uint16_t xoffset= XDES_FLST_NODE + uint16_t(descr - xdes->frame); + const uint16_t xoffset= uint16_t(descr - xdes->frame + XDES_FLST_NODE); const uint16_t ioffset= uint16_t(seg_inode - iblock->frame); if (xdes_is_full(descr)) { - flst_remove(iblock, FSEG_FULL + ioffset, xdes, xoffset, mtr); + flst_remove(iblock, static_cast<uint16_t>(FSEG_FULL + ioffset), + xdes, xoffset, mtr); } else if (!xdes_get_n_used(descr)) { - flst_remove(iblock, FSEG_FREE + ioffset, xdes, xoffset, mtr); + flst_remove(iblock, static_cast<uint16_t>(FSEG_FREE + ioffset), + xdes, xoffset, mtr); } else { - flst_remove(iblock, FSEG_NOT_FULL + ioffset, xdes, xoffset, - mtr); - + flst_remove(iblock, static_cast<uint16_t>(FSEG_NOT_FULL + + ioffset), + xdes, xoffset, mtr); ulint not_full_n_used = mach_read_from_4( FSEG_NOT_FULL_N_USED + seg_inode); ulint descr_n_used = xdes_get_n_used(descr); diff --git a/storage/innobase/fts/fts0que.cc b/storage/innobase/fts/fts0que.cc index afd2e894017..c912f5e0764 100644 --- a/storage/innobase/fts/fts0que.cc +++ b/storage/innobase/fts/fts0que.cc @@ -606,7 +606,8 @@ fts_ranking_words_add( /* Set ranking words */ ut_ad(byte_offset < ranking->words_len); bit_offset = pos % CHAR_BIT; - ranking->words[byte_offset] |= 1 << bit_offset; + ranking->words[byte_offset] = static_cast<byte>( + ranking->words[byte_offset] | 1 << bit_offset); } /*******************************************************************//** diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index d054657ccb4..766fece542e 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -5791,8 +5791,9 @@ initialize_auto_increment(dict_table_t* table, const Field* field) mutex_enter(&table->autoinc_mutex); - table->persistent_autoinc = 1 - + dict_table_get_nth_col_pos(table, col_no, NULL); + table->persistent_autoinc = static_cast<uint16_t>( + dict_table_get_nth_col_pos(table, col_no, NULL) + 1) + & dict_index_t::MAX_N_FIELDS; if (table->autoinc) { /* Already initialized. Our caller checked @@ -6567,7 +6568,7 @@ VARCHAR and the new true VARCHAR in >= 5.0.3 by the 'prtype'. ENUM and SET, and unsigned integer types are 'unsigned types' @param[in] f MySQL Field @return DATA_BINARY, DATA_VARCHAR, ... */ -unsigned +uint8_t get_innobase_type_from_mysql_type(unsigned *unsigned_flag, const Field *field) { /* The following asserts try to check that the MySQL type code fits in @@ -6702,7 +6703,7 @@ wsrep_store_key_val_for_row( char* buff_start = buff; enum_field_types mysql_type; Field* field; - uint buff_space = buff_len; + ulint buff_space = buff_len; DBUG_ENTER("wsrep_store_key_val_for_row"); @@ -7328,7 +7329,8 @@ ha_innobase::build_template( m_prebuilt->template_type = whole_row ? ROW_MYSQL_WHOLE_ROW : ROW_MYSQL_REC_FIELDS; - m_prebuilt->null_bitmap_len = table->s->null_bytes; + m_prebuilt->null_bitmap_len = table->s->null_bytes + & dict_index_t::MAX_N_FIELDS; /* Prepare to build m_prebuilt->mysql_template[]. */ m_prebuilt->templ_contains_blob = FALSE; @@ -8048,7 +8050,7 @@ calc_row_difference( ibool changes_fts_doc_col = FALSE; trx_t* const trx = prebuilt->trx; doc_id_t doc_id = FTS_NULL_DOC_ID; - unsigned num_v = 0; + uint16_t num_v = 0; const bool skip_virtual = ha_innobase::omits_virtual_cols(*table->s); ut_ad(!srv_read_only_mode); @@ -8280,7 +8282,7 @@ calc_row_difference( num_v++; ut_ad(field != table->found_next_number_field); } else { - ufield->field_no = static_cast<unsigned>( + ufield->field_no = static_cast<uint16_t>( dict_col_get_clust_pos( &prebuilt->table->cols [i - num_v], @@ -10277,7 +10279,8 @@ ha_innobase::wsrep_append_keys( keyval1, /* for len1+1 see keyval1 initialization comment */ - len1+1, key_type); + uint16_t(len1+1), + key_type); if (rcode) DBUG_RETURN(rcode); } @@ -10289,7 +10292,8 @@ ha_innobase::wsrep_append_keys( thd, trx, table_share, /* for len0+1 see keyval0 initialization comment */ - keyval0, len0+1, key_type); + keyval0, uint16_t(len0+1), + key_type); if (rcode) DBUG_RETURN(rcode); @@ -10457,7 +10461,8 @@ prepare_vcol_for_base_setup( bitmap_clear_all(&field->table->tmp_set); field->vcol_info->expr->walk( &Item::register_field_in_read_map, 1, field->table); - col->num_base= bitmap_bits_set(&field->table->tmp_set); + col->num_base= bitmap_bits_set(&field->table->tmp_set) + & dict_index_t::MAX_N_FIELDS; if (col->num_base != 0) { col->base_col = static_cast<dict_col_t**>(mem_heap_zalloc( table->heap, col->num_base * sizeof( @@ -10477,7 +10482,7 @@ innodb_base_col_setup( const Field* field, dict_v_col_t* v_col) { - unsigned n = 0; + uint16_t n = 0; prepare_vcol_for_base_setup(table, field, v_col); @@ -10502,7 +10507,7 @@ innodb_base_col_setup( n++; } } - v_col->num_base= n; + v_col->num_base= n & dict_index_t::MAX_N_FIELDS; } /** Set up base columns for stored column @@ -11895,7 +11900,8 @@ innobase_parse_hint_from_comment( /* x-lock index is needed to exclude concurrent pessimistic tree operations */ rw_lock_x_lock(dict_index_get_lock(index)); - index->merge_threshold = merge_threshold_table; + index->merge_threshold = merge_threshold_table + & ((1U << 6) - 1); rw_lock_x_unlock(dict_index_get_lock(index)); continue; @@ -11915,7 +11921,8 @@ innobase_parse_hint_from_comment( pessimistic tree operations */ rw_lock_x_lock(dict_index_get_lock(index)); index->merge_threshold - = merge_threshold_index[i]; + = merge_threshold_index[i] + & ((1U << 6) - 1); rw_lock_x_unlock(dict_index_get_lock(index)); is_found[i] = true; @@ -12411,7 +12418,7 @@ create_table_info_t::create_foreign_keys() dict_mem_foreign_table_name_lookup_set(foreign, TRUE); foreign->foreign_index = index; - foreign->n_fields = (unsigned int)i; + foreign->n_fields = i & dict_index_t::MAX_N_FIELDS; foreign->foreign_col_names = static_cast<const char**>( mem_heap_alloc(foreign->heap, i * sizeof(void*))); @@ -13113,9 +13120,12 @@ create_table_info_t::create_table_update_dict() } else { const unsigned col_no = innodb_col_no(ai); - innobase_table->persistent_autoinc = 1 - + dict_table_get_nth_col_pos( - innobase_table, col_no, NULL); + innobase_table->persistent_autoinc + = static_cast<uint16_t>( + dict_table_get_nth_col_pos( + innobase_table, col_no, NULL) + + 1) + & dict_index_t::MAX_N_FIELDS; /* Persist the "last used" value, which typically is AUTO_INCREMENT - 1. @@ -20947,7 +20957,8 @@ innobase_get_computed_value( /* It is a nullable column with a non-NULL value */ mysql_rec[templ->mysql_null_byte_offset] - &= ~(byte) templ->mysql_null_bit_mask; + &= static_cast<byte>( + ~templ->mysql_null_bit_mask); } } } diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc index 12dc0aea0d9..477e1b148ec 100644 --- a/storage/innobase/handler/handler0alter.cc +++ b/storage/innobase/handler/handler0alter.cc @@ -290,12 +290,12 @@ add_metadata: DBUG_ASSERT(instant->dropped[i].is_dropped()); } #endif - const uint n_fields = index.n_fields + n_dropped(); + const unsigned n_fields = index.n_fields + n_dropped(); DBUG_ASSERT(n_fields >= oindex.n_fields); dict_field_t* fields = static_cast<dict_field_t*>( mem_heap_zalloc(heap, n_fields * sizeof *fields)); - uint i = 0, j = 0, n_nullable = 0; + unsigned i = 0, j = 0, n_nullable = 0; ut_d(uint core_null = 0); for (; i < oindex.n_fields; i++) { DBUG_ASSERT(j <= i); @@ -385,11 +385,12 @@ found_j: == fields[i].col->name(*this)); } DBUG_ASSERT(j == index.n_fields); - index.n_fields = index.n_def = n_fields; + index.n_fields = index.n_def = n_fields + & dict_index_t::MAX_N_FIELDS; index.fields = fields; DBUG_ASSERT(n_nullable >= index.n_nullable); DBUG_ASSERT(n_nullable >= oindex.n_nullable); - index.n_nullable = n_nullable; + index.n_nullable = n_nullable & dict_index_t::MAX_N_FIELDS; goto set_core_fields; } @@ -497,7 +498,7 @@ inline bool dict_table_t::instant_column(const dict_table_t& table, /* Preserve the default values of previously instantly added columns, or copy the new default values to this->heap. */ - for (unsigned i = 0; i < table.n_cols; i++) { + for (uint16_t i = 0; i < table.n_cols; i++) { dict_col_t& c = cols[i]; if (const dict_col_t* o = find(old_cols, col_map, n_cols, i)) { @@ -511,10 +512,10 @@ inline bool dict_table_t::instant_column(const dict_table_t& table, if (o->vers_sys_start()) { ut_ad(o->ind == vers_start); - vers_start = i; + vers_start = i & dict_index_t::MAX_N_FIELDS; } else if (o->vers_sys_end()) { ut_ad(o->ind == vers_end); - vers_end = i; + vers_end = i & dict_index_t::MAX_N_FIELDS; } continue; } @@ -532,8 +533,10 @@ inline bool dict_table_t::instant_column(const dict_table_t& table, } } - n_t_def += table.n_cols - n_cols; - n_t_cols += table.n_cols - n_cols; + n_t_def = (n_t_def + (table.n_cols - n_cols)) + & dict_index_t::MAX_N_FIELDS; + n_t_cols = (n_t_cols + (table.n_cols - n_cols)) + & dict_index_t::MAX_N_FIELDS; n_def = table.n_cols; const dict_v_col_t* const old_v_cols = v_cols; @@ -555,8 +558,10 @@ inline bool dict_table_t::instant_column(const dict_table_t& table, v_cols = NULL; } - n_t_def += table.n_v_cols - n_v_cols; - n_t_cols += table.n_v_cols - n_v_cols; + n_t_def = (n_t_def + (table.n_v_cols - n_v_cols)) + & dict_index_t::MAX_N_FIELDS; + n_t_cols = (n_t_cols + (table.n_v_cols - n_v_cols)) + & dict_index_t::MAX_N_FIELDS; n_v_def = table.n_v_cols; for (unsigned i = 0; i < n_v_def; i++) { @@ -745,12 +750,14 @@ inline void dict_table_t::rollback_instant( v_cols[i].~dict_v_col_t(); } - index->n_core_fields = (index->n_fields == index->n_core_fields) - ? old_n_fields - : old_n_core_fields; - index->n_def = index->n_fields = old_n_fields; - index->n_core_null_bytes = UT_BITS_IN_BYTES( - index->get_n_nullable(index->n_core_fields)); + index->n_core_fields = ((index->n_fields == index->n_core_fields) + ? old_n_fields + : old_n_core_fields) + & dict_index_t::MAX_N_FIELDS; + index->n_def = index->n_fields = old_n_fields + & dict_index_t::MAX_N_FIELDS; + index->n_core_null_bytes = static_cast<uint8_t>( + UT_BITS_IN_BYTES(index->get_n_nullable(index->n_core_fields))); const dict_col_t* const new_cols = cols; const dict_col_t* const new_cols_end __attribute__((unused)) = cols + n_cols; @@ -761,16 +768,16 @@ inline void dict_table_t::rollback_instant( col_names = old_col_names; v_cols = old_v_cols; v_col_names = old_v_col_names; - n_def = n_cols = old_n_cols; - n_v_def = n_v_cols = old_n_v_cols; - n_t_def = n_t_cols = n_cols + n_v_cols; + n_def = n_cols = old_n_cols & dict_index_t::MAX_N_FIELDS; + n_v_def = n_v_cols = old_n_v_cols & dict_index_t::MAX_N_FIELDS; + n_t_def = n_t_cols = (n_cols + n_v_cols) & dict_index_t::MAX_N_FIELDS; if (versioned()) { for (unsigned i = 0; i < n_cols; ++i) { if (cols[i].vers_sys_start()) { - vers_start = i; + vers_start = i & dict_index_t::MAX_N_FIELDS; } else if (cols[i].vers_sys_end()) { - vers_end = i; + vers_end = i & dict_index_t::MAX_N_FIELDS; } } } @@ -2519,7 +2526,8 @@ innobase_init_foreign( dict_mem_foreign_table_name_lookup_set(foreign, TRUE); foreign->foreign_index = index; - foreign->n_fields = (unsigned int) num_field; + foreign->n_fields = static_cast<unsigned>(num_field) + & dict_index_t::MAX_N_FIELDS; foreign->foreign_col_names = static_cast<const char**>( mem_heap_alloc(foreign->heap, num_field * sizeof(void*))); @@ -4287,13 +4295,14 @@ innobase_build_col_map( } col_map[old_i - num_old_v] = i; - if (old_table->versioned() - && altered_table->versioned()) { - if (old_i == old_table->vers_start) { - new_table->vers_start = i + num_v; - } else if (old_i == old_table->vers_end) { - new_table->vers_end = i + num_v; - } + if (!old_table->versioned() + || !altered_table->versioned()) { + } else if (old_i == old_table->vers_start) { + new_table->vers_start = (i + num_v) + & dict_index_t::MAX_N_FIELDS; + } else if (old_i == old_table->vers_end) { + new_table->vers_end = (i + num_v) + & dict_index_t::MAX_N_FIELDS; } goto found_col; } @@ -4767,7 +4776,7 @@ prepare_inplace_add_virtual( const TABLE* table) { ha_innobase_inplace_ctx* ctx; - unsigned i = 0, j = 0; + uint16_t i = 0, j = 0; ctx = static_cast<ha_innobase_inplace_ctx*> (ha_alter_info->handler_ctx); @@ -4843,14 +4852,16 @@ prepare_inplace_add_virtual( ctx->add_vcol[j].m_col.mtype = col_type; - ctx->add_vcol[j].m_col.len = col_len; + ctx->add_vcol[j].m_col.len = static_cast<uint16_t>(col_len); - ctx->add_vcol[j].m_col.ind = i - 1; + ctx->add_vcol[j].m_col.ind = (i - 1) + & dict_index_t::MAX_N_FIELDS; ctx->add_vcol[j].num_base = 0; ctx->add_vcol_name[j] = field->field_name.str; ctx->add_vcol[j].base_col = NULL; - ctx->add_vcol[j].v_pos = ctx->old_table->n_v_cols - - ctx->num_to_drop_vcol + j; + ctx->add_vcol[j].v_pos = (ctx->old_table->n_v_cols + - ctx->num_to_drop_vcol + j) + & dict_index_t::MAX_N_FIELDS; ctx->add_vcol[j].n_v_indexes = 0; /* MDEV-17468: Do this on ctx->instant_table later */ @@ -4953,9 +4964,9 @@ prepare_inplace_drop_virtual( ctx->drop_vcol[j].m_col.mtype = col_type; - ctx->drop_vcol[j].m_col.len = col_len; + ctx->drop_vcol[j].m_col.len = static_cast<uint16_t>(col_len); - ctx->drop_vcol[j].m_col.ind = i; + ctx->drop_vcol[j].m_col.ind = i & dict_index_t::MAX_N_FIELDS; ctx->drop_vcol_name[j] = field->field_name.str; @@ -5732,7 +5743,7 @@ add_all_virtual: /* Reserve room for DB_TRX_ID,DB_ROLL_PTR and any non-updated off-page columns in case they are moved off page as a result of the update. */ - const unsigned f = user_table->instant != NULL; + const uint16_t f = user_table->instant != NULL; upd_t* update = upd_create(index->n_fields + f, ctx->heap); update->n_fields = n + f; update->info_bits = f @@ -5751,7 +5762,7 @@ add_all_virtual: for (unsigned k = n_old_fields; k < index->n_fields; k++) { upd_field_t* uf = upd_get_nth_field(update, j++); - uf->field_no = k + f; + uf->field_no = static_cast<uint16_t>(k + f); uf->new_val = entry->fields[k + f]; ut_ad(j <= n + f); @@ -6036,8 +6047,8 @@ prepare_inplace_alter_table_dict( unsigned mbminlen, mbmaxlen; dtype_get_mblen(col.mtype, col.prtype, &mbminlen, &mbmaxlen); - col.mbminlen = mbminlen; - col.mbmaxlen = mbmaxlen; + col.mbminlen = mbminlen & 7; + col.mbmaxlen = mbmaxlen & 7; } add_v = static_cast<dict_add_v_col_t*>( mem_heap_alloc(ctx->heap, sizeof *add_v)); @@ -6712,9 +6723,10 @@ error_handling_drop_uncached_1: if (const Field* ai = altered_table->found_next_number_field) { const unsigned col_no = innodb_col_no(ai); - ctx->new_table->persistent_autoinc = 1 - + dict_table_get_nth_col_pos( - ctx->new_table, col_no, NULL); + ctx->new_table->persistent_autoinc = + (dict_table_get_nth_col_pos( + ctx->new_table, col_no, NULL) + 1) + & dict_index_t::MAX_N_FIELDS; /* Initialize the AUTO_INCREMENT sequence to the rebuilt table from the old one. */ @@ -8964,14 +8976,15 @@ processed_field: } /** Convert field type and length to InnoDB format */ -static void get_type(const Field& f, uint& prtype, uint& mtype, uint& len) +static void get_type(const Field& f, uint& prtype, uint8_t& mtype, + uint16_t& len) { mtype = get_innobase_type_from_mysql_type(&prtype, &f); - len = f.pack_length(); + len = static_cast<uint16_t>(f.pack_length()); prtype |= f.type(); if (f.type() == MYSQL_TYPE_VARCHAR) { auto l = static_cast<const Field_varstring&>(f).length_bytes; - len -= l; + len = static_cast<uint16_t>(len - l); if (l == 2) prtype |= DATA_LONG_TRUE_VARCHAR; } if (!f.real_maybe_null()) prtype |= DATA_NOT_NULL; @@ -8988,7 +9001,7 @@ static void get_type(const Field& f, uint& prtype, uint& mtype, uint& len) if (!f.stored_in_db()) prtype |= DATA_VIRTUAL; if (dtype_is_string_type(mtype)) { - prtype |= ulint(f.charset()->number) << 16; + prtype |= f.charset()->number << 16; } } @@ -9033,7 +9046,9 @@ innobase_rename_or_enlarge_column_try( n_base = 0; } - unsigned prtype, mtype, len; + unsigned prtype; + uint8_t mtype; + uint16_t len; get_type(f, prtype, mtype, len); DBUG_ASSERT(!dtype_is_string_type(col->mtype) || col->mbminlen == f.charset()->mbminlen); @@ -9187,7 +9202,9 @@ innobase_rename_or_enlarge_columns_cache( DBUG_ASSERT(col->mbminlen == (is_string ? (*af)->charset()->mbminlen : 0)); - unsigned prtype, mtype, len; + unsigned prtype; + uint8_t mtype; + uint16_t len; get_type(**af, prtype, mtype, len); DBUG_ASSERT(is_string == dtype_is_string_type(mtype)); @@ -9195,7 +9212,7 @@ innobase_rename_or_enlarge_columns_cache( col->mtype = mtype; col->len = len; col->mbmaxlen = is_string - ? (*af)->charset()->mbmaxlen : 0; + ? (*af)->charset()->mbmaxlen & 7: 0; if ((*fp)->flags & FIELD_IS_RENAMED) { dict_mem_table_col_rename( @@ -10117,11 +10134,22 @@ commit_cache_norebuild( if (ctx->page_compression_level) { DBUG_ASSERT(ctx->new_table->space != fil_system.sys_space); - ctx->new_table->flags &= - ~(0xFU << DICT_TF_POS_PAGE_COMPRESSION_LEVEL); - ctx->new_table->flags |= 1 << DICT_TF_POS_PAGE_COMPRESSION - | (ctx->page_compression_level - << DICT_TF_POS_PAGE_COMPRESSION_LEVEL); +#if defined __GNUC__ && !defined __clang__ && __GNUC__ < 6 +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wconversion" /* GCC 4 and 5 need this here */ +#endif + ctx->new_table->flags + = static_cast<uint16_t>( + (ctx->new_table->flags + & ~(0xFU + << DICT_TF_POS_PAGE_COMPRESSION_LEVEL)) + | 1 << DICT_TF_POS_PAGE_COMPRESSION + | (ctx->page_compression_level & 0xF) + << DICT_TF_POS_PAGE_COMPRESSION_LEVEL) + & ((1U << DICT_TF_BITS) - 1); +#if defined __GNUC__ && !defined __clang__ && __GNUC__ < 6 +# pragma GCC diagnostic pop +#endif if (fil_space_t* space = ctx->new_table->space) { bool update = !(space->flags diff --git a/storage/innobase/handler/i_s.cc b/storage/innobase/handler/i_s.cc index 33ac0b47dc4..0f74e85c088 100644 --- a/storage/innobase/handler/i_s.cc +++ b/storage/innobase/handler/i_s.cc @@ -119,7 +119,7 @@ struct buf_page_info_t{ unsigned access_time:32; /*!< Time of first access */ unsigned flush_type:2; /*!< Flush type */ unsigned io_fix:2; /*!< type of pending I/O operation */ - unsigned fix_count:19; /*!< Count of how manyfold this block + uint32_t fix_count; /*!< Count of how manyfold this block is bufferfixed */ #ifdef BTR_CUR_HASH_ADAPT unsigned hashed:1; /*!< Whether hash index has been @@ -4118,13 +4118,13 @@ i_s_innodb_set_page_type( page_info->page_type = I_S_PAGE_TYPE_INDEX; } - page_info->data_size = unsigned(page_header_get_field( + page_info->data_size = uint16_t(page_header_get_field( page, PAGE_HEAP_TOP) - (page_is_comp(page) ? PAGE_NEW_SUPREMUM_END : PAGE_OLD_SUPREMUM_END) - page_header_get_field(page, PAGE_GARBAGE)); - page_info->num_recs = page_get_n_recs(page); + page_info->num_recs = page_get_n_recs(page) & ((1U << 14) - 1); } else if (page_type > FIL_PAGE_TYPE_LAST) { /* Encountered an unknown page type */ page_info->page_type = I_S_PAGE_TYPE_UNKNOWN; @@ -4133,7 +4133,7 @@ i_s_innodb_set_page_type( i_s_page_type[] array */ ut_a(page_type == i_s_page_type[page_type].type_value); - page_info->page_type = page_type; + page_info->page_type = page_type & 0xf; } if (page_info->page_type == FIL_PAGE_TYPE_ZBLOB @@ -4161,7 +4161,7 @@ i_s_innodb_buffer_page_get_info( { page_info->block_id = pos; - page_info->page_state = buf_page_get_state(bpage); + page_info->page_state = buf_page_get_state(bpage) & 7; /* Only fetch information for buffers that map to a tablespace, that is, buffer page with state BUF_BLOCK_ZIP_PAGE, @@ -4183,7 +4183,7 @@ i_s_innodb_buffer_page_get_info( page_info->zip_ssize = bpage->zip.ssize; - page_info->io_fix = bpage->io_fix; + page_info->io_fix = bpage->io_fix & 3; page_info->is_old = bpage->old; @@ -6604,7 +6604,7 @@ i_s_dict_fill_sys_tablespaces( ut_free(filepath); } - if (file.m_total_size == static_cast<os_offset_t>(~0)) { + if (file.m_total_size == os_offset_t(~0)) { stat.block_size = 0; file.m_total_size = 0; file.m_alloc_size = 0; diff --git a/storage/innobase/ibuf/ibuf0ibuf.cc b/storage/innobase/ibuf/ibuf0ibuf.cc index 66db3c0c832..1f5f172b1d4 100644 --- a/storage/innobase/ibuf/ibuf0ibuf.cc +++ b/storage/innobase/ibuf/ibuf0ibuf.cc @@ -637,13 +637,13 @@ ibuf_bitmap_page_set_bits( if (bit == IBUF_BITMAP_FREE) { ut_ad(bit_offset + 1 < 8); ut_ad(val <= 3); - b &= ~(3U << bit_offset); - b |= ((val & 2) >> 1) << bit_offset - | (val & 1) << (bit_offset + 1); + b &= static_cast<byte>(~(3U << bit_offset)); + b |= static_cast<byte>(((val & 2) >> 1) << bit_offset + | (val & 1) << (bit_offset + 1)); } else { ut_ad(val <= 1); - b &= ~(1U << bit_offset); - b |= val << bit_offset; + b &= static_cast<byte>(~(1U << bit_offset)); + b |= static_cast<byte>(val << bit_offset); } mtr->write<1,mtr_t::OPT>(*block, map_byte, b); @@ -1431,8 +1431,8 @@ ibuf_build_entry_from_ibuf_rec_func( ibuf_dummy_index_add_col(index, dfield_get_type(field), len); } - index->n_core_null_bytes - = UT_BITS_IN_BYTES(unsigned(index->n_nullable)); + index->n_core_null_bytes = static_cast<uint8_t>( + UT_BITS_IN_BYTES(unsigned(index->n_nullable))); /* Prevent an ut_ad() failure in page_zip_write_rec() by adding system columns to the dummy table pointed to by the @@ -3798,7 +3798,7 @@ dump: /* Copy the info bits. Clear the delete-mark. */ update->info_bits = rec_get_info_bits(rec, page_is_comp(page)); - update->info_bits &= ~REC_INFO_DELETED_FLAG; + update->info_bits &= byte(~REC_INFO_DELETED_FLAG); page_zip_des_t* page_zip = buf_block_get_page_zip(block); /* We cannot invoke btr_cur_optimistic_update() here, diff --git a/storage/innobase/include/btr0sea.h b/storage/innobase/include/btr0sea.h index 8bbfe18c5d9..32386c02d5f 100644 --- a/storage/innobase/include/btr0sea.h +++ b/storage/innobase/include/btr0sea.h @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2017, 2018, MariaDB Corporation. +Copyright (c) 2017, 2020, MariaDB Corporation. 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 the Free Software @@ -245,9 +245,9 @@ struct btr_search_t{ btr_search_info_create(). */ /*---------------------- @{ */ - ulint n_fields; /*!< recommended prefix length for hash search: + uint16_t n_fields; /*!< recommended prefix length for hash search: number of full fields */ - ulint n_bytes; /*!< recommended prefix: number of bytes in + uint16_t n_bytes; /*!< recommended prefix: number of bytes in an incomplete field @see BTR_PAGE_MAX_REC_SIZE */ bool left_side; /*!< true or false, depending on whether diff --git a/storage/innobase/include/buf0buf.h b/storage/innobase/include/buf0buf.h index 3afb6e49431..0912308ffcc 100644 --- a/storage/innobase/include/buf0buf.h +++ b/storage/innobase/include/buf0buf.h @@ -1445,13 +1445,13 @@ struct buf_block_t{ NOTE that these fields are NOT protected by any semaphore! */ /* @{ */ - ulint n_hash_helps; /*!< counter which controls building - of a new hash index for the page */ - volatile ulint n_bytes; /*!< recommended prefix length for hash + volatile uint16_t n_bytes; /*!< recommended prefix length for hash search: number of bytes in an incomplete last field */ - volatile ulint n_fields; /*!< recommended prefix length for hash + volatile uint16_t n_fields; /*!< recommended prefix length for hash search: number of full fields */ + uint16_t n_hash_helps; /*!< counter which controls building + of a new hash index for the page */ volatile bool left_side; /*!< true or false, depending on whether the leftmost record of several records with the same prefix should be diff --git a/storage/innobase/include/buf0buf.ic b/storage/innobase/include/buf0buf.ic index cc25ab2c2ca..55fe7d74760 100644 --- a/storage/innobase/include/buf0buf.ic +++ b/storage/innobase/include/buf0buf.ic @@ -354,7 +354,7 @@ buf_page_set_flush_type( buf_page_t* bpage, /*!< in: buffer page */ buf_flush_t flush_type) /*!< in: flush type */ { - bpage->flush_type = flush_type; + bpage->flush_type = flush_type & 3; ut_ad(buf_page_get_flush_type(bpage) == flush_type); } diff --git a/storage/innobase/include/data0data.ic b/storage/innobase/include/data0data.ic index 92be8f8c589..857ffc15d76 100644 --- a/storage/innobase/include/data0data.ic +++ b/storage/innobase/include/data0data.ic @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 1994, 2015, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2017, 2019, MariaDB Corporation. +Copyright (c) 2017, 2020, MariaDB Corporation. 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 the Free Software @@ -66,7 +66,6 @@ spatial_status_t dfield_get_spatial_status( const dfield_t* field) { - ut_ad(field); ut_ad(dfield_is_ext(field)); return(static_cast<spatial_status_t>(field->spatial_status)); @@ -81,10 +80,8 @@ dfield_set_spatial_status( dfield_t* field, spatial_status_t spatial_status) { - ut_ad(field); - ut_ad(dfield_is_ext(field)); - - field->spatial_status = spatial_status; + field->spatial_status = spatial_status & 3; + ut_ad(dfield_get_spatial_status(field) == spatial_status); } /*********************************************************************//** diff --git a/storage/innobase/include/data0type.h b/storage/innobase/include/data0type.h index edeee0c8f07..750c35341d6 100644 --- a/storage/innobase/include/data0type.h +++ b/storage/innobase/include/data0type.h @@ -181,7 +181,8 @@ be less than 256 */ BLOB columns. */ #define DATA_GIS_MBR 2048U /* Used as GIS MBR column */ -#define DATA_MBR_LEN SPDIMS * 2 * sizeof(double) /* GIS MBR length*/ +/** the size of a GIS maximum bounding rectangle */ +constexpr uint8_t DATA_MBR_LEN= uint8_t(SPDIMS * 2 * sizeof(double)); #define DATA_LONG_TRUE_VARCHAR 4096U /* this is ORed to the precise data type when the column is true VARCHAR where diff --git a/storage/innobase/include/data0type.ic b/storage/innobase/include/data0type.ic index f5a1eb22d66..b81b68e69e9 100644 --- a/storage/innobase/include/data0type.ic +++ b/storage/innobase/include/data0type.ic @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 1996, 2014, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2017, 2019, MariaDB Corporation. +Copyright (c) 2017, 2020, MariaDB Corporation. 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 the Free Software @@ -119,9 +119,9 @@ dtype_set( ut_ad(type); ut_ad(mtype <= DATA_MTYPE_MAX); - type->mtype = unsigned(mtype); - type->prtype = unsigned(prtype); - type->len = unsigned(len); + type->mtype = static_cast<byte>(mtype); + type->prtype = static_cast<unsigned>(prtype); + type->len = static_cast<uint16_t>(len); dtype_set_mblen(type); } diff --git a/storage/innobase/include/dict0dict.h b/storage/innobase/include/dict0dict.h index 508ef001057..867c0c215f3 100644 --- a/storage/innobase/include/dict0dict.h +++ b/storage/innobase/include/dict0dict.h @@ -921,7 +921,7 @@ inline ulint dict_tf_get_zip_size(ulint flags) inline ulint dict_table_extent_size(const dict_table_t* table) { if (ulint zip_size = table->space->zip_size()) { - return (1ULL << 20) / zip_size; + return (1U << 20) / zip_size; } return FSP_EXTENT_SIZE; @@ -1006,7 +1006,7 @@ Gets the number of fields in the internal representation of an index, including fields added by the dictionary system. @return number of fields */ UNIV_INLINE -unsigned +uint16_t dict_index_get_n_fields( /*====================*/ const dict_index_t* index) /*!< in: an internal @@ -1021,7 +1021,7 @@ we do not take multiversioning into account: in the B-tree use the value returned by dict_index_get_n_unique_in_tree. @return number of fields */ UNIV_INLINE -unsigned +uint16_t dict_index_get_n_unique( /*====================*/ const dict_index_t* index) /*!< in: an internal representation @@ -1033,7 +1033,7 @@ which uniquely determine the position of an index entry in the index, if we also take multiversioning into account. @return number of fields */ UNIV_INLINE -unsigned +uint16_t dict_index_get_n_unique_in_tree( /*============================*/ const dict_index_t* index) /*!< in: an internal representation @@ -1051,7 +1051,7 @@ include page no field. @param[in] index index @return number of fields */ UNIV_INLINE -unsigned +uint16_t dict_index_get_n_unique_in_tree_nonleaf( const dict_index_t* index) MY_ATTRIBUTE((nonnull, warn_unused_result)); @@ -1062,7 +1062,7 @@ unique, but this function returns the number of fields the user defined in the index as ordering fields. @return number of fields */ UNIV_INLINE -unsigned +uint16_t dict_index_get_n_ordering_defined_by_user( /*======================================*/ const dict_index_t* index) /*!< in: an internal representation diff --git a/storage/innobase/include/dict0dict.ic b/storage/innobase/include/dict0dict.ic index b5550263a49..4a006471c37 100644 --- a/storage/innobase/include/dict0dict.ic +++ b/storage/innobase/include/dict0dict.ic @@ -710,7 +710,7 @@ Gets the number of fields in the internal representation of an index, including fields added by the dictionary system. @return number of fields */ UNIV_INLINE -unsigned +uint16_t dict_index_get_n_fields( /*====================*/ const dict_index_t* index) /*!< in: an internal @@ -728,7 +728,7 @@ we do not take multiversioning into account: in the B-tree use the value returned by dict_index_get_n_unique_in_tree. @return number of fields */ UNIV_INLINE -unsigned +uint16_t dict_index_get_n_unique( /*====================*/ const dict_index_t* index) /*!< in: an internal representation @@ -745,7 +745,7 @@ which uniquely determine the position of an index entry in the index, if we also take multiversioning into account. @return number of fields */ UNIV_INLINE -unsigned +uint16_t dict_index_get_n_unique_in_tree( /*============================*/ const dict_index_t* index) /*!< in: an internal representation @@ -770,7 +770,7 @@ include page no field. @param[in] index index @return number of fields */ UNIV_INLINE -unsigned +uint16_t dict_index_get_n_unique_in_tree_nonleaf( const dict_index_t* index) { @@ -794,7 +794,7 @@ to make a clustered index unique, but this function returns the number of fields the user defined in the index as ordering fields. @return number of fields */ UNIV_INLINE -unsigned +uint16_t dict_index_get_n_ordering_defined_by_user( /*======================================*/ const dict_index_t* index) /*!< in: an internal representation @@ -992,7 +992,7 @@ dict_index_set_online_status( } #endif /* UNIV_DEBUG */ - index->online_status = status; + index->online_status = status & 3; ut_ad(dict_index_get_online_status(index) == status); } diff --git a/storage/innobase/include/dict0mem.h b/storage/innobase/include/dict0mem.h index 5e702d42dc7..f358783cc7c 100644 --- a/storage/innobase/include/dict0mem.h +++ b/storage/innobase/include/dict0mem.h @@ -279,7 +279,7 @@ index tables) of a FTS table are in HEX format. */ (table->flags2 & (flag)) #define DICT_TF2_FLAG_UNSET(table, flag) \ - (table->flags2 &= ~(flag)) + (table->flags2 &= ~(flag) & ((1U << DICT_TF2_BITS) - 1)) /** Tables could be chained together with Foreign key constraint. When first load the parent table, we would load all of its descedents. @@ -641,7 +641,7 @@ public: : DATA_BINARY_TYPE; if (fixed) { mtype = DATA_FIXBINARY; - len = fixed; + len = static_cast<uint16_t>(fixed); } else { mtype = DATA_BINARY; len = len2 ? 65535 : 255; @@ -1169,18 +1169,24 @@ struct dict_index_t { bool has_virtual() const { return type & DICT_VIRTUAL; } /** @return the position of DB_TRX_ID */ - unsigned db_trx_id() const { + uint16_t db_trx_id() const { DBUG_ASSERT(is_primary()); DBUG_ASSERT(n_uniq); DBUG_ASSERT(n_uniq <= MAX_REF_PARTS); return n_uniq; } /** @return the position of DB_ROLL_PTR */ - unsigned db_roll_ptr() const { return db_trx_id() + 1; } + uint16_t db_roll_ptr() const + { + return static_cast<uint16_t>(db_trx_id() + 1); + } /** @return the offset of the metadata BLOB field, or the first user field after the PRIMARY KEY,DB_TRX_ID,DB_ROLL_PTR */ - unsigned first_user_field() const { return db_trx_id() + 2; } + uint16_t first_user_field() const + { + return static_cast<uint16_t>(db_trx_id() + 2); + } /** @return whether the index is corrupted */ inline bool is_corrupted() const; @@ -1670,7 +1676,7 @@ class field_map_element_t /** Field metadata */ uint16_t data; - void clear_not_null() { data &= ~NOT_NULL; } + void clear_not_null() { data &= uint16_t(~NOT_NULL); } public: bool is_dropped() const { return data & DROPPED; } void set_dropped() { data |= DROPPED; } @@ -2307,14 +2313,14 @@ inline bool dict_index_t::is_corrupted() const inline void dict_index_t::clear_instant_add() { - DBUG_ASSERT(is_primary()); - DBUG_ASSERT(is_instant()); - DBUG_ASSERT(!table->instant); - for (unsigned i = n_core_fields; i < n_fields; i++) { - fields[i].col->clear_instant(); - } - n_core_fields = n_fields; - n_core_null_bytes = UT_BITS_IN_BYTES(unsigned(n_nullable)); + DBUG_ASSERT(is_primary()); + DBUG_ASSERT(is_instant()); + DBUG_ASSERT(!table->instant); + for (unsigned i= n_core_fields; i < n_fields; i++) + fields[i].col->clear_instant(); + n_core_fields= n_fields; + n_core_null_bytes= static_cast<byte> + (UT_BITS_IN_BYTES(static_cast<unsigned>(n_nullable))); } inline void dict_index_t::clear_instant_alter() @@ -2357,7 +2363,7 @@ inline void dict_index_t::clear_instant_alter() DBUG_ASSERT(&fields[n_fields - table->n_dropped()] == end); n_core_fields = n_fields = n_def = static_cast<unsigned>(end - fields) & MAX_N_FIELDS; - n_core_null_bytes = UT_BITS_IN_BYTES(n_nullable); + n_core_null_bytes = static_cast<byte>(UT_BITS_IN_BYTES(n_nullable)); std::sort(begin, end, [](const dict_field_t& a, const dict_field_t& b) { return a.col->ind < b.col->ind; }); table->instant = NULL; diff --git a/storage/innobase/include/dict0mem.ic b/storage/innobase/include/dict0mem.ic index 090ec73278b..0a554a54dbd 100644 --- a/storage/innobase/include/dict0mem.ic +++ b/storage/innobase/include/dict0mem.ic @@ -54,13 +54,13 @@ dict_mem_fill_index_struct( index->fields = NULL; } - /* Assign a ulint to a 4-bit-mapped field. - Only the low-order 4 bits are assigned. */ - index->type = unsigned(type); + index->type = type & ((1U << DICT_IT_BITS) - 1); index->page = FIL_NULL; index->merge_threshold = DICT_INDEX_MERGE_THRESHOLD_DEFAULT; - index->n_fields = (unsigned int) n_fields; - index->n_core_fields = (unsigned int) n_fields; + index->n_fields = static_cast<unsigned>(n_fields) + & index->MAX_N_FIELDS; + index->n_core_fields = static_cast<unsigned>(n_fields) + & index->MAX_N_FIELDS; /* The '1 +' above prevents allocation of an empty mem block */ index->nulls_equal = false; diff --git a/storage/innobase/include/ha_prototypes.h b/storage/innobase/include/ha_prototypes.h index 17309dc336b..c6bee5ab961 100644 --- a/storage/innobase/include/ha_prototypes.h +++ b/storage/innobase/include/ha_prototypes.h @@ -165,7 +165,7 @@ VARCHAR and the new true VARCHAR in >= 5.0.3 by the 'prtype'. at least ENUM and SET, and unsigned integer types are 'unsigned types' @param[in] f MySQL Field @return DATA_BINARY, DATA_VARCHAR, ... */ -unsigned +uint8_t get_innobase_type_from_mysql_type(unsigned *unsigned_flag, const Field *field); /******************************************************************//** diff --git a/storage/innobase/include/lock0priv.h b/storage/innobase/include/lock0priv.h index 5e00e1bb6f1..29e1a95e10f 100644 --- a/storage/innobase/include/lock0priv.h +++ b/storage/innobase/include/lock0priv.h @@ -521,7 +521,7 @@ inline byte lock_rec_reset_nth_bit(lock_t* lock, ulint i) byte* b = reinterpret_cast<byte*>(&lock[1]) + (i >> 3); byte mask = byte(1U << (i & 7)); byte bit = *b & mask; - *b &= ~mask; + *b &= byte(~mask); if (bit != 0) { ut_ad(lock->trx->lock.n_rec_locks > 0); diff --git a/storage/innobase/include/lock0priv.ic b/storage/innobase/include/lock0priv.ic index 7062e3f7082..1abba6457b3 100644 --- a/storage/innobase/include/lock0priv.ic +++ b/storage/innobase/include/lock0priv.ic @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 2007, 2014, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2018, MariaDB Corporation. +Copyright (c) 2018, 2020, MariaDB Corporation. 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 the Free Software @@ -98,8 +98,14 @@ lock_rec_set_nth_bit( byte_index = i / 8; bit_index = i % 8; - ((byte*) &lock[1])[byte_index] |= 1 << bit_index; - +#if defined __GNUC__ && !defined __clang__ && __GNUC__ < 6 +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wconversion" /* GCC 4 and 5 need this here */ +#endif + ((byte*) &lock[1])[byte_index] |= static_cast<byte>(1 << bit_index); +#if defined __GNUC__ && !defined __clang__ && __GNUC__ < 6 +# pragma GCC diagnostic pop +#endif ++lock->trx->lock.n_rec_locks; } diff --git a/storage/innobase/include/mtr0log.h b/storage/innobase/include/mtr0log.h index 29765faa017..2c7642c4c39 100644 --- a/storage/innobase/include/mtr0log.h +++ b/storage/innobase/include/mtr0log.h @@ -42,7 +42,7 @@ constexpr uint32_t MLOG_DECODE_ERROR= ~0U; inline uint8_t mlog_decode_varint_length(byte first) { uint8_t len= 1; - for (; first & 0x80; len++, first<<= 1); + for (; first & 0x80; len++, first= static_cast<uint8_t>(first << 1)); return len; } @@ -78,6 +78,10 @@ inline uint32_t mlog_decode_varint(const byte* log) @return end of the encoded integer */ inline byte *mlog_encode_varint(byte *log, size_t i) { +#if defined __GNUC__ && !defined __clang__ && __GNUC__ < 6 +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wconversion" /* GCC 4 and 5 need this here */ +#endif if (i < MIN_2BYTE) { } @@ -112,6 +116,9 @@ last3: last2: *log++= static_cast<byte>(i >> 8); } +#if defined __GNUC__ && !defined __clang__ && __GNUC__ < 6 +# pragma GCC diagnostic pop +#endif *log++= static_cast<byte>(i); return log; } diff --git a/storage/innobase/include/mtr0mtr.ic b/storage/innobase/include/mtr0mtr.ic index 016d7c768c2..aee390cf8b2 100644 --- a/storage/innobase/include/mtr0mtr.ic +++ b/storage/innobase/include/mtr0mtr.ic @@ -205,7 +205,7 @@ mtr_t::set_log_mode(mtr_log_t mode) /* MTR_LOG_NO_REDO can only be set before generating any redo log records. */ ut_ad(mode != MTR_LOG_NO_REDO || m_log.empty()); - m_log_mode = mode; + m_log_mode = mode & 3; return(old_mode); } diff --git a/storage/innobase/include/os0file.h b/storage/innobase/include/os0file.h index f6a3ae2224b..a13d511348f 100644 --- a/storage/innobase/include/os0file.h +++ b/storage/innobase/include/os0file.h @@ -248,15 +248,14 @@ public: /** Clear the punch hole flag */ void clear_punch_hole() { - m_type &= ~PUNCH_HOLE; + m_type &= uint16_t(~PUNCH_HOLE); } /** @return true if partial read warning disabled */ bool is_partial_io_warning_disabled() const MY_ATTRIBUTE((warn_unused_result)) { - return((m_type & DISABLE_PARTIAL_IO_WARNINGS) - == DISABLE_PARTIAL_IO_WARNINGS); + return !!(m_type & DISABLE_PARTIAL_IO_WARNINGS); } /** Disable partial read warnings */ diff --git a/storage/innobase/include/page0page.ic b/storage/innobase/include/page0page.ic index 2548356a14a..92b8922ffe0 100644 --- a/storage/innobase/include/page0page.ic +++ b/storage/innobase/include/page0page.ic @@ -575,13 +575,13 @@ page_get_data_size( /*===============*/ const page_t* page) /*!< in: index page */ { - uint16_t ret = page_header_get_field(page, PAGE_HEAP_TOP) + unsigned ret = page_header_get_field(page, PAGE_HEAP_TOP) - (page_is_comp(page) ? PAGE_NEW_SUPREMUM_END : PAGE_OLD_SUPREMUM_END) - page_header_get_field(page, PAGE_GARBAGE); ut_ad(ret < srv_page_size); - return(ret); + return static_cast<uint16_t>(ret); } #ifndef UNIV_INNOCHECKSUM @@ -716,7 +716,7 @@ page_get_instant(const page_t* page) break; } #endif /* UNIV_DEBUG */ - return(i >> 3); + return i / 8; } #endif /* !UNIV_INNOCHECKSUM */ diff --git a/storage/innobase/include/page0zip.ic b/storage/innobase/include/page0zip.ic index 1ca59116407..a59d880284a 100644 --- a/storage/innobase/include/page0zip.ic +++ b/storage/innobase/include/page0zip.ic @@ -133,7 +133,7 @@ page_zip_set_size( for (ssize = 1; size > (512U << ssize); ssize++) { } - page_zip->ssize = ssize; + page_zip->ssize = ssize & ((1U << PAGE_ZIP_SSIZE_BITS) - 1); } else { page_zip->ssize = 0; } diff --git a/storage/innobase/include/pars0pars.h b/storage/innobase/include/pars0pars.h index 73a19dd24d8..03aa72d3be8 100644 --- a/storage/innobase/include/pars0pars.h +++ b/storage/innobase/include/pars0pars.h @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2017, 2019, MariaDB Corporation. +Copyright (c) 2017, 2020, MariaDB Corporation. 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 the Free Software @@ -87,7 +87,7 @@ pars_sql( /*************************************************************//** Retrieves characters to the lexical analyzer. @return number of characters copied or 0 on EOF */ -size_t +int pars_get_lex_chars( /*===============*/ char* buf, /*!< in/out: buffer where to copy */ diff --git a/storage/innobase/include/rem0rec.h b/storage/innobase/include/rem0rec.h index 033f7c94a4b..428503d3c09 100644 --- a/storage/innobase/include/rem0rec.h +++ b/storage/innobase/include/rem0rec.h @@ -63,21 +63,21 @@ The status is stored in the low-order bits. */ #ifndef UNIV_INNOCHECKSUM /** SQL null flag in a 1-byte offset of ROW_FORMAT=REDUNDANT records */ -static const offset_t REC_1BYTE_SQL_NULL_MASK= 0x80; +constexpr offset_t REC_1BYTE_SQL_NULL_MASK= 0x80; /** SQL null flag in a 2-byte offset of ROW_FORMAT=REDUNDANT records */ -static const offset_t REC_2BYTE_SQL_NULL_MASK= 0x8000; +constexpr offset_t REC_2BYTE_SQL_NULL_MASK= 0x8000; /** In a 2-byte offset of ROW_FORMAT=REDUNDANT records, the second most significant bit denotes that the tail of a field is stored off-page. */ -static const offset_t REC_2BYTE_EXTERN_MASK= 0x4000; +constexpr offset_t REC_2BYTE_EXTERN_MASK= 0x4000; -static const size_t RECORD_OFFSET= 2; -static const size_t INDEX_OFFSET= +constexpr size_t RECORD_OFFSET= 2; +constexpr size_t INDEX_OFFSET= RECORD_OFFSET + sizeof(rec_t *) / sizeof(offset_t); #endif /* UNIV_INNOCHECKSUM */ /* Length of the rec_get_offsets() header */ -static const size_t REC_OFFS_HEADER_SIZE= +constexpr size_t REC_OFFS_HEADER_SIZE= #ifdef UNIV_DEBUG #ifndef UNIV_INNOCHECKSUM sizeof(rec_t *) / sizeof(offset_t) + @@ -88,9 +88,9 @@ static const size_t REC_OFFS_HEADER_SIZE= /* Number of elements that should be initially allocated for the offsets[] array, first passed to rec_get_offsets() */ -static const size_t REC_OFFS_NORMAL_SIZE= 300; -static const size_t REC_OFFS_SMALL_SIZE= 18; -static const size_t REC_OFFS_SEC_INDEX_SIZE= +constexpr size_t REC_OFFS_NORMAL_SIZE= 300; +constexpr size_t REC_OFFS_SMALL_SIZE= 18; +constexpr size_t REC_OFFS_SEC_INDEX_SIZE= /* PK max key parts */ 16 + /* sec idx max key parts */ 16 + /* child page number for non-leaf pages */ 1; @@ -117,30 +117,30 @@ enum field_type_t }; /** without 2 upper bits */ -static const offset_t DATA_MASK= 0x3fff; +static constexpr offset_t DATA_MASK= 0x3fff; /** 2 upper bits */ -static const offset_t TYPE_MASK= ~DATA_MASK; +static constexpr offset_t TYPE_MASK= ~DATA_MASK; inline field_type_t get_type(offset_t n) { return static_cast<field_type_t>(n & TYPE_MASK); } inline void set_type(offset_t &n, field_type_t type) { - n= (n & DATA_MASK) | static_cast<offset_t>(type); + n= static_cast<offset_t>((n & DATA_MASK) | type); } inline offset_t get_value(offset_t n) { return n & DATA_MASK; } inline offset_t combine(offset_t value, field_type_t type) { - return get_value(value) | static_cast<offset_t>(type); + return static_cast<offset_t>(get_value(value) | type); } /** Compact flag ORed to the extra size returned by rec_get_offsets() */ -const offset_t REC_OFFS_COMPACT= ~(offset_t(~0) >> 1); +constexpr offset_t REC_OFFS_COMPACT= offset_t(~(offset_t(~0) >> 1)); /** External flag in offsets returned by rec_get_offsets() */ -const offset_t REC_OFFS_EXTERNAL= REC_OFFS_COMPACT >> 1; +constexpr offset_t REC_OFFS_EXTERNAL= REC_OFFS_COMPACT >> 1; /** Default value flag in offsets returned by rec_get_offsets() */ -const offset_t REC_OFFS_DEFAULT= REC_OFFS_COMPACT >> 2; -const offset_t REC_OFFS_MASK= REC_OFFS_DEFAULT - 1; +constexpr offset_t REC_OFFS_DEFAULT= REC_OFFS_COMPACT >> 2; +constexpr offset_t REC_OFFS_MASK= REC_OFFS_DEFAULT - 1; /******************************************************//** The following function is used to get the pointer of the next chained record on the same page. @@ -256,7 +256,7 @@ The following function is used to retrieve the info bits of a record. @return info bits */ UNIV_INLINE -ulint +byte rec_get_info_bits( /*==============*/ const rec_t* rec, /*!< in: physical record */ @@ -278,13 +278,11 @@ rec_get_status(const rec_t* rec) /** Set the status bits of a non-REDUNDANT record. @param[in,out] rec ROW_FORMAT=COMPACT,DYNAMIC,COMPRESSED record @param[in] bits status bits */ -inline -void -rec_set_status(rec_t* rec, byte bits) +inline void rec_set_status(rec_t *rec, byte bits) { - ut_ad(bits <= REC_STATUS_INSTANT); - rec[-REC_NEW_STATUS] = (rec[-REC_NEW_STATUS] & ~REC_NEW_STATUS_MASK) - | bits; + ut_ad(bits <= REC_STATUS_INSTANT); + rec[-REC_NEW_STATUS]= static_cast<byte>((rec[-REC_NEW_STATUS] & + ~REC_NEW_STATUS_MASK) | bits); } /** Get the length of added field count in a REC_STATUS_INSTANT record. @@ -325,7 +323,7 @@ inline void rec_set_n_add_field(byte*& header, ulint n_add) if (n_add < 0x80) { *header-- = byte(n_add); } else { - *header-- = byte(n_add) | 0x80; + *header-- = byte(byte(n_add) | 0x80); *header-- = byte(n_add >> 7); } } @@ -333,9 +331,9 @@ inline void rec_set_n_add_field(byte*& header, ulint n_add) /******************************************************//** The following function is used to retrieve the info and status bits of a record. (Only compact records have status bits.) -@return info bits */ +@return info and status bits */ UNIV_INLINE -ulint +byte rec_get_info_and_status_bits( /*=========================*/ const rec_t* rec, /*!< in: physical record */ diff --git a/storage/innobase/include/rem0rec.ic b/storage/innobase/include/rem0rec.ic index 7ea68ade6ca..94bd497ac23 100644 --- a/storage/innobase/include/rem0rec.ic +++ b/storage/innobase/include/rem0rec.ic @@ -126,7 +126,7 @@ and the shift needed to obtain each bit-field of the record. */ /******************************************************//** Gets a bit field from within 1 byte. */ UNIV_INLINE -ulint +byte rec_get_bit_field_1( /*================*/ const rec_t* rec, /*!< in: pointer to record origin */ @@ -134,9 +134,7 @@ rec_get_bit_field_1( ulint mask, /*!< in: mask used to filter bits */ ulint shift) /*!< in: shift right applied after masking */ { - ut_ad(rec); - - return((mach_read_from_1(rec - offs) & mask) >> shift); + return static_cast<byte>((*(rec - offs) & mask) >> shift); } /******************************************************//** @@ -504,40 +502,35 @@ rec_get_n_owned_new( The following function is used to retrieve the info bits of a record. @return info bits */ UNIV_INLINE -ulint +byte rec_get_info_bits( /*==============*/ const rec_t* rec, /*!< in: physical record */ ulint comp) /*!< in: nonzero=compact page format */ { - const ulint val = rec_get_bit_field_1( + return rec_get_bit_field_1( rec, comp ? REC_NEW_INFO_BITS : REC_OLD_INFO_BITS, REC_INFO_BITS_MASK, REC_INFO_BITS_SHIFT); - return(val); } /******************************************************//** The following function is used to retrieve the info and status bits of a record. (Only compact records have status bits.) -@return info bits */ +@return info and status bits */ UNIV_INLINE -ulint +byte rec_get_info_and_status_bits( /*=========================*/ const rec_t* rec, /*!< in: physical record */ ulint comp) /*!< in: nonzero=compact page format */ { - ulint bits; - compile_time_assert(!((REC_NEW_STATUS_MASK >> REC_NEW_STATUS_SHIFT) - & (REC_INFO_BITS_MASK >> REC_INFO_BITS_SHIFT))); - if (comp) { - bits = rec_get_info_bits(rec, TRUE) - | ulint(rec_get_status(rec)); - } else { - bits = rec_get_info_bits(rec, FALSE); - ut_ad(!(bits & ~(REC_INFO_BITS_MASK >> REC_INFO_BITS_SHIFT))); - } - return(bits); + compile_time_assert(!((REC_NEW_STATUS_MASK >> REC_NEW_STATUS_SHIFT) + & (REC_INFO_BITS_MASK >> REC_INFO_BITS_SHIFT))); + if (comp) + return static_cast<byte>(rec_get_info_bits(rec, TRUE) | + rec_get_status(rec)); + else + return rec_get_info_bits(rec, FALSE); } /******************************************************//** The following function is used to set the info and status @@ -1176,8 +1169,8 @@ rec_get_converted_size( ut_ad(dtuple->n_fields > 1); } else if ((dtuple_get_info_bits(dtuple) & REC_NEW_STATUS_MASK) == REC_STATUS_NODE_PTR) { - ut_ad(dtuple->n_fields - == dict_index_get_n_unique_in_tree_nonleaf(index) + 1); + ut_ad(dtuple->n_fields - 1 + == dict_index_get_n_unique_in_tree_nonleaf(index)); } else if (index->table->id == DICT_INDEXES_ID) { /* The column SYS_INDEXES.MERGE_THRESHOLD was instantly added in MariaDB 10.2.2 (MySQL 5.7). */ diff --git a/storage/innobase/include/row0upd.h b/storage/innobase/include/row0upd.h index 68692b8e86f..9022bd9f5ce 100644 --- a/storage/innobase/include/row0upd.h +++ b/storage/innobase/include/row0upd.h @@ -75,7 +75,7 @@ void upd_field_set_field_no( /*===================*/ upd_field_t* upd_field, /*!< in: update vector field */ - ulint field_no, /*!< in: field number in a clustered + uint16_t field_no, /*!< in: field number in a clustered index */ dict_index_t* index); @@ -87,7 +87,7 @@ UNIV_INLINE void upd_field_set_v_field_no( upd_field_t* upd_field, - ulint field_no, + uint16_t field_no, dict_index_t* index); /*********************************************************************//** Returns a field of an update vector by field_no. @@ -97,7 +97,7 @@ const upd_field_t* upd_get_field_by_field_no( /*======================*/ const upd_t* update, /*!< in: update vector */ - ulint no, /*!< in: field_no */ + uint16_t no, /*!< in: field_no */ bool is_virtual) /*!< in: if it is a virtual column */ MY_ATTRIBUTE((warn_unused_result)); /*********************************************************************//** @@ -319,14 +319,14 @@ row_upd_step( /* Update vector field */ struct upd_field_t{ - unsigned field_no:16; /*!< field number in an index, usually + uint16_t field_no; /*!< field number in an index, usually the clustered index, but in updating a secondary index record in btr0cur.cc this is the position in the secondary index. If this field is a virtual column, then field_no represents the nth virtual column in the table */ - unsigned orig_len:16; /*!< original length of the locally + uint16_t orig_len; /*!< original length of the locally stored part of an externally stored column, or 0 */ que_node_t* exp; /*!< expression for calculating a new @@ -349,7 +349,7 @@ struct upd_field_t{ /* Update vector structure */ struct upd_t{ mem_heap_t* heap; /*!< heap from which memory allocated */ - ulint info_bits; /*!< new value of info bits to record; + byte info_bits; /*!< new value of info bits to record; default is 0 */ dtuple_t* old_vrow; /*!< pointer to old row, used for virtual column update now */ @@ -366,7 +366,7 @@ struct upd_t{ /** Determine if the given field_no is modified. @return true if modified, false otherwise. */ - bool is_modified(const ulint field_no) const + bool is_modified(uint16_t field_no) const { for (ulint i = 0; i < n_fields; ++i) { if (field_no == fields[i].field_no) { diff --git a/storage/innobase/include/row0upd.ic b/storage/innobase/include/row0upd.ic index fb8ec66aee2..13aacf3f003 100644 --- a/storage/innobase/include/row0upd.ic +++ b/storage/innobase/include/row0upd.ic @@ -93,11 +93,11 @@ void upd_field_set_field_no( /*===================*/ upd_field_t* upd_field, /*!< in: update vector field */ - ulint field_no, /*!< in: field number in a clustered + uint16_t field_no, /*!< in: field number in a clustered index */ dict_index_t* index) /*!< in: index */ { - upd_field->field_no = unsigned(field_no); + upd_field->field_no = field_no; upd_field->orig_len = 0; dict_col_copy_type(dict_index_get_nth_col(index, field_no), dfield_get_type(&upd_field->new_val)); @@ -111,11 +111,11 @@ UNIV_INLINE void upd_field_set_v_field_no( upd_field_t* upd_field, - ulint field_no, + uint16_t field_no, dict_index_t* index) { ut_a(field_no < dict_table_get_n_v_cols(index->table)); - upd_field->field_no = unsigned(field_no); + upd_field->field_no = field_no; upd_field->orig_len = 0; dict_col_copy_type(&dict_table_get_nth_v_col( @@ -131,7 +131,7 @@ const upd_field_t* upd_get_field_by_field_no( /*======================*/ const upd_t* update, /*!< in: update vector */ - ulint no, /*!< in: field_no */ + uint16_t no, /*!< in: field_no */ bool is_virtual) /*!< in: if it is virtual column */ { ulint i; diff --git a/storage/innobase/include/sync0rw.ic b/storage/innobase/include/sync0rw.ic index 4791c801424..0296ef065ff 100644 --- a/storage/innobase/include/sync0rw.ic +++ b/storage/innobase/include/sync0rw.ic @@ -2,7 +2,7 @@ Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2008, Google Inc. -Copyright (c) 2017, 2018, MariaDB Corporation. +Copyright (c) 2017, 2020, MariaDB Corporation. Portions of this file contain modifications contributed and copyrighted by Google, Inc. Those modifications are gratefully acknowledged and are described @@ -333,7 +333,7 @@ rw_lock_x_lock_func_nowait( ut_d(rw_lock_add_debug_info(lock, 0, RW_LOCK_X, file_name, line)); lock->last_x_file_name = file_name; - lock->last_x_line = line; + lock->last_x_line = line & ((1 << 14) - 1); ut_ad(rw_lock_validate(lock)); diff --git a/storage/innobase/include/trx0purge.h b/storage/innobase/include/trx0purge.h index 3af3b30ad04..0c3d4ee5c00 100644 --- a/storage/innobase/include/trx0purge.h +++ b/storage/innobase/include/trx0purge.h @@ -36,16 +36,6 @@ Created 3/26/1996 Heikki Tuuri which needs no purge */ extern trx_undo_rec_t trx_purge_dummy_rec; -/********************************************************************//** -Calculates the file address of an undo log header when we have the file -address of its history list node. -@return file address of the log */ -UNIV_INLINE -fil_addr_t -trx_purge_get_log_from_hist( -/*========================*/ - fil_addr_t node_addr); /*!< in: file address of the history - list node of the log */ /** Prepend the history list with an undo log. Remove the undo log segment from the rseg slot if it is too big for reuse. @param[in] trx transaction @@ -261,6 +251,4 @@ public: /** The global data structure coordinating a purge */ extern purge_sys_t purge_sys; -#include "trx0purge.ic" - #endif /* trx0purge_h */ diff --git a/storage/innobase/include/trx0purge.ic b/storage/innobase/include/trx0purge.ic deleted file mode 100644 index e460676d58e..00000000000 --- a/storage/innobase/include/trx0purge.ic +++ /dev/null @@ -1,42 +0,0 @@ -/***************************************************************************** - -Copyright (c) 1996, 2013, Oracle and/or its affiliates. All Rights Reserved. - -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 the Free Software -Foundation; version 2 of the License. - -This program is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., -51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA - -*****************************************************************************/ - -/**************************************************//** -@file include/trx0purge.ic -Purge old versions - -Created 3/26/1996 Heikki Tuuri -*******************************************************/ - -#include "trx0undo.h" - -/********************************************************************//** -Calculates the file address of an undo log header when we have the file -address of its history list node. -@return file address of the log */ -UNIV_INLINE -fil_addr_t -trx_purge_get_log_from_hist( -/*========================*/ - fil_addr_t node_addr) /*!< in: file address of the history - list node of the log */ -{ - node_addr.boffset -= TRX_UNDO_HISTORY_NODE; - - return(node_addr); -} diff --git a/storage/innobase/include/trx0rec.h b/storage/innobase/include/trx0rec.h index e022a13ba4a..885cd94045b 100644 --- a/storage/innobase/include/trx0rec.h +++ b/storage/innobase/include/trx0rec.h @@ -110,7 +110,7 @@ trx_undo_update_rec_get_sys_cols( general parameters */ trx_id_t* trx_id, /*!< out: trx id */ roll_ptr_t* roll_ptr, /*!< out: roll ptr */ - ulint* info_bits); /*!< out: info bits state */ + byte* info_bits); /*!< out: info bits state */ /*******************************************************************//** Builds an update vector based on a remaining part of an undo log record. @return remaining part of the record, NULL if an error detected, which @@ -132,7 +132,7 @@ trx_undo_update_rec_get_update( the update vector */ trx_id_t trx_id, /*!< in: transaction id from this undorecord */ roll_ptr_t roll_ptr,/*!< in: roll pointer from this undo record */ - ulint info_bits,/*!< in: info bits from this undo record */ + byte info_bits,/*!< in: info bits from this undo record */ mem_heap_t* heap, /*!< in: memory heap from which the memory needed is allocated */ upd_t** upd); /*!< out, own: update vector */ diff --git a/storage/innobase/include/ut0ut.h b/storage/innobase/include/ut0ut.h index 410d2ead738..0814b90979d 100644 --- a/storage/innobase/include/ut0ut.h +++ b/storage/innobase/include/ut0ut.h @@ -117,7 +117,7 @@ when m is a power of two. In other words, rounds n up to m * k. @return n rounded up to the smallest possible integer multiple of m */ #define UT_CALC_ALIGN(n, m) ((n + m - 1) & ~(m - 1)) template <typename T> inline T ut_calc_align(T n, T m) -{ return UT_CALC_ALIGN(n, m); } +{ return static_cast<T>(UT_CALC_ALIGN(n, m)); } /*************************************************************//** Calculates fast the 2-logarithm of a number, rounded upward to an diff --git a/storage/innobase/innodb.cmake b/storage/innobase/innodb.cmake index 657fb7815c3..1d95f24c422 100644 --- a/storage/innobase/innodb.cmake +++ b/storage/innobase/innodb.cmake @@ -1,5 +1,5 @@ # Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved. -# Copyright (c) 2017, 2019, MariaDB Corporation. +# Copyright (c) 2017, 2020, MariaDB Corporation. # # 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 @@ -84,17 +84,6 @@ ENDIF() SET(MUTEXTYPE "event" CACHE STRING "Mutex type: event, sys or futex") -IF(CMAKE_CXX_COMPILER_ID MATCHES "GNU") -# After: WL#5825 Using C++ Standard Library with MySQL code -# we no longer use -fno-exceptions -# SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions") - -# Add -Wconversion if compiling with GCC -## As of Mar 15 2011 this flag causes 3573+ warnings. If you are reading this -## please fix them and enable the following code: -#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wconversion") -ENDIF() - # Enable InnoDB's UNIV_DEBUG in debug builds SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DUNIV_DEBUG") @@ -128,6 +117,13 @@ IF(HAVE_FALLOC_PUNCH_HOLE_AND_KEEP_SIZE) ADD_DEFINITIONS(-DHAVE_FALLOC_PUNCH_HOLE_AND_KEEP_SIZE=1) ENDIF() +IF (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR + CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + ADD_DEFINITIONS("-Wconversion -Wno-sign-conversion") + SET_SOURCE_FILES_PROPERTIES(fts/fts0pars.cc + PROPERTIES COMPILE_FLAGS -Wno-conversion) +ENDIF() + IF(NOT MSVC) # Work around MDEV-18417, MDEV-18656, MDEV-18417 IF(WITH_ASAN AND CMAKE_COMPILER_IS_GNUCC AND diff --git a/storage/innobase/lock/lock0lock.cc b/storage/innobase/lock/lock0lock.cc index c134c055be8..17c9a89cd0b 100644 --- a/storage/innobase/lock/lock0lock.cc +++ b/storage/innobase/lock/lock0lock.cc @@ -1382,7 +1382,7 @@ lock_rec_create_low( } lock->trx = trx; - lock->type_mode = (type_mode & ~LOCK_TYPE_MASK) | LOCK_REC; + lock->type_mode = (type_mode & unsigned(~LOCK_TYPE_MASK)) | LOCK_REC; lock->index = index; lock->un_member.rec_lock.space = uint32_t(space); lock->un_member.rec_lock.page_no = uint32_t(page_no); diff --git a/storage/innobase/log/log0crypt.cc b/storage/innobase/log/log0crypt.cc index 5a1711ecf1e..7e350e37a9a 100644 --- a/storage/innobase/log/log0crypt.cc +++ b/storage/innobase/log/log0crypt.cc @@ -145,7 +145,7 @@ bool log_crypt(byte* buf, lsn_t lsn, ulint size, log_crypt_t op) /* The log block number is not encrypted. */ memcpy_aligned<4>(dst, buf + LOG_BLOCK_HDR_NO, 4); memcpy_aligned<4>(aes_ctr_iv, buf + LOG_BLOCK_HDR_NO, 4); - *aes_ctr_iv &= ~(LOG_BLOCK_FLUSH_BIT_MASK >> 24); + *aes_ctr_iv &= byte(~(LOG_BLOCK_FLUSH_BIT_MASK >> 24)); static_assert(LOG_BLOCK_HDR_NO + 4 == LOG_CRYPT_HDR_SIZE, "compatibility"); memcpy_aligned<4>(aes_ctr_iv + 4, info.crypt_nonce, 4); @@ -155,7 +155,7 @@ bool log_crypt(byte* buf, lsn_t lsn, ulint size, log_crypt_t op) == lsn); byte* key_ver = &buf[OS_FILE_LOG_BLOCK_SIZE - LOG_BLOCK_KEY - LOG_BLOCK_CHECKSUM]; - const uint dst_size + const size_t dst_size = log_sys.log.format == log_t::FORMAT_ENC_10_4 ? sizeof dst - LOG_BLOCK_KEY : sizeof dst; @@ -195,7 +195,7 @@ bool log_crypt(byte* buf, lsn_t lsn, ulint size, log_crypt_t op) uint dst_len; int rc = encryption_crypt( - buf + LOG_CRYPT_HDR_SIZE, dst_size, + buf + LOG_CRYPT_HDR_SIZE, static_cast<uint>(dst_size), reinterpret_cast<byte*>(dst), &dst_len, const_cast<byte*>(info.crypt_key), MY_AES_BLOCK_SIZE, @@ -317,7 +317,7 @@ found: mach_write_to_8(aes_ctr_iv + 3, log_block_get_start_lsn(start_lsn, log_block_no)); memcpy(aes_ctr_iv + 11, buf, 4); - aes_ctr_iv[11] &= ~(LOG_BLOCK_FLUSH_BIT_MASK >> 24); + aes_ctr_iv[11] &= byte(~(LOG_BLOCK_FLUSH_BIT_MASK >> 24)); aes_ctr_iv[15] = 0; int rc = encryption_crypt(buf + LOG_BLOCK_HDR_SIZE, src_len, diff --git a/storage/innobase/log/log0recv.cc b/storage/innobase/log/log0recv.cc index 9dd54c945b9..c21c539c50c 100644 --- a/storage/innobase/log/log0recv.cc +++ b/storage/innobase/log/log0recv.cc @@ -150,7 +150,7 @@ public: { ut_ad(start_lsn < lsn); reinterpret_cast<byte*>(memcpy(end(), recs, size))[size]= 0; - len+= static_cast<uint16_t>(size); + len= static_cast<uint16_t>(len + size); } /** Apply an UNDO_APPEND record. @@ -458,7 +458,7 @@ page_corrupted: if (UNIV_UNLIKELY(offset + last_offset < 8 || offset + last_offset >= size)) goto record_corrupted; - last_offset+= static_cast<uint16_t>(offset); + last_offset= static_cast<uint16_t>(last_offset + offset); l+= olen; rlen-= olen; size_t llen= rlen; @@ -477,7 +477,7 @@ page_corrupted: applied= APPLIED_TO_FSP_HEADER; next_after_applying_write: ut_ad(llen + last_offset <= size); - last_offset+= static_cast<uint16_t>(llen); + last_offset= static_cast<uint16_t>(last_offset + llen); goto next_after_applying; } llen= mlog_decode_varint_length(*l); @@ -1665,7 +1665,8 @@ recv_calc_lsn_on_data_add( ib_uint64_t len) /*!< in: this many bytes of data is added, log block headers not included */ { - unsigned frag_len = (lsn % OS_FILE_LOG_BLOCK_SIZE) - LOG_BLOCK_HDR_SIZE; + unsigned frag_len = static_cast<unsigned>(lsn % OS_FILE_LOG_BLOCK_SIZE) + - LOG_BLOCK_HDR_SIZE; unsigned payload_size = log_sys.payload_size(); ut_ad(frag_len < payload_size); lsn_t lsn_len = len; diff --git a/storage/innobase/os/os0event.cc b/storage/innobase/os/os0event.cc index 0676ba5f6c1..f18633ccd45 100644 --- a/storage/innobase/os/os0event.cc +++ b/storage/innobase/os/os0event.cc @@ -358,8 +358,8 @@ os_event::wait_time_low( if (time_in_usec != OS_SYNC_INFINITE_TIME) { ulonglong usec = ulonglong(time_in_usec) + my_hrtime().val; - abstime.tv_sec = usec / 1000000; - abstime.tv_nsec = (usec % 1000000) * 1000; + abstime.tv_sec = static_cast<time_t>(usec / 1000000); + abstime.tv_nsec = static_cast<uint>((usec % 1000000) * 1000); } else { abstime.tv_nsec = 999999999; abstime.tv_sec = (time_t) ULINT_MAX; diff --git a/storage/innobase/os/os0file.cc b/storage/innobase/os/os0file.cc index 096bbd8ff0b..b46caac721e 100644 --- a/storage/innobase/os/os0file.cc +++ b/storage/innobase/os/os0file.cc @@ -4032,8 +4032,8 @@ static bool is_linux_native_aio_supported() bool os_aio_init(ulint n_reader_threads, ulint n_writer_threads, ulint) { - int max_write_events = (int)n_writer_threads * OS_AIO_N_PENDING_IOS_PER_THREAD; - int max_read_events = (int)n_reader_threads * OS_AIO_N_PENDING_IOS_PER_THREAD; + int max_write_events= int(n_writer_threads * OS_AIO_N_PENDING_IOS_PER_THREAD); + int max_read_events= int(n_reader_threads * OS_AIO_N_PENDING_IOS_PER_THREAD); int max_ibuf_events = 1 * OS_AIO_N_PENDING_IOS_PER_THREAD; int max_events = max_read_events + max_write_events + max_ibuf_events; int ret; diff --git a/storage/innobase/page/page0cur.cc b/storage/innobase/page/page0cur.cc index 607abb596c4..c1c389fed67 100644 --- a/storage/innobase/page/page0cur.cc +++ b/storage/innobase/page/page0cur.cc @@ -1404,20 +1404,20 @@ use_heap: if (UNIV_UNLIKELY(!last_insert)) { no_direction: - *dir= (*dir & ~((1U << 3) - 1)) | PAGE_NO_DIRECTION; + *dir= static_cast<byte>((*dir & ~((1U << 3) - 1)) | PAGE_NO_DIRECTION); memset(n, 0, 2); } else if (block->frame + last_insert == cur->rec && (*dir & ((1U << 3) - 1)) != PAGE_LEFT) { - *dir= (*dir & ~((1U << 3) - 1)) | PAGE_RIGHT; + *dir= static_cast<byte>((*dir & ~((1U << 3) - 1)) | PAGE_RIGHT); inc_dir: mach_write_to_2(n, mach_read_from_2(n) + 1); } else if (next_rec == block->frame + last_insert && (*dir & ((1U << 3) - 1)) != PAGE_RIGHT) { - *dir= (*dir & ~((1U << 3) - 1)) | PAGE_LEFT; + *dir= static_cast<byte>((*dir & ~((1U << 3) - 1)) | PAGE_LEFT); goto inc_dir; } else @@ -1866,7 +1866,7 @@ too_small: static_assert(UNIV_ZIP_SIZE_SHIFT_MAX == 14, "compatibility"); if (next_rec) { - next_rec+= free_rec; + next_rec= static_cast<int16_t>(next_rec + free_rec); ut_ad(int{PAGE_NEW_SUPREMUM_END + REC_N_NEW_EXTRA_BYTES} <= next_rec); ut_ad(static_cast<uint16_t>(next_rec) < srv_page_size); } @@ -2041,7 +2041,8 @@ static void page_mem_free(const buf_block_t &block, rec_t *rec, ut_ad(!block.page.zip.data); const rec_t *free= page_header_get_ptr(block.frame, PAGE_FREE); - const uint16_t n_heap= page_header_get_field(block.frame, PAGE_N_HEAP) - 1; + const uint16_t n_heap= uint16_t(page_header_get_field(block.frame, + PAGE_N_HEAP) - 1); ut_ad(page_get_n_recs(block.frame) < (n_heap & 0x7fff)); const bool deleting_top= n_heap == ((n_heap & 0x8000) ? (rec_get_heap_no_new(rec) | 0x8000) @@ -2480,20 +2481,20 @@ corrupted: if (UNIV_UNLIKELY(!last_insert)) { no_direction: - *dir= (*dir & ~((1U << 3) - 1)) | PAGE_NO_DIRECTION; + *dir= static_cast<byte>((*dir & ~((1U << 3) - 1)) | PAGE_NO_DIRECTION); memset(n_dir, 0, 2); } else if (block.frame + last_insert == prev_rec && (*dir & ((1U << 3) - 1)) != PAGE_LEFT) { - *dir= (*dir & ~((1U << 3) - 1)) | PAGE_RIGHT; + *dir= static_cast<byte>((*dir & ~((1U << 3) - 1)) | PAGE_RIGHT); inc_dir: mach_write_to_2(n_dir, mach_read_from_2(n_dir) + 1); } else if (next_rec == block.frame + last_insert && (*dir & ((1U << 3) - 1)) != PAGE_RIGHT) { - *dir= (*dir & ~((1U << 3) - 1)) | PAGE_LEFT; + *dir= static_cast<byte>((*dir & ~((1U << 3) - 1)) | PAGE_LEFT); goto inc_dir; } else @@ -2570,7 +2571,7 @@ corrupted: uint16_t n= static_cast<uint16_t>(PAGE_NEW_INFIMUM + prev); rec_t *prev_rec= block.frame + n; - n+= mach_read_from_2(prev_rec - REC_NEXT); + n= static_cast<uint16_t>(n + mach_read_from_2(prev_rec - REC_NEXT)); if (!prev); else if (UNIV_UNLIKELY(heap_bot + REC_N_NEW_EXTRA_BYTES > prev_rec || prev_rec > heap_top)) @@ -2589,7 +2590,7 @@ corrupted: for (ulint ns= PAGE_DIR_SLOT_MAX_N_OWNED; !(n_owned= rec_get_n_owned_new(owner_rec)); ) { - n+= mach_read_from_2(owner_rec - REC_NEXT); + n= static_cast<uint16_t>(n + mach_read_from_2(owner_rec - REC_NEXT)); owner_rec= block.frame + n; if (n == PAGE_NEW_SUPREMUM); else if (UNIV_UNLIKELY(heap_bot + REC_N_NEW_EXTRA_BYTES > owner_rec || @@ -2643,7 +2644,7 @@ corrupted: goto corrupted; if ((n= mach_read_from_2(free_rec - REC_NEXT)) != 0) { - n+= static_cast<uint16_t>(free_rec - block.frame); + n= static_cast<uint16_t>(n + free_rec - block.frame); if (UNIV_UNLIKELY(n < PAGE_NEW_SUPREMUM_END + REC_N_NEW_EXTRA_BYTES || heap_top < block.frame + n)) goto corrupted; @@ -2708,20 +2709,20 @@ corrupted: if (UNIV_UNLIKELY(!last_insert)) { no_direction: - *dir= (*dir & ~((1U << 3) - 1)) | PAGE_NO_DIRECTION; + *dir= static_cast<byte>((*dir & ~((1U << 3) - 1)) | PAGE_NO_DIRECTION); memset(n_dir, 0, 2); } else if (block.frame + last_insert == prev_rec && (*dir & ((1U << 3) - 1)) != PAGE_LEFT) { - *dir= (*dir & ~((1U << 3) - 1)) | PAGE_RIGHT; + *dir= static_cast<byte>((*dir & ~((1U << 3) - 1)) | PAGE_RIGHT); inc_dir: mach_write_to_2(n_dir, mach_read_from_2(n_dir) + 1); } else if (next_rec == block.frame + last_insert && (*dir & ((1U << 3) - 1)) != PAGE_RIGHT) { - *dir= (*dir & ~((1U << 3) - 1)) | PAGE_LEFT; + *dir= static_cast<byte>((*dir & ~((1U << 3) - 1)) | PAGE_LEFT); goto inc_dir; } else @@ -2864,7 +2865,7 @@ corrupted: rec_t *prev_rec= block.frame + n; if (UNIV_UNLIKELY(prev_rec > slot)) goto corrupted; - n+= mach_read_from_2(prev_rec - REC_NEXT); + n= static_cast<uint16_t>(n + mach_read_from_2(prev_rec - REC_NEXT)); rec_t *rec= block.frame + n; if (UNIV_UNLIKELY(n < PAGE_NEW_SUPREMUM_END + REC_N_NEW_EXTRA_BYTES || slot < rec)) @@ -2873,7 +2874,7 @@ corrupted: if (UNIV_UNLIKELY(n < PAGE_NEW_SUPREMUM_END + extra_size || slot < rec + data_size)) goto corrupted; - n+= mach_read_from_2(rec - REC_NEXT); + n= static_cast<uint16_t>(n + mach_read_from_2(rec - REC_NEXT)); rec_t *next= block.frame + n; if (n == PAGE_NEW_SUPREMUM); else if (UNIV_UNLIKELY(n < PAGE_NEW_SUPREMUM_END + REC_N_NEW_EXTRA_BYTES || @@ -2885,7 +2886,7 @@ corrupted: ulint slot_owned; for (ulint i= n_recs; !(slot_owned= rec_get_n_owned_new(s)); ) { - n+= mach_read_from_2(s - REC_NEXT); + n= static_cast<uint16_t>(n + mach_read_from_2(s - REC_NEXT)); s= block.frame + n; if (n == PAGE_NEW_SUPREMUM); else if (UNIV_UNLIKELY(n < PAGE_NEW_SUPREMUM_END + REC_N_NEW_EXTRA_BYTES || diff --git a/storage/innobase/page/page0page.cc b/storage/innobase/page/page0page.cc index 582c8df4086..5620330071e 100644 --- a/storage/innobase/page/page0page.cc +++ b/storage/innobase/page/page0page.cc @@ -1003,8 +1003,8 @@ page_delete_rec_list_end( { mtr->write<2,mtr_t::OPT>(*block, slot, PAGE_NEW_SUPREMUM); byte *owned= PAGE_NEW_SUPREMUM - REC_NEW_N_OWNED + block->frame; - byte new_owned= (*owned & ~REC_N_OWNED_MASK) | - static_cast<byte>(n_owned << REC_N_OWNED_SHIFT); + byte new_owned= static_cast<byte>((*owned & ~REC_N_OWNED_MASK) | + n_owned << REC_N_OWNED_SHIFT); #if 0 // FIXME: implement minimal logging for ROW_FORMAT=COMPRESSED if (UNIV_LIKELY_NULL(block->page.zip.data)) { @@ -1032,8 +1032,8 @@ page_delete_rec_list_end( { mtr->write<2,mtr_t::OPT>(*block, slot, PAGE_OLD_SUPREMUM); byte *owned= PAGE_OLD_SUPREMUM - REC_OLD_N_OWNED + block->frame; - byte new_owned= (*owned & ~REC_N_OWNED_MASK) | - static_cast<byte>(n_owned << REC_N_OWNED_SHIFT); + byte new_owned= static_cast<byte>((*owned & ~REC_N_OWNED_MASK) | + n_owned << REC_N_OWNED_SHIFT); mtr->write<1,mtr_t::OPT>(*block, owned, new_owned); mtr->write<2>(*block, prev_rec - REC_NEXT, PAGE_OLD_SUPREMUM); mtr->write<2>(*block, last_rec - REC_NEXT, free); diff --git a/storage/innobase/page/page0zip.cc b/storage/innobase/page/page0zip.cc index 90a443c8b20..8147471b1fb 100644 --- a/storage/innobase/page/page0zip.cc +++ b/storage/innobase/page/page0zip.cc @@ -1418,7 +1418,7 @@ page_zip_compress( page_zip_set_alloc(&c_stream, heap); err = deflateInit2(&c_stream, static_cast<int>(level), - Z_DEFLATED, srv_page_size_shift, + Z_DEFLATED, static_cast<int>(srv_page_size_shift), MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY); ut_a(err == Z_OK); @@ -1562,9 +1562,9 @@ err_exit: #ifdef UNIV_DEBUG page_zip->m_start = #endif /* UNIV_DEBUG */ - page_zip->m_end = unsigned(PAGE_DATA + c_stream.total_out); + page_zip->m_end = uint16_t(PAGE_DATA + c_stream.total_out); page_zip->m_nonempty = FALSE; - page_zip->n_blobs = unsigned(n_blobs); + page_zip->n_blobs = unsigned(n_blobs) & ((1U << 12) - 1); /* Copy those header fields that will not be written in buf_flush_init_for_writing() */ memcpy_aligned<8>(page_zip->data + FIL_PAGE_PREV, page + FIL_PAGE_PREV, @@ -1678,7 +1678,7 @@ page_zip_fields_decode( table = dict_mem_table_create("ZIP_DUMMY", NULL, n, 0, DICT_TF_COMPACT, 0); index = dict_mem_index_create(table, "ZIP_DUMMY", 0, n); - index->n_uniq = unsigned(n); + index->n_uniq = static_cast<unsigned>(n) & dict_index_t::MAX_N_FIELDS; /* avoid ut_ad(index->cached) in dict_index_get_n_unique_in_tree */ index->cached = TRUE; @@ -1737,14 +1737,15 @@ page_zip_fields_decode( page_zip_fields_free(index); index = NULL; } else { - index->n_nullable = unsigned(val); + index->n_nullable = static_cast<unsigned>(val) + & dict_index_t::MAX_N_FIELDS; } } /* ROW_FORMAT=COMPRESSED does not support instant ADD COLUMN */ index->n_core_fields = index->n_fields; - index->n_core_null_bytes - = UT_BITS_IN_BYTES(unsigned(index->n_nullable)); + index->n_core_null_bytes = static_cast<uint8_t>( + UT_BITS_IN_BYTES(unsigned(index->n_nullable))); ut_ad(b == end); @@ -2402,7 +2403,7 @@ zlib_done: } #ifdef UNIV_DEBUG - page_zip->m_start = unsigned(PAGE_DATA + d_stream->total_in); + page_zip->m_start = uint16_t(PAGE_DATA + d_stream->total_in); #endif /* UNIV_DEBUG */ /* Apply the modification log. */ @@ -2417,7 +2418,7 @@ zlib_done: if (UNIV_UNLIKELY(!mod_log_ptr)) { return(FALSE); } - page_zip->m_end = unsigned(mod_log_ptr - page_zip->data); + page_zip->m_end = uint16_t(mod_log_ptr - page_zip->data); page_zip->m_nonempty = mod_log_ptr != d_stream->next_in; } @@ -2556,7 +2557,7 @@ zlib_done: - d_stream->next_out)); } - ut_d(page_zip->m_start = unsigned(PAGE_DATA + d_stream->total_in)); + ut_d(page_zip->m_start = uint16_t(PAGE_DATA + d_stream->total_in)); /* Apply the modification log. */ { @@ -2570,7 +2571,7 @@ zlib_done: if (UNIV_UNLIKELY(!mod_log_ptr)) { return(FALSE); } - page_zip->m_end = unsigned(mod_log_ptr - page_zip->data); + page_zip->m_end = uint16_t(mod_log_ptr - page_zip->data); page_zip->m_nonempty = mod_log_ptr != d_stream->next_in; } @@ -2886,7 +2887,7 @@ zlib_done: - d_stream->next_out)); } - ut_d(page_zip->m_start = unsigned(PAGE_DATA + d_stream->total_in)); + ut_d(page_zip->m_start = uint16_t(PAGE_DATA + d_stream->total_in)); /* Apply the modification log. */ { @@ -2900,7 +2901,7 @@ zlib_done: if (UNIV_UNLIKELY(!mod_log_ptr)) { return(FALSE); } - page_zip->m_end = unsigned(mod_log_ptr - page_zip->data); + page_zip->m_end = uint16_t(mod_log_ptr - page_zip->data); page_zip->m_nonempty = mod_log_ptr != d_stream->next_in; } @@ -3107,7 +3108,7 @@ zlib_error: d_stream.next_out = page + PAGE_ZIP_START; d_stream.avail_out = uInt(srv_page_size - PAGE_ZIP_START); - if (UNIV_UNLIKELY(inflateInit2(&d_stream, srv_page_size_shift) + if (UNIV_UNLIKELY(inflateInit2(&d_stream, int(srv_page_size_shift)) != Z_OK)) { ut_error; } @@ -3588,7 +3589,8 @@ page_zip_write_rec_ext( externs -= blob_no * FIELD_REF_SIZE; if (create) { - page_zip->n_blobs += static_cast<unsigned>(n_ext); + page_zip->n_blobs = (page_zip->n_blobs + n_ext) + & ((1U << 12) - 1); ASSERT_ZERO_BLOB(ext_end - n_ext * FIELD_REF_SIZE); if (ulint len = ulint(externs - ext_end)) { byte* ext_start = ext_end @@ -3714,7 +3716,7 @@ void page_zip_write_rec(buf_block_t *block, const byte *rec, || row_get_rec_trx_id(rec, index, offsets)); *slot |= PAGE_ZIP_DIR_SLOT_DEL >> 8; } else { - *slot &= ~(PAGE_ZIP_DIR_SLOT_DEL >> 8); + *slot &= byte(~(PAGE_ZIP_DIR_SLOT_DEL >> 8)); } ut_ad(rec_get_start((rec_t*) rec, offsets) >= page + PAGE_ZIP_START); @@ -3840,7 +3842,7 @@ void page_zip_write_rec(buf_block_t *block, const byte *rec, ut_ad((ulint) (data - page_zip->data) < page_zip_get_size(page_zip)); mtr->zmemcpy(block->page, page_zip->m_end, data - page_zip->data - page_zip->m_end); - page_zip->m_end = unsigned(data - page_zip->data); + page_zip->m_end = uint16_t(data - page_zip->data); page_zip->m_nonempty = TRUE; #ifdef UNIV_ZIP_DEBUG @@ -4165,7 +4167,7 @@ void page_zip_rec_set_deleted(buf_block_t *block, rec_t *rec, bool flag, if (flag) b|= (PAGE_ZIP_DIR_SLOT_DEL >> 8); else - b&= ~(PAGE_ZIP_DIR_SLOT_DEL >> 8); + b&= byte(~(PAGE_ZIP_DIR_SLOT_DEL >> 8)); mtr->zmemcpy<mtr_t::OPT>(block->page, slot, &b, 1); #ifdef UNIV_ZIP_DEBUG ut_a(page_zip_validate(&block->page.zip, block->frame, nullptr)); @@ -4191,7 +4193,7 @@ page_zip_rec_set_owned( if (flag) b|= (PAGE_ZIP_DIR_SLOT_OWNED >> 8); else - b&= ~(PAGE_ZIP_DIR_SLOT_OWNED >> 8); + b&= byte(~(PAGE_ZIP_DIR_SLOT_OWNED >> 8)); mtr->zmemcpy<mtr_t::OPT>(block->page, slot, &b, 1); } @@ -4382,7 +4384,7 @@ void page_zip_dir_delete(buf_block_t *block, byte *rec, } memset(ext_end, 0, n_ext * FIELD_REF_SIZE); mtr->memset(*block, ext_end - page_zip->data, n_ext * FIELD_REF_SIZE, 0); - page_zip->n_blobs -= static_cast<unsigned>(n_ext); + page_zip->n_blobs = (page_zip->n_blobs - n_ext) & ((1U << 12) - 1); } /* The compression algorithm expects info_bits and n_owned @@ -4596,7 +4598,8 @@ page_zip_copy_recs( rec_t* rec = page + offs; ut_a(rec[-REC_N_NEW_EXTRA_BYTES] & REC_INFO_MIN_REC_FLAG); - rec[-REC_N_NEW_EXTRA_BYTES] &= ~ REC_INFO_MIN_REC_FLAG; + rec[-REC_N_NEW_EXTRA_BYTES] + &= byte(~REC_INFO_MIN_REC_FLAG); } } diff --git a/storage/innobase/pars/pars0opt.cc b/storage/innobase/pars/pars0opt.cc index 3730879146d..e1a913b0179 100644 --- a/storage/innobase/pars/pars0opt.cc +++ b/storage/innobase/pars/pars0opt.cc @@ -388,7 +388,7 @@ opt_calc_index_goodness( } } - if (goodness >= 4 * dict_index_get_n_unique(index)) { + if (goodness / 4 >= dict_index_get_n_unique(index)) { goodness += 1024; if (dict_index_is_clust(index)) { diff --git a/storage/innobase/pars/pars0pars.cc b/storage/innobase/pars/pars0pars.cc index b424d972fe3..2f3791aeb5e 100644 --- a/storage/innobase/pars/pars0pars.cc +++ b/storage/innobase/pars/pars0pars.cc @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2018, 2019, MariaDB Corporation. +Copyright (c) 2018, 2020, MariaDB Corporation. 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 the Free Software @@ -1131,9 +1131,11 @@ pars_process_assign_list( col_sym = assign_node->col; - upd_field_set_field_no(upd_field, dict_index_get_nth_col_pos( - clust_index, col_sym->col_no, - NULL), + ulint field_no = dict_index_get_nth_col_pos( + clust_index, col_sym->col_no, NULL); + ut_ad(field_no < clust_index->n_fields); + upd_field_set_field_no(upd_field, + static_cast<uint16_t>(field_no), clust_index); upd_field->exp = assign_node->val; @@ -1929,7 +1931,7 @@ pars_stored_procedure_call( /*************************************************************//** Retrieves characters to the lexical analyzer. */ -size_t +int pars_get_lex_chars( /*===============*/ char* buf, /*!< in/out: buffer where to copy */ @@ -1951,7 +1953,7 @@ pars_get_lex_chars( pars_sym_tab_global->next_char_pos += len; - return(len); + return static_cast<int>(len); } /*************************************************************//** diff --git a/storage/innobase/rem/rem0rec.cc b/storage/innobase/rem/rem0rec.cc index 47b6ed73536..78ed14311b1 100644 --- a/storage/innobase/rem/rem0rec.cc +++ b/storage/innobase/rem/rem0rec.cc @@ -351,7 +351,8 @@ start: do { if (mblob) { if (i == index->first_user_field()) { - offs += FIELD_REF_SIZE; + offs = static_cast<offset_t>(offs + + FIELD_REF_SIZE); len = combine(offs, STORED_OFFPAGE); any |= REC_OFFS_EXTERNAL; field--; @@ -424,12 +425,12 @@ start: more, or when the field is stored externally. */ if ((len & 0x80) && DATA_BIG_COL(col)) { /* 1exxxxxxx xxxxxxxx */ - len <<= 8; - len |= *lens--; - - offs += get_value(len); + len = static_cast<offset_t>(len << 8 + | *lens--); + offs = static_cast<offset_t>(offs + + get_value(len)); if (UNIV_UNLIKELY(len & 0x4000)) { - ut_ad(dict_index_is_clust(index)); + ut_ad(index->is_primary()); any |= REC_OFFS_EXTERNAL; len = combine(offs, STORED_OFFPAGE); } else { @@ -439,9 +440,10 @@ start: continue; } - len = offs += len; + len = offs = static_cast<offset_t>(offs + len); } else { - len = offs += field->fixed_len; + len = offs = static_cast<offset_t>(offs + + field->fixed_len); } } while (field++, rec_offs_base(offsets)[++i] = len, i < rec_offs_n_fields(offsets)); @@ -466,11 +468,12 @@ rec_offs_make_valid( const bool is_alter_metadata = leaf && rec_is_alter_metadata(rec, *index); ut_ad(is_alter_metadata - || rec_offs_n_fields(offsets) - <= (leaf - ? dict_index_get_n_fields(index) - : dict_index_get_n_unique_in_tree_nonleaf(index) + 1) - || index->is_dummy || dict_index_is_ibuf(index)); + || index->is_dummy || index->is_ibuf() + || (leaf + ? rec_offs_n_fields(offsets) + <= dict_index_get_n_fields(index) + : rec_offs_n_fields(offsets) - 1 + <= dict_index_get_n_unique_in_tree_nonleaf(index))); const bool is_user_rec = (dict_table_is_comp(index->table) ? rec_get_heap_no_new(rec) : rec_get_heap_no_old(rec)) @@ -526,7 +529,7 @@ rec_offs_validate( } if (index) { ut_ad(!memcmp(&index, &offsets[INDEX_OFFSET], sizeof(index))); - ulint max_n_fields = std::max( + ulint max_n_fields = std::max<ulint>( dict_index_get_n_fields(index), dict_index_get_n_unique_in_tree(index) + 1); if (comp && rec) { @@ -664,7 +667,8 @@ rec_init_offsets( do { offset_t len; if (UNIV_UNLIKELY(i == n_node_ptr_field)) { - len = offs += REC_NODE_PTR_SIZE; + len = offs = static_cast<offset_t>( + offs + REC_NODE_PTR_SIZE); goto resolved; } @@ -707,25 +711,26 @@ rec_init_offsets( if (DATA_BIG_COL(col)) { if (len & 0x80) { /* 1exxxxxxx xxxxxxxx */ - - len <<= 8; - len |= *lens--; + len = static_cast<offset_t>( + len << 8 | *lens--); /* B-tree node pointers must not contain externally stored columns. Thus the "e" flag must be 0. */ ut_a(!(len & 0x4000)); - offs += get_value(len); + offs = static_cast<offset_t>( + offs + get_value(len)); len = offs; goto resolved; } } - len = offs += len; + len = offs = static_cast<offset_t>(offs + len); } else { - len = offs += field->fixed_len; + len = offs = static_cast<offset_t>( + offs + field->fixed_len); } resolved: rec_offs_base(offsets)[i + 1] = len; @@ -742,29 +747,32 @@ resolved: offset_t any; if (rec_get_1byte_offs_flag(rec)) { - offs += static_cast<offset_t>(n_fields); + offs = static_cast<offset_t>(offs + n_fields); any = offs; /* Determine offsets to fields */ do { offs = rec_1_get_field_end_info(rec, i); if (offs & REC_1BYTE_SQL_NULL_MASK) { - offs &= ~REC_1BYTE_SQL_NULL_MASK; + offs &= static_cast<offset_t>( + ~REC_1BYTE_SQL_NULL_MASK); set_type(offs, SQL_NULL); } rec_offs_base(offsets)[1 + i] = offs; } while (++i < n); } else { - offs += 2 * static_cast<offset_t>(n_fields); + offs = static_cast<offset_t>(offs + 2 * n_fields); any = offs; /* Determine offsets to fields */ do { offs = rec_2_get_field_end_info(rec, i); if (offs & REC_2BYTE_SQL_NULL_MASK) { - offs &= ~REC_2BYTE_SQL_NULL_MASK; + offs &= static_cast<offset_t>( + ~REC_2BYTE_SQL_NULL_MASK); set_type(offs, SQL_NULL); } if (offs & REC_2BYTE_EXTERN_MASK) { - offs &= ~REC_2BYTE_EXTERN_MASK; + offs &= static_cast<offset_t>( + ~REC_2BYTE_EXTERN_MASK); set_type(offs, STORED_OFFPAGE); any |= REC_OFFS_EXTERNAL; } @@ -864,8 +872,8 @@ rec_get_offsets_func( ut_ad(!is_user_rec || leaf || index->is_dummy || dict_index_is_ibuf(index) || n == n_fields /* dict_stats_analyze_index_level() */ - || n - == dict_index_get_n_unique_in_tree_nonleaf(index) + 1); + || n - 1 + == dict_index_get_n_unique_in_tree_nonleaf(index)); ut_ad(!is_user_rec || !leaf || index->is_dummy || dict_index_is_ibuf(index) || n == n_fields /* btr_pcur_restore_position() */ @@ -972,7 +980,8 @@ rec_get_offsets_reverse( do { offset_t len; if (UNIV_UNLIKELY(i == n_node_ptr_field)) { - len = offs += REC_NODE_PTR_SIZE; + len = offs = static_cast<offset_t>( + offs + REC_NODE_PTR_SIZE); goto resolved; } @@ -1012,10 +1021,11 @@ rec_get_offsets_reverse( if (DATA_BIG_COL(col)) { if (len & 0x80) { /* 1exxxxxxx xxxxxxxx */ - len <<= 8; - len |= *lens++; + len = static_cast<offset_t>( + len << 8 | *lens++); - offs += get_value(len); + offs = static_cast<offset_t>( + offs + get_value(len)); if (UNIV_UNLIKELY(len & 0x4000)) { any_ext = REC_OFFS_EXTERNAL; len = combine(offs, @@ -1028,9 +1038,10 @@ rec_get_offsets_reverse( } } - len = offs += len; + len = offs = static_cast<offset_t>(offs + len); } else { - len = offs += static_cast<offset_t>(field->fixed_len); + len = offs = static_cast<offset_t>(offs + + field->fixed_len); } resolved: rec_offs_base(offsets)[i + 1] = len; @@ -1116,7 +1127,7 @@ rec_get_converted_size_comp_prefix_low( { ulint extra_size = temp ? 0 : REC_N_NEW_EXTRA_BYTES; ut_ad(n_fields > 0); - ut_ad(n_fields <= dict_index_get_n_fields(index) + mblob); + ut_ad(n_fields - mblob <= dict_index_get_n_fields(index)); ut_d(ulint n_null = index->n_nullable); ut_ad(status == REC_STATUS_ORDINARY || status == REC_STATUS_NODE_PTR || status == REC_STATUS_INSTANT); @@ -1524,8 +1535,8 @@ rec_convert_dtuple_to_rec_comp( REC_NEW_HEAP_NO, REC_HEAP_NO_MASK, REC_HEAP_NO_SHIFT); rec_set_status(rec, status); - ut_ad(n_fields - == dict_index_get_n_unique_in_tree_nonleaf(index) + 1); + ut_ad(n_fields - 1 + == dict_index_get_n_unique_in_tree_nonleaf(index)); ut_d(n_null = std::min<uint>(index->n_core_null_bytes * 8U, index->n_nullable)); n_node_ptr_field = n_fields - 1; @@ -1580,7 +1591,7 @@ start: /* set the null flag if necessary */ if (dfield_is_null(field)) { - *nulls |= null_mask; + *nulls |= static_cast<byte>(null_mask); null_mask <<= 1; continue; } @@ -1825,8 +1836,8 @@ rec_copy_prefix_to_dtuple( offset_t* offsets = offsets_; rec_offs_init(offsets_); - ut_ad(is_leaf || n_fields - <= dict_index_get_n_unique_in_tree_nonleaf(index) + 1); + ut_ad(is_leaf || n_fields - 1 + <= dict_index_get_n_unique_in_tree_nonleaf(index)); offsets = rec_get_offsets(rec, index, offsets, is_leaf, n_fields, &heap); @@ -2187,7 +2198,7 @@ rec_print_old( n = rec_get_n_fields_old(rec); fprintf(file, "PHYSICAL RECORD: n_fields " ULINTPF ";" - " %u-byte offsets; info bits " ULINTPF "\n", + " %u-byte offsets; info bits %u\n", n, rec_get_1byte_offs_flag(rec) ? 1 : 2, rec_get_info_bits(rec, FALSE)); @@ -2441,7 +2452,7 @@ rec_print_new( } fprintf(file, "PHYSICAL RECORD: n_fields " ULINTPF ";" - " compact format; info bits " ULINTPF "\n", + " compact format; info bits %u\n", rec_offs_n_fields(offsets), rec_get_info_bits(rec, TRUE)); diff --git a/storage/innobase/row/row0ftsort.cc b/storage/innobase/row/row0ftsort.cc index e59b380029d..a8e4a06b8ea 100644 --- a/storage/innobase/row/row0ftsort.cc +++ b/storage/innobase/row/row0ftsort.cc @@ -103,7 +103,8 @@ row_merge_create_fts_sort_index( ? DATA_VARCHAR : DATA_VARMYSQL; field->col->mbminlen = idx_field->col->mbminlen; field->col->mbmaxlen = idx_field->col->mbmaxlen; - field->col->len = HA_FT_MAXCHARLEN * unsigned(field->col->mbmaxlen); + field->col->len = static_cast<uint16_t>( + HA_FT_MAXCHARLEN * field->col->mbmaxlen); field->fixed_len = 0; @@ -635,7 +636,7 @@ row_merge_fts_doc_tokenize( field->type.mtype = DATA_INT; field->type.prtype = DATA_NOT_NULL | DATA_BINARY_TYPE; - field->type.len = field->len; + field->type.len = static_cast<uint16_t>(field->len); field->type.mbminlen = 0; field->type.mbmaxlen = 0; @@ -1619,7 +1620,8 @@ row_fts_merge_insert( in order to get the correct aux table names. */ index->table->flags2 |= DICT_TF2_FTS_AUX_HEX_NAME; DBUG_EXECUTE_IF("innodb_test_wrong_fts_aux_table_name", - index->table->flags2 &= ~DICT_TF2_FTS_AUX_HEX_NAME;); + index->table->flags2 &= ~DICT_TF2_FTS_AUX_HEX_NAME + & ((1U << DICT_TF2_BITS) - 1);); fts_table.type = FTS_INDEX_TABLE; fts_table.index_id = index->id; fts_table.table_id = table->id; diff --git a/storage/innobase/row/row0import.cc b/storage/innobase/row/row0import.cc index dcf96179158..494a8b3b729 100644 --- a/storage/innobase/row/row0import.cc +++ b/storage/innobase/row/row0import.cc @@ -2510,10 +2510,10 @@ row_import_cfg_read_index_fields( new (field) dict_field_t(); - field->prefix_len = mach_read_from_4(ptr); + field->prefix_len = mach_read_from_4(ptr) & ((1U << 12) - 1); ptr += sizeof(ib_uint32_t); - field->fixed_len = mach_read_from_4(ptr); + field->fixed_len = mach_read_from_4(ptr) & ((1U << 10) - 1); ptr += sizeof(ib_uint32_t); /* Include the NUL byte in the length. */ @@ -2818,24 +2818,24 @@ row_import_read_columns( col->prtype = mach_read_from_4(ptr); ptr += sizeof(ib_uint32_t); - col->mtype = mach_read_from_4(ptr); + col->mtype = static_cast<byte>(mach_read_from_4(ptr)); ptr += sizeof(ib_uint32_t); - col->len = mach_read_from_4(ptr); + col->len = static_cast<uint16_t>(mach_read_from_4(ptr)); ptr += sizeof(ib_uint32_t); uint32_t mbminmaxlen = mach_read_from_4(ptr); - col->mbmaxlen = mbminmaxlen / 5; - col->mbminlen = mbminmaxlen % 5; + col->mbmaxlen = (mbminmaxlen / 5) & 7; + col->mbminlen = (mbminmaxlen % 5) & 7; ptr += sizeof(ib_uint32_t); col->ind = mach_read_from_4(ptr) & dict_index_t::MAX_N_FIELDS; ptr += sizeof(ib_uint32_t); - col->ord_part = mach_read_from_4(ptr); + col->ord_part = mach_read_from_4(ptr) & 1; ptr += sizeof(ib_uint32_t); - col->max_prefix = mach_read_from_4(ptr); + col->max_prefix = mach_read_from_4(ptr) & ((1U << 12) - 1); ptr += sizeof(ib_uint32_t); /* Read in the column name as [len, byte array]. The len @@ -4214,7 +4214,7 @@ row_import_for_mysql( } table->file_unreadable = false; - table->flags2 &= ~DICT_TF2_DISCARDED; + table->flags2 &= ~DICT_TF2_DISCARDED & ((1U << DICT_TF2_BITS) - 1); /* Set autoinc value read from .cfg file, if one was specified. Otherwise, keep the PAGE_ROOT_AUTO_INC as is. */ diff --git a/storage/innobase/row/row0ins.cc b/storage/innobase/row/row0ins.cc index 16158032e19..cbe82cfcd9c 100644 --- a/storage/innobase/row/row0ins.cc +++ b/storage/innobase/row/row0ins.cc @@ -540,9 +540,10 @@ row_ins_cascade_calc_update_vec( ufield = update->fields + n_fields_updated; - ufield->field_no = dict_table_get_nth_col_pos( - table, dict_col_get_no(col), - &prefix_col); + ufield->field_no = static_cast<uint16_t>( + dict_table_get_nth_col_pos( + table, dict_col_get_no(col), + &prefix_col)); ufield->orig_len = 0; ufield->exp = NULL; @@ -972,7 +973,7 @@ row_ins_foreign_fill_virtual( goto func_exit; } - for (ulint i = 0; i < n_v_fld; i++) { + for (uint16_t i = 0; i < n_v_fld; i++) { dict_v_col_t* col = dict_table_get_nth_v_col( index->table, i); @@ -1297,8 +1298,9 @@ row_ins_foreign_check_on_constraint( index, i); ulint prefix_col; - ufield->field_no = dict_table_get_nth_col_pos( - table, col_no, &prefix_col); + ufield->field_no = static_cast<uint16_t>( + dict_table_get_nth_col_pos( + table, col_no, &prefix_col)); dict_col_t* col = dict_table_get_nth_col( table, col_no); dict_col_copy_type(col, dfield_get_type(&ufield->new_val)); diff --git a/storage/innobase/row/row0log.cc b/storage/innobase/row/row0log.cc index 8559db3384b..f7e9cb18e5e 100644 --- a/storage/innobase/row/row0log.cc +++ b/storage/innobase/row/row0log.cc @@ -2067,9 +2067,8 @@ row_log_table_apply_update( ut_ad(dtuple_get_n_fields_cmp(old_pk) == dict_index_get_n_unique(index)); - ut_ad(dtuple_get_n_fields(old_pk) - == dict_index_get_n_unique(index) - + (log->same_pk ? 0 : 2)); + ut_ad(dtuple_get_n_fields(old_pk) - (log->same_pk ? 0 : 2) + == dict_index_get_n_unique(index)); row = row_log_table_apply_convert_mrec( mrec, dup->index, offsets, log, heap, &error); diff --git a/storage/innobase/row/row0merge.cc b/storage/innobase/row/row0merge.cc index 050d79abc21..ef9d8ee542c 100644 --- a/storage/innobase/row/row0merge.cc +++ b/storage/innobase/row/row0merge.cc @@ -656,7 +656,8 @@ row_merge_buf_add( doc_item->field = field; doc_item->doc_id = *doc_id; - bucket = *doc_id % fts_sort_pll_degree; + bucket = static_cast<ulint>( + *doc_id % fts_sort_pll_degree); /* Add doc item to fts_doc_list */ mutex_enter(&psort_info[bucket].mutex); @@ -3287,7 +3288,7 @@ row_merge_sort( num_runs = file->offset; if (stage != NULL) { - stage->begin_phase_sort(log2(num_runs)); + stage->begin_phase_sort(log2(double(num_runs))); } /* If num_runs are less than 1, nothing to merge */ diff --git a/storage/innobase/row/row0mysql.cc b/storage/innobase/row/row0mysql.cc index ce52b01d01e..a9bcd9463a2 100644 --- a/storage/innobase/row/row0mysql.cc +++ b/storage/innobase/row/row0mysql.cc @@ -2561,8 +2561,8 @@ row_create_index_for_mysql( ut_ad((index == NULL) == (err != DB_SUCCESS)); if (UNIV_LIKELY(err == DB_SUCCESS)) { ut_ad(!index->is_instant()); - index->n_core_null_bytes = UT_BITS_IN_BYTES( - unsigned(index->n_nullable)); + index->n_core_null_bytes = static_cast<uint8_t>( + UT_BITS_IN_BYTES(unsigned(index->n_nullable))); err = dict_create_index_tree_in_mem(index, trx); diff --git a/storage/innobase/row/row0purge.cc b/storage/innobase/row/row0purge.cc index 58b84528949..20685398a81 100644 --- a/storage/innobase/row/row0purge.cc +++ b/storage/innobase/row/row0purge.cc @@ -704,7 +704,7 @@ static void row_purge_reset_trx_id(purge_node_t* node, mtr_t* mtr) byte* ptr = rec_get_nth_field( rec, offsets, trx_id_pos, &len); ut_ad(len == DATA_TRX_ID_LEN); - uint16_t offs = page_offset(ptr); + size_t offs = page_offset(ptr); mtr->memset(block, offs, DATA_TRX_ID_LEN, 0); offs += DATA_TRX_ID_LEN; mtr->write<1,mtr_t::OPT>(*block, block->frame @@ -882,7 +882,7 @@ row_purge_parse_undo_rec( undo_no_t undo_no; table_id_t table_id; roll_ptr_t roll_ptr; - ulint info_bits; + byte info_bits; ulint type; ut_ad(node != NULL); diff --git a/storage/innobase/row/row0row.cc b/storage/innobase/row/row0row.cc index 83add52dd88..1af9638412c 100644 --- a/storage/innobase/row/row0row.cc +++ b/storage/innobase/row/row0row.cc @@ -765,7 +765,7 @@ row_rec_to_index_entry_impl( (missing merge_threshold column) is acceptable. */ || (!index->table->is_temporary() && index->table->id == DICT_INDEXES_ID - && rec_len == dict_index_get_n_fields(index) - 1)); + && rec_len + 1 == dict_index_get_n_fields(index))); ulint i; for (i = 0; i < (mblob ? index->first_user_field() : rec_len); diff --git a/storage/innobase/row/row0sel.cc b/storage/innobase/row/row0sel.cc index 564858e6668..b8f89d53e69 100644 --- a/storage/innobase/row/row0sel.cc +++ b/storage/innobase/row/row0sel.cc @@ -2995,7 +2995,7 @@ row_sel_store_mysql_field( /* It is a nullable column with a non-NULL value */ mysql_rec[templ->mysql_null_byte_offset] - &= ~(byte) templ->mysql_null_bit_mask; + &= static_cast<byte>(~templ->mysql_null_bit_mask); } DBUG_RETURN(TRUE); @@ -3098,8 +3098,9 @@ static bool row_sel_store_mysql_rec( (const byte*)dfield->data, dfield->len); if (templ->mysql_null_bit_mask) { mysql_rec[ - templ->mysql_null_byte_offset] - &= ~(byte) templ->mysql_null_bit_mask; + templ->mysql_null_byte_offset] + &= static_cast<byte> + (~templ->mysql_null_bit_mask); } } diff --git a/storage/innobase/row/row0umod.cc b/storage/innobase/row/row0umod.cc index cc5ac98937f..6822c4a363d 100644 --- a/storage/innobase/row/row0umod.cc +++ b/storage/innobase/row/row0umod.cc @@ -478,8 +478,7 @@ row_undo_mod_clust( 0, 1ULL << ROLL_PTR_INSERT_FLAG_POS, &mtr); } else { - uint16_t offs = page_offset(rec - + trx_id_offset); + size_t offs = page_offset(rec + trx_id_offset); mtr.memset(block, offs, DATA_TRX_ID_LEN, 0); offs += DATA_TRX_ID_LEN; mtr.write<1,mtr_t::OPT>(*block, block->frame @@ -1204,7 +1203,7 @@ static bool row_undo_mod_parse_undo_rec(undo_node_t* node, bool dict_locked) table_id_t table_id; trx_id_t trx_id; roll_ptr_t roll_ptr; - ulint info_bits; + byte info_bits; ulint type; ulint cmpl_info; bool dummy_extern; diff --git a/storage/innobase/row/row0upd.cc b/storage/innobase/row/row0upd.cc index 1bd14280c8b..e797d527969 100644 --- a/storage/innobase/row/row0upd.cc +++ b/storage/innobase/row/row0upd.cc @@ -605,7 +605,6 @@ row_upd_build_sec_rec_difference_binary( ulint len; upd_t* update; ulint n_diff; - ulint i; /* This function is used only for a secondary index */ ut_a(!dict_index_is_clust(index)); @@ -619,7 +618,7 @@ row_upd_build_sec_rec_difference_binary( n_diff = 0; - for (i = 0; i < dtuple_get_n_fields(entry); i++) { + for (uint16_t i = 0; i < dtuple_get_n_fields(entry); i++) { data = rec_get_nth_field(rec, offsets, i, &len); @@ -707,7 +706,7 @@ row_upd_build_difference_binary( ut_ad(rec_offs_validate(rec, index, offsets)); } - for (ulint i = 0; i < entry->n_fields; i++) { + for (uint16_t i = 0; i < entry->n_fields; i++) { const byte* data = rec_get_nth_cfield(rec, index, offsets, i, &len); const dfield_t* dfield = dtuple_get_nth_field(entry, i); @@ -728,7 +727,8 @@ row_upd_build_difference_binary( } } - for (ulint i = entry->n_fields; i < index->n_fields; i++) { + for (uint16_t i = static_cast<uint16_t>(entry->n_fields); + i < index->n_fields; i++) { upd_field_t* uf = upd_get_nth_field(update, n_diff++); const dict_col_t* col = dict_index_get_nth_col(index, i); /* upd_create() zero-initialized uf */ @@ -762,7 +762,7 @@ row_upd_build_difference_binary( &mysql_table, &record, &vcol_storage); - for (ulint i = 0; i < n_v_fld; i++) { + for (uint16_t i = 0; i < n_v_fld; i++) { const dict_v_col_t* col = dict_table_get_nth_v_col(index->table, i); @@ -1021,7 +1021,7 @@ row_upd_index_replace_new_col_vals_index_pos( dtuple_set_info_bits(entry, update->info_bits); - for (unsigned i = index->n_fields; i--; ) { + for (uint16_t i = index->n_fields; i--; ) { const dict_field_t* field; const dict_col_t* col; const upd_field_t* uf; @@ -1091,8 +1091,9 @@ row_upd_index_replace_new_col_vals( update, vcol->v_pos, true); } else { uf = upd_get_field_by_field_no( - update, - dict_col_get_clust_pos(col, clust_index), + update, static_cast<uint16_t>( + dict_col_get_clust_pos( + col, clust_index)), false); } @@ -1392,8 +1393,9 @@ row_upd_changes_ord_field_binary_func( update, vcol->v_pos, true); } else { upd_field = upd_get_field_by_field_no( - update, - dict_col_get_clust_pos(col, clust_index), + update, static_cast<uint16_t>( + dict_col_get_clust_pos( + col, clust_index)), false); } @@ -2278,14 +2280,13 @@ row_upd_clust_rec_by_insert_inherit_func( const upd_t* update) /*!< in: update vector */ { bool inherit = false; - ulint i; ut_ad(!rec == !offsets); ut_ad(!rec == !index); ut_ad(!rec || rec_offs_validate(rec, index, offsets)); ut_ad(!rec || rec_offs_any_extern(offsets)); - for (i = 0; i < dtuple_get_n_fields(entry); i++) { + for (uint16_t i = 0; i < dtuple_get_n_fields(entry); i++) { dfield_t* dfield = dtuple_get_nth_field(entry, i); byte* data; ulint len; @@ -2336,7 +2337,7 @@ row_upd_clust_rec_by_insert_inherit_func( a lock wait and we already had disowned the BLOB. */ ut_a(rec == NULL || !(data[BTR_EXTERN_LEN] & BTR_EXTERN_OWNER_FLAG)); - data[BTR_EXTERN_LEN] &= ~BTR_EXTERN_OWNER_FLAG; + data[BTR_EXTERN_LEN] &= byte(~BTR_EXTERN_OWNER_FLAG); data[BTR_EXTERN_LEN] |= BTR_EXTERN_INHERITED_FLAG; /* The BTR_EXTERN_INHERITED_FLAG only matters in rollback of a fresh insert. Purge will always free @@ -2972,7 +2973,7 @@ row_upd( ut_ad(!thr_get_trx(thr)->in_rollback); DBUG_PRINT("row_upd", ("table: %s", node->table->name.m_name)); - DBUG_PRINT("row_upd", ("info bits in update vector: 0x" ULINTPFx, + DBUG_PRINT("row_upd", ("info bits in update vector: 0x%x", node->update ? node->update->info_bits: 0)); DBUG_PRINT("row_upd", ("foreign_id: %s", node->foreign ? node->foreign->id: "NULL")); @@ -3193,7 +3194,9 @@ void upd_node_t::make_versioned_helper(const trx_t* trx, ulint idx) upd_field_t* ufield = upd_get_nth_field(update, update->n_fields - 1); const dict_col_t* col = dict_table_get_nth_col(table, idx); - upd_field_set_field_no(ufield, dict_col_get_clust_pos(col, clust_index), + upd_field_set_field_no(ufield, static_cast<uint16_t>( + dict_col_get_clust_pos( + col, clust_index)), clust_index); char* where = reinterpret_cast<char*>(update->vers_sys_value); diff --git a/storage/innobase/srv/srv0start.cc b/storage/innobase/srv/srv0start.cc index 7ead0630e5e..055a289bd62 100644 --- a/storage/innobase/srv/srv0start.cc +++ b/storage/innobase/srv/srv0start.cc @@ -1192,7 +1192,8 @@ dberr_t srv_start(bool create_new_db) /* Register performance schema stages before any real work has been started which may need to be instrumented. */ - mysql_stage_register("innodb", srv_stages, UT_ARR_SIZE(srv_stages)); + mysql_stage_register("innodb", srv_stages, + static_cast<int>(UT_ARR_SIZE(srv_stages))); /* Set the maximum number of threads which can wait for a semaphore inside InnoDB: this is the 'sync wait array' size, as well as the diff --git a/storage/innobase/sync/sync0rw.cc b/storage/innobase/sync/sync0rw.cc index 2795fc902fc..6f22d640298 100644 --- a/storage/innobase/sync/sync0rw.cc +++ b/storage/innobase/sync/sync0rw.cc @@ -227,8 +227,8 @@ rw_lock_create_func( /* This should hold in practice. If it doesn't then we need to split the source file anyway. Or create the locks on lines less than 8192. cline is unsigned:13. */ - ut_ad(cline <= 8192); - lock->cline = cline; + ut_ad(cline <= ((1U << 13) - 1)); + lock->cline = cline & ((1U << 13) - 1); lock->count_os_wait = 0; lock->last_x_file_name = "not yet reserved"; lock->last_x_line = 0; @@ -547,7 +547,7 @@ rw_lock_x_lock_low( ut_d(rw_lock_add_debug_info(lock, pass, RW_LOCK_X, file_name, line)); lock->last_x_file_name = file_name; - lock->last_x_line = line; + lock->last_x_line = line & ((1U << 14) - 1); return(TRUE); } @@ -626,7 +626,7 @@ rw_lock_sx_lock_low( ut_d(rw_lock_add_debug_info(lock, pass, RW_LOCK_SX, file_name, line)); lock->last_x_file_name = file_name; - lock->last_x_line = line; + lock->last_x_line = line & ((1U << 14) - 1); return(TRUE); } diff --git a/storage/innobase/trx/trx0i_s.cc b/storage/innobase/trx/trx0i_s.cc index 78681ab68f8..2161044cc80 100644 --- a/storage/innobase/trx/trx0i_s.cc +++ b/storage/innobase/trx/trx0i_s.cc @@ -718,16 +718,16 @@ static bool fill_locks_row( && (lock->type_mode & LOCK_GAP); switch (lock->type_mode & LOCK_MODE_MASK) { case LOCK_S: - row->lock_mode = 1 + is_gap_lock; + row->lock_mode = uint8_t(1 + is_gap_lock); break; case LOCK_X: - row->lock_mode = 3 + is_gap_lock; + row->lock_mode = uint8_t(3 + is_gap_lock); break; case LOCK_IS: - row->lock_mode = 5 + is_gap_lock; + row->lock_mode = uint8_t(5 + is_gap_lock); break; case LOCK_IX: - row->lock_mode = 7 + is_gap_lock; + row->lock_mode = uint8_t(7 + is_gap_lock); break; case LOCK_AUTO_INC: row->lock_mode = 9; diff --git a/storage/innobase/trx/trx0purge.cc b/storage/innobase/trx/trx0purge.cc index df370d91c0b..762ee1fd461 100644 --- a/storage/innobase/trx/trx0purge.cc +++ b/storage/innobase/trx/trx0purge.cc @@ -294,9 +294,9 @@ trx_purge_add_undo_to_history(const trx_t* trx, trx_undo_t*& undo, mtr_t* mtr) } /* Add the log as the first in the history list */ - flst_add_first(rseg_header, TRX_RSEG + TRX_RSEG_HISTORY, - undo_page, undo->hdr_offset + TRX_UNDO_HISTORY_NODE, - mtr); + flst_add_first(rseg_header, TRX_RSEG + TRX_RSEG_HISTORY, undo_page, + static_cast<uint16_t>(undo->hdr_offset + + TRX_UNDO_HISTORY_NODE), mtr); mtr->write<8>(*undo_page, undo_header + TRX_UNDO_TRX_NO, trx->no); /* This is needed for upgrading old undo log pages from @@ -336,7 +336,7 @@ static void trx_purge_remove_log_hdr(buf_block_t *rseg, buf_block_t* log, uint16_t offset, mtr_t *mtr) { flst_remove(rseg, TRX_RSEG + TRX_RSEG_HISTORY, - log, offset + TRX_UNDO_HISTORY_NODE, mtr); + log, static_cast<uint16_t>(offset + TRX_UNDO_HISTORY_NODE), mtr); trx_sys.rseg_history_len--; } @@ -438,8 +438,11 @@ trx_purge_truncate_rseg_history( buf_block_t* rseg_hdr = trx_rsegf_get(rseg.space, rseg.page_no, &mtr); - hdr_addr = trx_purge_get_log_from_hist( - flst_get_last(TRX_RSEG + TRX_RSEG_HISTORY + rseg_hdr->frame)); + hdr_addr = flst_get_last(TRX_RSEG + TRX_RSEG_HISTORY + + rseg_hdr->frame); + hdr_addr.boffset = static_cast<uint16_t>(hdr_addr.boffset + - TRX_UNDO_HISTORY_NODE); + loop: if (hdr_addr.page == FIL_NULL) { func_exit: @@ -464,9 +467,10 @@ func_exit: goto func_exit; } - prev_hdr_addr = trx_purge_get_log_from_hist( - flst_get_prev_addr(block->frame + hdr_addr.boffset - + TRX_UNDO_HISTORY_NODE)); + prev_hdr_addr = flst_get_prev_addr(block->frame + hdr_addr.boffset + + TRX_UNDO_HISTORY_NODE); + prev_hdr_addr.boffset = static_cast<uint16_t>(prev_hdr_addr.boffset + - TRX_UNDO_HISTORY_NODE); if (mach_read_from_2(TRX_UNDO_SEG_HDR + TRX_UNDO_STATE + block->frame) == TRX_UNDO_TO_PURGE @@ -841,8 +845,10 @@ static void trx_purge_rseg_get_next_history_log( (*n_pages_handled)++; - prev_log_addr = trx_purge_get_log_from_hist( - flst_get_prev_addr(log_hdr + TRX_UNDO_HISTORY_NODE)); + prev_log_addr = flst_get_prev_addr(log_hdr + TRX_UNDO_HISTORY_NODE); + prev_log_addr.boffset = static_cast<uint16_t>(prev_log_addr.boffset + - TRX_UNDO_HISTORY_NODE); + const bool empty = prev_log_addr.page == FIL_NULL; diff --git a/storage/innobase/trx/trx0rec.cc b/storage/innobase/trx/trx0rec.cc index 3604b20057c..f451659d2ca 100644 --- a/storage/innobase/trx/trx0rec.cc +++ b/storage/innobase/trx/trx0rec.cc @@ -1401,11 +1401,10 @@ trx_undo_update_rec_get_sys_cols( general parameters */ trx_id_t* trx_id, /*!< out: trx id */ roll_ptr_t* roll_ptr, /*!< out: roll ptr */ - ulint* info_bits) /*!< out: info bits state */ + byte* info_bits) /*!< out: info bits state */ { /* Read the state of the info bits */ - *info_bits = mach_read_from_1(ptr); - ptr += 1; + *info_bits = *ptr++; /* Read the values of the system columns */ @@ -1436,7 +1435,7 @@ trx_undo_update_rec_get_update( the update vector */ trx_id_t trx_id, /*!< in: transaction id from this undo record */ roll_ptr_t roll_ptr,/*!< in: roll pointer from this undo record */ - ulint info_bits,/*!< in: info bits from this undo record */ + byte info_bits,/*!< in: info bits from this undo record */ mem_heap_t* heap, /*!< in: memory heap from which the memory needed is allocated */ upd_t** upd) /*!< out, own: update vector */ @@ -1500,7 +1499,7 @@ trx_undo_update_rec_get_update( &field_no); first_v_col = false; /* This column could be dropped or no longer indexed */ - if (field_no == FIL_NULL) { + if (field_no >= index->n_fields) { /* Mark this is no longer needed */ upd_field->field_no = REC_MAX_N_FIELDS; @@ -1512,12 +1511,14 @@ trx_undo_update_rec_get_update( continue; } - upd_field_set_v_field_no(upd_field, field_no, index); + upd_field_set_v_field_no( + upd_field, static_cast<uint16_t>(field_no), + index); } else if (UNIV_UNLIKELY((update->info_bits & ~REC_INFO_DELETED_FLAG) == REC_INFO_MIN_REC_FLAG)) { ut_ad(type == TRX_UNDO_UPD_EXIST_REC); - const ulint uf = index->first_user_field(); + const uint32_t uf = index->first_user_field(); ut_ad(field_no >= uf); if (update->info_bits != REC_INFO_MIN_REC_FLAG) { @@ -1570,7 +1571,9 @@ trx_undo_update_rec_get_update( upd_field->field_no = field_no & dict_index_t::MAX_N_FIELDS; } else if (field_no < index->n_fields) { - upd_field_set_field_no(upd_field, field_no, index); + upd_field_set_field_no(upd_field, + static_cast<uint16_t>(field_no), + index); } else { ib::error() << "Trying to access update undo rec" " field " << field_no @@ -1590,7 +1593,7 @@ trx_undo_update_rec_get_update( ptr = trx_undo_rec_get_col_val(ptr, &field, &len, &orig_len); - upd_field->orig_len = orig_len; + upd_field->orig_len = static_cast<uint16_t>(orig_len); if (len == UNIV_SQL_NULL) { dfield_set_null(&upd_field->new_val); @@ -2238,7 +2241,7 @@ trx_undo_prev_version_build( roll_ptr_t roll_ptr; upd_t* update; byte* ptr; - ulint info_bits; + byte info_bits; ulint cmpl_info; bool dummy_extern; byte* buf; @@ -2406,8 +2409,9 @@ trx_undo_prev_version_build( ut_ad(!index->table->not_redundant()); ulint l = rec_get_1byte_offs_flag(*old_vers) ? (n + 1) : (n + 1) * 2; - (*old_vers)[-REC_N_OLD_EXTRA_BYTES - l] - |= REC_1BYTE_SQL_NULL_MASK; + byte* b = *old_vers - REC_N_OLD_EXTRA_BYTES + - l; + *b= byte(*b | REC_1BYTE_SQL_NULL_MASK); compile_time_assert(REC_1BYTE_SQL_NULL_MASK << 8 == REC_2BYTE_SQL_NULL_MASK); continue; @@ -2424,7 +2428,7 @@ trx_undo_prev_version_build( ulint l = rec_get_1byte_offs_flag(*old_vers) ? (n + 1) : (n + 1) * 2; (*old_vers)[-REC_N_OLD_EXTRA_BYTES - l] - &= ~REC_1BYTE_SQL_NULL_MASK; + &= byte(~REC_1BYTE_SQL_NULL_MASK); } } } diff --git a/storage/innobase/trx/trx0rseg.cc b/storage/innobase/trx/trx0rseg.cc index b61a2331f46..ccc8ccb6ac1 100644 --- a/storage/innobase/trx/trx0rseg.cc +++ b/storage/innobase/trx/trx0rseg.cc @@ -510,9 +510,11 @@ trx_rseg_mem_restore(trx_rseg_t* rseg, trx_id_t& max_trx_id, mtr_t* mtr) + rseg_hdr->frame)) { trx_sys.rseg_history_len += len; - fil_addr_t node_addr = trx_purge_get_log_from_hist( - flst_get_last(TRX_RSEG + TRX_RSEG_HISTORY - + rseg_hdr->frame)); + fil_addr_t node_addr = flst_get_last(TRX_RSEG + + TRX_RSEG_HISTORY + + rseg_hdr->frame); + node_addr.boffset = static_cast<uint16_t>( + node_addr.boffset - TRX_UNDO_HISTORY_NODE); rseg->last_page_no = node_addr.page; rseg->last_offset = node_addr.boffset; diff --git a/storage/innobase/ut/ut0new.cc b/storage/innobase/ut/ut0new.cc index f47a5112fd7..d1d9e8452f1 100644 --- a/storage/innobase/ut/ut0new.cc +++ b/storage/innobase/ut/ut0new.cc @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 2014, 2016, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2019, MariaDB Corporation. +Copyright (c) 2019, 2020, MariaDB Corporation. 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 the Free Software @@ -192,12 +192,10 @@ ut_new_boot() pfs_info_auto[i].m_flags = 0; } - PSI_MEMORY_CALL(register_memory)("innodb", - pfs_info, - UT_ARR_SIZE(pfs_info)); - PSI_MEMORY_CALL(register_memory)("innodb", - pfs_info_auto, - n_auto); + PSI_MEMORY_CALL(register_memory)("innodb", pfs_info, static_cast<int>( + UT_ARR_SIZE(pfs_info))); + PSI_MEMORY_CALL(register_memory)("innodb", pfs_info_auto, + static_cast<int>(n_auto)); #endif /* UNIV_PFS_MEMORY */ } |