mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
cleanup
* make a local variable for target_table->field[col] * move an often-used bit function to my_bit.h * remove a non-static and not really needed trivial comparison function with a very generic name
This commit is contained in:
@ -121,6 +121,15 @@ static inline uint32 my_reverse_bits(uint32 key)
|
||||
_my_bits_reverse_table[(key>>24) ];
|
||||
}
|
||||
|
||||
/*
|
||||
a number with the n lowest bits set
|
||||
an overflow-safe version of (1 << n) - 1
|
||||
*/
|
||||
static inline uint32 my_set_bits(int n)
|
||||
{
|
||||
return (((1UL << (n - 1)) - 1) << 1) | 1;
|
||||
}
|
||||
|
||||
C_MODE_END
|
||||
|
||||
#endif /* MY_BIT_INCLUDED */
|
||||
|
@ -15,6 +15,7 @@
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
#include <my_global.h>
|
||||
#include <my_bit.h>
|
||||
#include "rpl_utility.h"
|
||||
#include "log_event.h"
|
||||
|
||||
@ -22,30 +23,6 @@
|
||||
#include "rpl_rli.h"
|
||||
#include "sql_select.h"
|
||||
|
||||
/**
|
||||
Function to compare two size_t integers for their relative
|
||||
order. Used below.
|
||||
*/
|
||||
int compare(size_t a, size_t b)
|
||||
{
|
||||
if (a < b)
|
||||
return -1;
|
||||
if (b < a)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Max value for an unsigned integer of 'bits' bits.
|
||||
|
||||
The somewhat contorted expression is to avoid overflow.
|
||||
*/
|
||||
uint32 uint_max(int bits) {
|
||||
return (((1UL << (bits - 1)) - 1) << 1) | 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Calculate display length for MySQL56 temporal data types from their metadata.
|
||||
It contains fractional precision in the low 16-bit word.
|
||||
@ -160,10 +137,10 @@ max_display_length_for_field(enum_field_types sql_type, unsigned int metadata)
|
||||
*/
|
||||
|
||||
case MYSQL_TYPE_TINY_BLOB:
|
||||
return uint_max(1 * 8);
|
||||
return my_set_bits(1 * 8);
|
||||
|
||||
case MYSQL_TYPE_MEDIUM_BLOB:
|
||||
return uint_max(3 * 8);
|
||||
return my_set_bits(3 * 8);
|
||||
|
||||
case MYSQL_TYPE_BLOB:
|
||||
/*
|
||||
@ -171,11 +148,11 @@ max_display_length_for_field(enum_field_types sql_type, unsigned int metadata)
|
||||
blobs are of type MYSQL_TYPE_BLOB. In that case, we have to look
|
||||
at the length instead to decide what the max display size is.
|
||||
*/
|
||||
return uint_max(metadata * 8);
|
||||
return my_set_bits(metadata * 8);
|
||||
|
||||
case MYSQL_TYPE_LONG_BLOB:
|
||||
case MYSQL_TYPE_GEOMETRY:
|
||||
return uint_max(4 * 8);
|
||||
return my_set_bits(4 * 8);
|
||||
|
||||
default:
|
||||
return ~(uint32) 0;
|
||||
@ -205,7 +182,7 @@ int compare_lengths(Field *field, enum_field_types source_type, uint16 metadata)
|
||||
" target_length: %lu, target_type: %u",
|
||||
(unsigned long) source_length, source_type,
|
||||
(unsigned long) target_length, field->real_type()));
|
||||
int result= compare(source_length, target_length);
|
||||
int result= source_length < target_length ? -1 : source_length > target_length;
|
||||
DBUG_PRINT("result", ("%d", result));
|
||||
DBUG_RETURN(result);
|
||||
}
|
||||
@ -950,6 +927,7 @@ TABLE *table_def::create_conversion_table(THD *thd, rpl_group_info *rgi,
|
||||
{
|
||||
Create_field *field_def=
|
||||
(Create_field*) alloc_root(thd->mem_root, sizeof(Create_field));
|
||||
Field *target_field= target_table->field[col];
|
||||
bool unsigned_flag= 0;
|
||||
if (field_list.push_back(field_def, thd->mem_root))
|
||||
DBUG_RETURN(NULL);
|
||||
@ -964,7 +942,7 @@ TABLE *table_def::create_conversion_table(THD *thd, rpl_group_info *rgi,
|
||||
int precision;
|
||||
case MYSQL_TYPE_ENUM:
|
||||
case MYSQL_TYPE_SET:
|
||||
interval= static_cast<Field_enum*>(target_table->field[col])->typelib;
|
||||
interval= static_cast<Field_enum*>(target_field)->typelib;
|
||||
pack_length= field_metadata(col) & 0x00ff;
|
||||
break;
|
||||
|
||||
@ -988,7 +966,7 @@ TABLE *table_def::create_conversion_table(THD *thd, rpl_group_info *rgi,
|
||||
" column Name: %s.%s.%s.",
|
||||
target_table->s->db.str,
|
||||
target_table->s->table_name.str,
|
||||
target_table->field[col]->field_name);
|
||||
target_field->field_name);
|
||||
goto err;
|
||||
|
||||
case MYSQL_TYPE_TINY_BLOB:
|
||||
@ -1009,7 +987,7 @@ TABLE *table_def::create_conversion_table(THD *thd, rpl_group_info *rgi,
|
||||
assume we have same sign on master and slave. This is true when not
|
||||
using conversions so it should be true also when using conversions.
|
||||
*/
|
||||
unsigned_flag= ((Field_num*) target_table->field[col])->unsigned_flag;
|
||||
unsigned_flag= static_cast<Field_num*>(target_field)->unsigned_flag;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -1017,7 +995,7 @@ TABLE *table_def::create_conversion_table(THD *thd, rpl_group_info *rgi,
|
||||
|
||||
DBUG_PRINT("debug", ("sql_type: %d, target_field: '%s', max_length: %d, decimals: %d,"
|
||||
" maybe_null: %d, unsigned_flag: %d, pack_length: %u",
|
||||
binlog_type(col), target_table->field[col]->field_name,
|
||||
binlog_type(col), target_field->field_name,
|
||||
max_length, decimals, TRUE, unsigned_flag,
|
||||
pack_length));
|
||||
field_def->init_for_tmp_table(type(col),
|
||||
@ -1026,7 +1004,7 @@ TABLE *table_def::create_conversion_table(THD *thd, rpl_group_info *rgi,
|
||||
TRUE, // maybe_null
|
||||
unsigned_flag,
|
||||
pack_length);
|
||||
field_def->charset= target_table->field[col]->charset();
|
||||
field_def->charset= target_field->charset();
|
||||
field_def->interval= interval;
|
||||
}
|
||||
|
||||
|
@ -5069,7 +5069,7 @@ static Sys_var_set Sys_log_slow_filter(
|
||||
"Log only certain types of queries",
|
||||
SESSION_VAR(log_slow_filter), CMD_LINE(REQUIRED_ARG),
|
||||
log_slow_filter_names,
|
||||
DEFAULT(MAX_SET(array_elements(log_slow_filter_names)-1)));
|
||||
DEFAULT(my_set_bits(array_elements(log_slow_filter_names)-1)));
|
||||
|
||||
static const char *default_regex_flags_names[]=
|
||||
{
|
||||
|
@ -1094,9 +1094,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
// overflow-safe (1 << X)-1
|
||||
#define MAX_SET(X) ((((1UL << ((X)-1))-1) << 1) | 1)
|
||||
|
||||
/**
|
||||
The class for flagset variables - a variant of SET that allows in-place
|
||||
editing (turning on/off individual bits). String representations looks like
|
||||
@ -1131,7 +1128,7 @@ public:
|
||||
global_var(ulonglong)= def_val;
|
||||
SYSVAR_ASSERT(typelib.count > 1);
|
||||
SYSVAR_ASSERT(typelib.count <= 65);
|
||||
SYSVAR_ASSERT(def_val < MAX_SET(typelib.count));
|
||||
SYSVAR_ASSERT(def_val < my_set_bits(typelib.count));
|
||||
SYSVAR_ASSERT(strcmp(values[typelib.count-1], "default") == 0);
|
||||
SYSVAR_ASSERT(size == sizeof(ulonglong));
|
||||
}
|
||||
@ -1179,7 +1176,7 @@ public:
|
||||
{
|
||||
longlong tmp=var->value->val_int();
|
||||
if ((tmp < 0 && ! var->value->unsigned_flag)
|
||||
|| (ulonglong)tmp > MAX_SET(typelib.count))
|
||||
|| (ulonglong)tmp > my_set_bits(typelib.count))
|
||||
return true;
|
||||
else
|
||||
var->save_result.ulonglong_value= tmp;
|
||||
@ -1240,7 +1237,7 @@ public:
|
||||
global_var(ulonglong)= def_val;
|
||||
SYSVAR_ASSERT(typelib.count > 0);
|
||||
SYSVAR_ASSERT(typelib.count <= 64);
|
||||
SYSVAR_ASSERT(def_val <= MAX_SET(typelib.count));
|
||||
SYSVAR_ASSERT(def_val <= my_set_bits(typelib.count));
|
||||
SYSVAR_ASSERT(size == sizeof(ulonglong));
|
||||
}
|
||||
bool do_check(THD *thd, set_var *var)
|
||||
@ -1278,7 +1275,7 @@ public:
|
||||
{
|
||||
longlong tmp=var->value->val_int();
|
||||
if ((tmp < 0 && ! var->value->unsigned_flag)
|
||||
|| (ulonglong)tmp > MAX_SET(typelib.count))
|
||||
|| (ulonglong)tmp > my_set_bits(typelib.count))
|
||||
return true;
|
||||
else
|
||||
var->save_result.ulonglong_value= tmp;
|
||||
|
Reference in New Issue
Block a user