16 #include "rpl_utility.h"
35 static int compare(
size_t a,
size_t b)
50 static uint32 uint_max(
int bits) {
51 return (((1UL << (bits - 1)) - 1) << 1) | 1;
63 max_display_length_for_field(enum_field_types sql_type,
unsigned int metadata)
65 DBUG_PRINT(
"debug", (
"sql_type: %d, metadata: 0x%x", sql_type, metadata));
66 DBUG_ASSERT(metadata >> 16 == 0);
69 case MYSQL_TYPE_NEWDECIMAL:
72 case MYSQL_TYPE_FLOAT:
75 case MYSQL_TYPE_DOUBLE:
80 return metadata & 0x00ff;
82 case MYSQL_TYPE_STRING:
84 uchar
type= metadata >> 8;
85 if (type == MYSQL_TYPE_SET || type == MYSQL_TYPE_ENUM)
86 return metadata & 0xff;
89 return (((metadata >> 4) & 0x300) ^ 0x300) + (metadata & 0x00ff);
96 case MYSQL_TYPE_SHORT:
99 case MYSQL_TYPE_INT24:
102 case MYSQL_TYPE_LONG:
105 #ifdef HAVE_LONG_LONG
106 case MYSQL_TYPE_LONGLONG:
110 case MYSQL_TYPE_NULL:
113 case MYSQL_TYPE_NEWDATE:
116 case MYSQL_TYPE_DATE:
117 case MYSQL_TYPE_TIME:
118 case MYSQL_TYPE_TIME2:
121 case MYSQL_TYPE_TIMESTAMP:
122 case MYSQL_TYPE_TIMESTAMP2:
125 case MYSQL_TYPE_DATETIME:
126 case MYSQL_TYPE_DATETIME2:
133 DBUG_ASSERT((metadata & 0xff) <= 7);
134 return 8 * (metadata >> 8
U) + (metadata & 0x00ff);
136 case MYSQL_TYPE_VAR_STRING:
137 case MYSQL_TYPE_VARCHAR:
149 case MYSQL_TYPE_TINY_BLOB:
150 return uint_max(1 * 8);
152 case MYSQL_TYPE_MEDIUM_BLOB:
153 return uint_max(3 * 8);
155 case MYSQL_TYPE_BLOB:
161 return uint_max(metadata * 8);
163 case MYSQL_TYPE_LONG_BLOB:
164 case MYSQL_TYPE_GEOMETRY:
165 return uint_max(4 * 8);
185 int compare_lengths(
Field *field, enum_field_types source_type, uint16 metadata)
187 DBUG_ENTER(
"compare_lengths");
188 size_t const source_length=
189 max_display_length_for_field(source_type, metadata);
190 size_t const target_length= field->max_display_length();
191 DBUG_PRINT(
"debug", (
"source_length: %lu, source_type: %u,"
192 " target_length: %lu, target_type: %u",
193 (
unsigned long) source_length, source_type,
194 (
unsigned long) target_length, field->real_type()));
195 int result=
compare(source_length, target_length);
196 DBUG_PRINT(
"result", (
"%d", result));
209 uint32 table_def::calc_field_size(uint col, uchar *master_data)
const
214 case MYSQL_TYPE_NEWDECIMAL:
215 length= my_decimal_get_binary_size(m_field_metadata[col] >> 8,
216 m_field_metadata[col] & 0xff);
218 case MYSQL_TYPE_DECIMAL:
219 case MYSQL_TYPE_FLOAT:
220 case MYSQL_TYPE_DOUBLE:
221 length= m_field_metadata[col];
229 case MYSQL_TYPE_ENUM:
230 case MYSQL_TYPE_STRING:
232 uchar type= m_field_metadata[col] >> 8
U;
233 if ((type == MYSQL_TYPE_SET) || (type == MYSQL_TYPE_ENUM))
234 length= m_field_metadata[col] & 0x00ff;
242 length= max_display_length_for_field(MYSQL_TYPE_STRING, m_field_metadata[col]) > 255 ? 2 : 1;
245 length+= ((length == 1) ? *master_data : uint2korr(master_data));
249 case MYSQL_TYPE_YEAR:
250 case MYSQL_TYPE_TINY:
253 case MYSQL_TYPE_SHORT:
256 case MYSQL_TYPE_INT24:
259 case MYSQL_TYPE_LONG:
262 #ifdef HAVE_LONG_LONG
263 case MYSQL_TYPE_LONGLONG:
267 case MYSQL_TYPE_NULL:
270 case MYSQL_TYPE_NEWDATE:
273 case MYSQL_TYPE_DATE:
274 case MYSQL_TYPE_TIME:
277 case MYSQL_TYPE_TIME2:
278 length= my_time_binary_length(m_field_metadata[col]);
280 case MYSQL_TYPE_TIMESTAMP:
283 case MYSQL_TYPE_TIMESTAMP2:
284 length= my_timestamp_binary_length(m_field_metadata[col]);
286 case MYSQL_TYPE_DATETIME:
289 case MYSQL_TYPE_DATETIME2:
290 length= my_datetime_binary_length(m_field_metadata[col]);
301 uint from_len= (m_field_metadata[col] >> 8U) & 0x00ff;
302 uint from_bit_len= m_field_metadata[col] & 0x00ff;
303 DBUG_ASSERT(from_bit_len <= 7);
304 length= from_len + ((from_bit_len > 0) ? 1 : 0);
307 case MYSQL_TYPE_VARCHAR:
309 length= m_field_metadata[col] > 255 ? 2 : 1;
310 length+= length == 1 ? (uint32) *master_data : uint2korr(master_data);
313 case MYSQL_TYPE_TINY_BLOB:
314 case MYSQL_TYPE_MEDIUM_BLOB:
315 case MYSQL_TYPE_LONG_BLOB:
316 case MYSQL_TYPE_BLOB:
317 case MYSQL_TYPE_GEOMETRY:
328 length= fb.get_packed_size(master_data, TRUE);
336 switch (m_field_metadata[col]) {
338 length= *master_data;
341 length= uint2korr(master_data);
344 length= uint3korr(master_data);
347 length= uint4korr(master_data);
354 length+= m_field_metadata[col];
367 static void show_sql_type(enum_field_types type, uint16 metadata,
String *str,
370 DBUG_ENTER(
"show_sql_type");
371 DBUG_PRINT(
"enter", (
"type: %d, metadata: 0x%x", type, metadata));
375 case MYSQL_TYPE_TINY:
376 str->set_ascii(STRING_WITH_LEN(
"tinyint"));
379 case MYSQL_TYPE_SHORT:
380 str->set_ascii(STRING_WITH_LEN(
"smallint"));
383 case MYSQL_TYPE_LONG:
384 str->set_ascii(STRING_WITH_LEN(
"int"));
387 case MYSQL_TYPE_FLOAT:
388 str->set_ascii(STRING_WITH_LEN(
"float"));
391 case MYSQL_TYPE_DOUBLE:
392 str->set_ascii(STRING_WITH_LEN(
"double"));
395 case MYSQL_TYPE_NULL:
396 str->set_ascii(STRING_WITH_LEN(
"null"));
399 case MYSQL_TYPE_TIMESTAMP:
400 case MYSQL_TYPE_TIMESTAMP2:
401 str->set_ascii(STRING_WITH_LEN(
"timestamp"));
404 case MYSQL_TYPE_LONGLONG:
405 str->set_ascii(STRING_WITH_LEN(
"bigint"));
408 case MYSQL_TYPE_INT24:
409 str->set_ascii(STRING_WITH_LEN(
"mediumint"));
412 case MYSQL_TYPE_NEWDATE:
413 case MYSQL_TYPE_DATE:
414 str->set_ascii(STRING_WITH_LEN(
"date"));
417 case MYSQL_TYPE_TIME:
418 case MYSQL_TYPE_TIME2:
419 str->set_ascii(STRING_WITH_LEN(
"time"));
422 case MYSQL_TYPE_DATETIME:
423 case MYSQL_TYPE_DATETIME2:
424 str->set_ascii(STRING_WITH_LEN(
"datetime"));
427 case MYSQL_TYPE_YEAR:
428 str->set_ascii(STRING_WITH_LEN(
"year"));
431 case MYSQL_TYPE_VAR_STRING:
432 case MYSQL_TYPE_VARCHAR:
436 cs->cset->snprintf(cs, (
char*) str->ptr(), str->alloced_length(),
437 "varchar(%u)", metadata);
445 int bit_length= 8 * (metadata >> 8) + (metadata & 0xFF);
447 cs->cset->snprintf(cs, (
char*) str->ptr(), str->alloced_length(),
448 "bit(%d)", bit_length);
453 case MYSQL_TYPE_DECIMAL:
457 cs->cset->snprintf(cs, (
char*) str->ptr(), str->alloced_length(),
458 "decimal(%d,?)", metadata);
463 case MYSQL_TYPE_NEWDECIMAL:
467 cs->cset->snprintf(cs, (
char*) str->ptr(), str->alloced_length(),
468 "decimal(%d,%d)", metadata >> 8, metadata & 0xff);
473 case MYSQL_TYPE_ENUM:
474 str->set_ascii(STRING_WITH_LEN(
"enum"));
478 str->set_ascii(STRING_WITH_LEN(
"set"));
481 case MYSQL_TYPE_BLOB:
487 switch (get_blob_type_from_length(metadata))
489 case MYSQL_TYPE_TINY_BLOB:
490 str->set_ascii(STRING_WITH_LEN(
"tinyblob"));
493 case MYSQL_TYPE_MEDIUM_BLOB:
494 str->set_ascii(STRING_WITH_LEN(
"mediumblob"));
497 case MYSQL_TYPE_LONG_BLOB:
498 str->set_ascii(STRING_WITH_LEN(
"longblob"));
501 case MYSQL_TYPE_BLOB:
502 str->set_ascii(STRING_WITH_LEN(
"blob"));
511 case MYSQL_TYPE_STRING:
517 uint bytes= (((metadata >> 4) & 0x300) ^ 0x300) + (metadata & 0x00ff);
519 cs->cset->snprintf(cs, (
char*) str->ptr(), str->alloced_length(),
520 "char(%d)", bytes / field_cs->mbmaxlen);
525 case MYSQL_TYPE_GEOMETRY:
526 str->set_ascii(STRING_WITH_LEN(
"geometry"));
530 str->set_ascii(STRING_WITH_LEN(
"<unknown type>"));
545 DBUG_ENTER(
"is_conversion_ok");
546 bool allow_non_lossy, allow_lossy;
548 allow_non_lossy = slave_type_conversions_options &
549 (ULL(1) << SLAVE_TYPE_CONVERSIONS_ALL_NON_LOSSY);
550 allow_lossy= slave_type_conversions_options &
551 (ULL(1) << SLAVE_TYPE_CONVERSIONS_ALL_LOSSY);
553 DBUG_PRINT(
"enter", (
"order: %d, flags:%s%s", order,
554 allow_non_lossy ?
" ALL_NON_LOSSY" :
"",
555 allow_lossy ?
" ALL_LOSSY" :
""));
556 if (order < 0 && !allow_non_lossy)
562 if (order > 0 && !allow_lossy)
604 can_convert_field_to(
Field *field,
605 enum_field_types source_type, uint16 metadata,
609 DBUG_ENTER(
"can_convert_field_to");
611 char field_type_buf[MAX_FIELD_WIDTH];
612 String field_type(field_type_buf,
sizeof(field_type_buf), &my_charset_latin1);
613 field->sql_type(field_type);
614 DBUG_PRINT(
"enter", (
"field_type: %s, target_type: %d, source_type: %d, source_metadata: 0x%x",
615 field_type.c_ptr_safe(), field->real_type(), source_type, metadata));
621 if (field->real_type() == source_type)
631 DBUG_PRINT(
"debug", (
"Base types are identical, but there is no metadata"));
636 DBUG_PRINT(
"debug", (
"Base types are identical, doing field size comparison"));
638 DBUG_RETURN(is_conversion_ok(*order_var, rli));
642 else if (metadata == 0 &&
643 ((field->real_type() == MYSQL_TYPE_TIMESTAMP2 &&
644 source_type == MYSQL_TYPE_TIMESTAMP) ||
645 (field->real_type() == MYSQL_TYPE_TIME2 &&
646 source_type == MYSQL_TYPE_TIME) ||
647 (field->real_type() == MYSQL_TYPE_DATETIME2 &&
648 source_type == MYSQL_TYPE_DATETIME)))
659 else if (!slave_type_conversions_options)
668 DBUG_PRINT(
"debug", (
"Base types are different, checking conversion"));
671 case MYSQL_TYPE_DECIMAL:
672 case MYSQL_TYPE_NEWDECIMAL:
673 case MYSQL_TYPE_FLOAT:
674 case MYSQL_TYPE_DOUBLE:
675 switch (field->real_type())
677 case MYSQL_TYPE_NEWDECIMAL:
683 DBUG_RETURN(is_conversion_ok(*order_var, rli));
685 case MYSQL_TYPE_DECIMAL:
686 case MYSQL_TYPE_FLOAT:
687 case MYSQL_TYPE_DOUBLE:
689 if (source_type == MYSQL_TYPE_NEWDECIMAL ||
690 source_type == MYSQL_TYPE_DECIMAL)
693 *order_var= compare_lengths(field, source_type, metadata);
694 DBUG_ASSERT(*order_var != 0);
695 DBUG_RETURN(is_conversion_ok(*order_var, rli));
707 case MYSQL_TYPE_TINY:
708 case MYSQL_TYPE_SHORT:
709 case MYSQL_TYPE_INT24:
710 case MYSQL_TYPE_LONG:
711 case MYSQL_TYPE_LONGLONG:
712 switch (field->real_type())
714 case MYSQL_TYPE_TINY:
715 case MYSQL_TYPE_SHORT:
716 case MYSQL_TYPE_INT24:
717 case MYSQL_TYPE_LONG:
718 case MYSQL_TYPE_LONGLONG:
719 *order_var= compare_lengths(field, source_type, metadata);
720 DBUG_ASSERT(*order_var != 0);
721 DBUG_RETURN(is_conversion_ok(*order_var, rli));
741 case MYSQL_TYPE_TINY_BLOB:
742 case MYSQL_TYPE_MEDIUM_BLOB:
743 case MYSQL_TYPE_LONG_BLOB:
744 case MYSQL_TYPE_BLOB:
745 case MYSQL_TYPE_STRING:
746 case MYSQL_TYPE_VAR_STRING:
747 case MYSQL_TYPE_VARCHAR:
748 switch (field->real_type())
750 case MYSQL_TYPE_TINY_BLOB:
751 case MYSQL_TYPE_MEDIUM_BLOB:
752 case MYSQL_TYPE_LONG_BLOB:
753 case MYSQL_TYPE_BLOB:
754 case MYSQL_TYPE_STRING:
755 case MYSQL_TYPE_VAR_STRING:
756 case MYSQL_TYPE_VARCHAR:
757 *order_var= compare_lengths(field, source_type, metadata);
766 DBUG_RETURN(is_conversion_ok(*order_var, rli));
773 case MYSQL_TYPE_GEOMETRY:
774 case MYSQL_TYPE_TIMESTAMP:
775 case MYSQL_TYPE_DATE:
776 case MYSQL_TYPE_TIME:
777 case MYSQL_TYPE_DATETIME:
778 case MYSQL_TYPE_YEAR:
779 case MYSQL_TYPE_NEWDATE:
780 case MYSQL_TYPE_NULL:
781 case MYSQL_TYPE_ENUM:
783 case MYSQL_TYPE_TIMESTAMP2:
784 case MYSQL_TYPE_DATETIME2:
785 case MYSQL_TYPE_TIME2:
827 uint
const cols_to_check= min<ulong>(table->s->fields,
size());
828 TABLE *tmp_table= NULL;
830 for (uint col= 0 ; col < cols_to_check ; ++col)
832 Field *
const field= table->field[col];
834 if (can_convert_field_to(field, type(col), field_metadata(col), rli, m_flags, &order))
836 DBUG_PRINT(
"debug", (
"Checking column %d -"
837 " field '%s' can be converted - order: %d",
838 col, field->field_name, order));
839 DBUG_ASSERT(order >= -1 && order <= 1);
845 if (order != 0 && tmp_table == NULL)
852 if (tmp_table == NULL)
857 for (
unsigned int i= 0;
i < col; ++
i)
858 tmp_table->field[
i]= NULL;
861 if (order == 0 && tmp_table != NULL)
862 tmp_table->field[col]= NULL;
866 DBUG_PRINT(
"debug", (
"Checking column %d -"
867 " field '%s' can not be converted",
868 col, field->field_name));
869 DBUG_ASSERT(col <
size() && col < table->s->fields);
870 DBUG_ASSERT(table->s->db.str && table->s->table_name.str);
871 const char *db_name= table->s->db.str;
872 const char *tbl_name= table->s->table_name.str;
873 char source_buf[MAX_FIELD_WIDTH];
874 char target_buf[MAX_FIELD_WIDTH];
875 String source_type(source_buf,
sizeof(source_buf), &my_charset_latin1);
876 String target_type(target_buf,
sizeof(target_buf), &my_charset_latin1);
877 show_sql_type(type(col), field_metadata(col), &source_type, field->charset());
878 field->sql_type(target_type);
879 rli->
report(ERROR_LEVEL, ER_SLAVE_CONVERSION_FAILED,
880 ER(ER_SLAVE_CONVERSION_FAILED),
881 col, db_name, tbl_name,
882 source_type.c_ptr_safe(), target_type.c_ptr_safe());
890 for (
unsigned int col= 0; col < tmp_table->s->fields; ++col)
891 if (tmp_table->field[col])
893 char source_buf[MAX_FIELD_WIDTH];
894 char target_buf[MAX_FIELD_WIDTH];
895 String source_type(source_buf,
sizeof(source_buf), &my_charset_latin1);
896 String target_type(target_buf,
sizeof(target_buf), &my_charset_latin1);
897 tmp_table->field[col]->sql_type(source_type);
898 table->field[col]->sql_type(target_type);
899 DBUG_PRINT(
"debug", (
"Field %s - conversion required."
900 " Source type: '%s', Target type: '%s'",
901 tmp_table->field[col]->field_name,
902 source_type.c_ptr_safe(), target_type.c_ptr_safe()));
907 *conv_table_var= tmp_table;
923 DBUG_ENTER(
"table_def::create_conversion_table");
926 TABLE *conv_table= NULL;
932 uint
const cols_to_create= min<ulong>(target_table->s->fields,
size());
935 bool unsigned_flag= FALSE;
938 unsigned_flag= slave_type_conversions_options &
939 (ULL(1) << SLAVE_TYPE_CONVERSIONS_ALL_UNSIGNED);
942 unsigned_flag= unsigned_flag && !(slave_type_conversions_options &
943 (ULL(1) << SLAVE_TYPE_CONVERSIONS_ALL_SIGNED));
945 for (uint col= 0 ; col < cols_to_create; ++col)
949 if (field_list.push_back(field_def))
956 max_display_length_for_field(type(col), field_metadata(col));
961 case MYSQL_TYPE_ENUM:
963 interval=
static_cast<Field_enum*
>(target_table->field[col])->typelib;
964 pack_length= field_metadata(col) & 0x00ff;
967 case MYSQL_TYPE_NEWDECIMAL:
973 precision= field_metadata(col) >> 8;
974 decimals= field_metadata(col) & 0x00ff;
976 my_decimal_precision_to_length(precision, decimals, FALSE);
979 case MYSQL_TYPE_DECIMAL:
980 sql_print_error(
"In RBR mode, Slave received incompatible DECIMAL field "
981 "(old-style decimal field) from Master while creating "
982 "conversion table. Please consider changing datatype on "
983 "Master to new style decimal by executing ALTER command for"
984 " column Name: %s.%s.%s.",
985 target_table->s->db.str,
986 target_table->s->table_name.str,
987 target_table->field[col]->field_name);
990 case MYSQL_TYPE_TINY_BLOB:
991 case MYSQL_TYPE_MEDIUM_BLOB:
992 case MYSQL_TYPE_LONG_BLOB:
993 case MYSQL_TYPE_BLOB:
994 case MYSQL_TYPE_GEOMETRY:
995 pack_length= field_metadata(col) & 0x00ff;
1002 DBUG_PRINT(
"debug", (
"sql_type: %d, target_field: '%s', max_length: %d, decimals: %d,"
1003 " maybe_null: %d, unsigned_flag: %d, pack_length: %u",
1004 binlog_type(col), target_table->field[col]->field_name,
1005 max_length, decimals, TRUE, unsigned_flag, pack_length));
1012 field_def->charset= target_table->field[col]->charset();
1013 field_def->interval= interval;
1016 conv_table= create_virtual_tmp_table(thd, field_list);
1019 if (conv_table == NULL)
1020 rli->
report(ERROR_LEVEL, ER_SLAVE_CANT_CREATE_CONVERSION,
1021 ER(ER_SLAVE_CANT_CREATE_CONVERSION),
1022 target_table->s->db.str,
1023 target_table->s->table_name.str);
1024 DBUG_RETURN(conv_table);
1030 uchar *field_metadata,
int metadata_size,
1031 uchar *null_bitmap, uint16
flags)
1032 : m_size(size), m_type(0), m_field_metadata_size(metadata_size),
1033 m_field_metadata(0), m_null_bits(0), m_flags(flags),
1036 m_memory= (uchar *)my_multi_malloc(MYF(MY_WME),
1039 size *
sizeof(uint16),
1040 &m_null_bits, (size + 7) / 8,
1043 memset(m_field_metadata, 0, size *
sizeof(uint16));
1046 memcpy(m_type, types, size);
1056 if (m_size && metadata_size)
1059 for (
unsigned int i= 0;
i < m_size;
i++)
1061 switch (binlog_type(
i)) {
1062 case MYSQL_TYPE_TINY_BLOB:
1063 case MYSQL_TYPE_BLOB:
1064 case MYSQL_TYPE_MEDIUM_BLOB:
1065 case MYSQL_TYPE_LONG_BLOB:
1066 case MYSQL_TYPE_DOUBLE:
1067 case MYSQL_TYPE_FLOAT:
1068 case MYSQL_TYPE_GEOMETRY:
1073 m_field_metadata[
i]= field_metadata[
index];
1077 case MYSQL_TYPE_SET:
1078 case MYSQL_TYPE_ENUM:
1079 case MYSQL_TYPE_STRING:
1081 uint16 x= field_metadata[index++] << 8U;
1082 x+= field_metadata[index++];
1083 m_field_metadata[
i]= x;
1086 case MYSQL_TYPE_BIT:
1088 uint16 x= field_metadata[index++];
1089 x = x + (field_metadata[index++] << 8U);
1090 m_field_metadata[
i]= x;
1093 case MYSQL_TYPE_VARCHAR:
1098 char *ptr= (
char *)&field_metadata[index];
1099 m_field_metadata[
i]= uint2korr(ptr);
1103 case MYSQL_TYPE_NEWDECIMAL:
1105 uint16 x= field_metadata[index++] << 8U;
1106 x+= field_metadata[index++];
1107 m_field_metadata[
i]= x;
1110 case MYSQL_TYPE_TIME2:
1111 case MYSQL_TYPE_DATETIME2:
1112 case MYSQL_TYPE_TIMESTAMP2:
1113 m_field_metadata[
i]= field_metadata[index++];
1116 m_field_metadata[
i]= 0;
1121 if (m_size && null_bitmap)
1122 memcpy(m_null_bits, null_bitmap, (m_size + 7) / 8);
1126 table_def::~table_def()
1147 if (alg != BINLOG_CHECKSUM_ALG_OFF && alg != BINLOG_CHECKSUM_ALG_UNDEF)
1149 ha_checksum incoming;
1150 ha_checksum computed;
1152 if (event_buf[EVENT_TYPE_OFFSET] == FORMAT_DESCRIPTION_EVENT)
1156 BINLOG_CHECKSUM_ALG_DESC_LEN];
1161 flags= uint2korr(event_buf + FLAGS_OFFSET);
1162 if (flags & LOG_EVENT_BINLOG_IN_USE_F)
1163 event_buf[FLAGS_OFFSET] &= ~LOG_EVENT_BINLOG_IN_USE_F;
1168 DBUG_ASSERT(fd_alg == BINLOG_CHECKSUM_ALG_CRC32 || fd_alg == 0);
1169 DBUG_ASSERT(alg == BINLOG_CHECKSUM_ALG_CRC32);
1173 compile_time_assert(BINLOG_CHECKSUM_ALG_ENUM_END <= 0x80);
1176 computed= my_checksum(0L, NULL, 0);
1178 computed= my_checksum(computed, (
const uchar*) event_buf,
1183 DBUG_ASSERT(event_buf[EVENT_TYPE_OFFSET] == FORMAT_DESCRIPTION_EVENT);
1184 event_buf[FLAGS_OFFSET]=
flags;
1186 res= !(computed == incoming);
1188 return DBUG_EVALUATE_IF(
"simulate_checksum_test_failure", TRUE, res);
1191 #ifndef MYSQL_CLIENT
1193 #define HASH_ROWS_POS_SEARCH_INVALID -1
1200 hash_slave_rows_get_key(
const uchar *
record,
1202 my_bool not_used __attribute__((unused)))
1204 DBUG_ENTER(
"get_key");
1208 *length= preamble->
length;
1210 DBUG_RETURN((uchar*) &preamble->hash_value);
1216 DBUG_ENTER(
"free_entry");
1219 if (entry->preamble)
1220 my_free(entry->preamble);
1221 if (entry->positions)
1222 my_free(entry->positions);
1230 return (m_hash.records == 0);
1239 if (my_hash_init(&m_hash,
1244 hash_slave_rows_get_key,
1245 (my_hash_free_key) hash_slave_rows_free_entry,
1253 if (my_hash_inited(&m_hash))
1254 my_hash_free(&m_hash);
1261 return m_hash.records;
1271 DBUG_ENTER(
"Hash_slave_rows::make_entry");
1277 if (!entry || !preamble || !pos)
1283 preamble->hash_value= 0;
1284 preamble->
length=
sizeof(my_hash_value_type);
1291 pos->
bi_start= (
const uchar *) bi_start;
1292 pos->bi_ends= (
const uchar *) bi_ends;
1297 entry->preamble= preamble;
1298 entry->positions= pos;
1318 DBUG_ENTER(
"Hash_slave_rows::put");
1328 preamble->hash_value= make_hash_key(table, cols);
1330 my_hash_insert(&m_hash, (uchar *) entry);
1331 DBUG_PRINT(
"debug", (
"Added record to hash with key=%u", preamble->hash_value));
1338 DBUG_ENTER(
"Hash_slave_rows::get");
1339 HASH_SEARCH_STATE state;
1340 my_hash_value_type key;
1343 key= make_hash_key(table, cols);
1345 DBUG_PRINT(
"debug", (
"Looking for record with key=%u in the hash.", key));
1348 (
const uchar*) &key,
1349 sizeof(my_hash_value_type),
1353 DBUG_PRINT(
"debug", (
"Found record with key=%u in the hash.", key));
1368 DBUG_ENTER(
"Hash_slave_rows::next");
1369 DBUG_ASSERT(*entry);
1379 my_hash_value_type key= preamble->hash_value;
1390 DBUG_PRINT(
"debug", (
"Looking for record with key=%u in the hash (next).", key));
1396 (
const uchar*) &key,
1397 sizeof(my_hash_value_type),
1401 DBUG_PRINT(
"debug", (
"Found record with key=%u in the hash (next).", key));
1402 preamble= (*entry)->preamble;
1417 DBUG_ENTER(
"Hash_slave_rows::del");
1420 if (my_hash_delete(&m_hash, (uchar *) entry))
1428 DBUG_ENTER(
"Hash_slave_rows::make_hash_key");
1429 ha_checksum crc= 0L;
1431 uchar *record= table->record[0];
1432 uchar saved_x= 0, saved_filler= 0;
1434 if (table->s->null_bytes > 0)
1439 if (!(table->s->db_options_in_use & HA_OPTION_PACK_RECORD))
1450 if (table->s->last_null_bit_pos > 0)
1452 saved_filler= record[table->s->null_bytes - 1];
1453 record[table->s->null_bytes - 1]|=
1454 256U - (1U << table->s->last_null_bit_pos);
1467 if (bitmap_is_set_all(cols))
1469 crc= my_checksum(crc, table->null_flags, table->s->null_bytes);
1470 DBUG_PRINT(
"debug", (
"make_hash_entry: hash after null_flags: %u", crc));
1473 for (
Field **ptr=table->field ;
1474 *ptr && ((*ptr)->field_index < cols->n_bits);
1482 if (bitmap_is_set(cols, f->field_index) && !f->is_null())
1489 switch (f->type()) {
1490 case MYSQL_TYPE_BLOB:
1491 case MYSQL_TYPE_VARCHAR:
1492 case MYSQL_TYPE_GEOMETRY:
1493 case MYSQL_TYPE_BIT:
1497 crc= my_checksum(crc, (uchar*) tmp.ptr(), tmp.length());
1501 crc= my_checksum(crc, f->ptr, f->data_length());
1507 DBUG_PRINT(
"debug", (
"make_hash_entry: hash after field %s=%s: %u", f->field_name, tmp.c_ptr_safe(), crc));
1518 if (table->s->null_bytes > 0)
1520 if (!(table->s->db_options_in_use & HA_OPTION_PACK_RECORD))
1523 if (table->s->last_null_bit_pos)
1524 record[table->s->null_bytes - 1]= saved_filler;
1527 DBUG_PRINT(
"debug", (
"Created key=%u", crc));
1534 #if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION)
1538 my_init_dynamic_array(&array,
sizeof(
Log_event *), 32, 16);
1541 Deferred_log_events::~Deferred_log_events()
1543 delete_dynamic(&array);
1546 int Deferred_log_events::add(
Log_event *ev)
1548 insert_dynamic(&array, (uchar*) &ev);
1553 bool Deferred_log_events::is_empty()
1555 return array.elements == 0;
1562 DBUG_ASSERT(rli->deferred_events_collecting);
1564 rli->deferred_events_collecting=
false;
1565 for (uint
i= 0; !res &&
i < array.elements;
i++)
1568 dynamic_array_ptr(&array,
i));
1569 res= ev->apply_event(rli);
1571 rli->deferred_events_collecting=
true;
1575 void Deferred_log_events::rewind()
1583 for (uint
i= 0;
i < array.elements;
i++)
1588 if (array.elements > array.max_element)
1589 freeze_size(&array);
1590 reset_dynamic(&array);