| 1192 | */ |
| 1193 | |
| 1194 | TABLE *table_def::create_conversion_table(THD *thd, rpl_group_info *rgi, |
| 1195 | RPL_TABLE_LIST *table_list) const |
| 1196 | { |
| 1197 | Virtual_conversion_table *conv_table; |
| 1198 | Relay_log_info *rli= rgi->rli; |
| 1199 | TABLE *target_table= table_list->table; |
| 1200 | uint const cols_to_create= MY_MIN(size(), target_table->s->fields); |
| 1201 | DBUG_ENTER("table_def::create_conversion_table"); |
| 1202 | |
| 1203 | if (!(conv_table= new(thd) Virtual_conversion_table(thd)) || |
| 1204 | conv_table->init(cols_to_create)) |
| 1205 | goto err; |
| 1206 | |
| 1207 | /* |
| 1208 | Iterate through the number of columns logged on the master, and if |
| 1209 | skip any that are missing on the slave. Skipped columns are not |
| 1210 | added to the conv_table, as there is no column on the slave to use |
| 1211 | as the reference for the target_field. |
| 1212 | */ |
| 1213 | for (uint col= 0 ; col < cols_to_create; col++) |
| 1214 | { |
| 1215 | Field *field; |
| 1216 | if (master_to_slave_error[col]) |
| 1217 | continue; // Slave does not have field |
| 1218 | const Type_handler *ha= field_type_handler(col); |
| 1219 | if (!ha) |
| 1220 | { |
| 1221 | /* This can happen as we have not checked all columns in the caller */ |
| 1222 | master_to_slave_error[col]= SLAVE_FIELD_UNKNOWN_TYPE; |
| 1223 | continue; |
| 1224 | } |
| 1225 | |
| 1226 | field= target_table->field[master_to_slave_map[col]]; |
| 1227 | if (conv_table->add(ha, field_metadata(col), field)) |
| 1228 | { |
| 1229 | DBUG_PRINT("debug", ("binlog_type: %d, metadata: %04X, target_field: '%s'" |
| 1230 | " make_conversion_table_field() failed", |
| 1231 | binlog_type(col), field_metadata(col), |
| 1232 | field->field_name.str)); |
| 1233 | goto err; |
| 1234 | } |
| 1235 | /* |
| 1236 | We only use the conversion table for not null values |
| 1237 | This also avoids a bug in Virtual_conversion_table where the null |
| 1238 | pointer for created fields points to uninitialized memory. |
| 1239 | */ |
| 1240 | conv_table->make_not_null(); |
| 1241 | } |
| 1242 | |
| 1243 | conv_table->fix_field_count(); |
| 1244 | if (conv_table->open()) |
| 1245 | goto err; // Could not allocate record buffer? |
| 1246 | |
| 1247 | DBUG_RETURN(conv_table); |
| 1248 | |
| 1249 | err: |
| 1250 | if (conv_table) |
| 1251 | delete conv_table; |
nothing calls this directly
no test coverage detected