| 9297 | */ |
| 9298 | |
| 9299 | int TABLE::update_virtual_fields(handler *h, enum_vcol_update_mode update_mode) |
| 9300 | { |
| 9301 | DBUG_ENTER("TABLE::update_virtual_fields"); |
| 9302 | DBUG_PRINT("enter", ("update_mode: %d is_error: %d", update_mode, |
| 9303 | in_use->is_error())); |
| 9304 | Field **vfield_ptr, *vf; |
| 9305 | Query_arena backup_arena; |
| 9306 | Turn_errors_to_warnings_handler Suppress_errors; |
| 9307 | bool handler_pushed= 0, update_all_columns= 1; |
| 9308 | DBUG_ASSERT(vfield); |
| 9309 | |
| 9310 | /* |
| 9311 | TODO: this imposes memory leak until table flush when save_in_field() |
| 9312 | does expr_arena allocation. F.ex. case in |
| 9313 | gcol.gcol_supported_sql_funcs_innodb (see CONVERT_TZ): |
| 9314 | |
| 9315 | create table t1 ( |
| 9316 | a datetime, b datetime generated always as |
| 9317 | (convert_tz(a, 'MET', 'UTC')) virtual); |
| 9318 | insert into t1 values ('2008-08-31', default); |
| 9319 | */ |
| 9320 | in_use->set_n_backup_active_arena(expr_arena, &backup_arena); |
| 9321 | |
| 9322 | /* When reading or deleting row, ignore errors from virtual columns */ |
| 9323 | if (update_mode == VCOL_UPDATE_FOR_READ || |
| 9324 | update_mode == VCOL_UPDATE_FOR_DELETE || |
| 9325 | update_mode == VCOL_UPDATE_INDEXED) |
| 9326 | { |
| 9327 | in_use->push_internal_handler(&Suppress_errors); |
| 9328 | handler_pushed= 1; |
| 9329 | } |
| 9330 | else if (update_mode == VCOL_UPDATE_FOR_REPLACE && |
| 9331 | in_use->is_current_stmt_binlog_format_row() && |
| 9332 | in_use->variables.binlog_row_image != BINLOG_ROW_IMAGE_MINIMAL) |
| 9333 | { |
| 9334 | /* |
| 9335 | If we are doing a replace with not minimal binary logging, we have to |
| 9336 | calculate all virtual columns. |
| 9337 | */ |
| 9338 | update_all_columns= 1; |
| 9339 | } |
| 9340 | |
| 9341 | /* Iterate over virtual fields in the table */ |
| 9342 | for (vfield_ptr= vfield; *vfield_ptr ; vfield_ptr++) |
| 9343 | { |
| 9344 | vf= (*vfield_ptr); |
| 9345 | Virtual_column_info *vcol_info= vf->vcol_info; |
| 9346 | DBUG_ASSERT(vcol_info); |
| 9347 | DBUG_ASSERT(vcol_info->expr); |
| 9348 | |
| 9349 | bool update= 0, swap_values= 0; |
| 9350 | switch (update_mode) { |
| 9351 | case VCOL_UPDATE_FOR_READ: |
| 9352 | if (!bitmap_is_set(read_set, vf->field_index)) |
| 9353 | update= false; |
| 9354 | else if (h->keyread_enabled()) |
| 9355 | { |
| 9356 | /* |
no test coverage detected