| 1570 | */ |
| 1571 | |
| 1572 | static bool check_view_insertability(THD *thd, TABLE_LIST *view, |
| 1573 | List<Item> &fields) |
| 1574 | { |
| 1575 | uint num= view->view->first_select_lex()->item_list.elements; |
| 1576 | TABLE *table= view->table; |
| 1577 | Field_translator *trans_start= view->field_translation, |
| 1578 | *trans_end= trans_start + num; |
| 1579 | Field_translator *trans; |
| 1580 | uint used_fields_buff_size= bitmap_buffer_size(table->s->fields); |
| 1581 | my_bitmap_map *used_fields_buff= (my_bitmap_map*)thd->alloc(used_fields_buff_size); |
| 1582 | MY_BITMAP used_fields; |
| 1583 | enum_column_usage saved_column_usage= thd->column_usage; |
| 1584 | List_iterator_fast<Item> it(fields); |
| 1585 | Item *ex; |
| 1586 | DBUG_ENTER("check_key_in_view"); |
| 1587 | |
| 1588 | if (!used_fields_buff) |
| 1589 | DBUG_RETURN(TRUE); // EOM |
| 1590 | |
| 1591 | DBUG_ASSERT(view->table != 0 && view->field_translation != 0); |
| 1592 | |
| 1593 | (void) my_bitmap_init(&used_fields, used_fields_buff, table->s->fields); |
| 1594 | bitmap_clear_all(&used_fields); |
| 1595 | |
| 1596 | view->contain_auto_increment= 0; |
| 1597 | /* |
| 1598 | we must not set query_id for fields as they're not |
| 1599 | really used in this context |
| 1600 | */ |
| 1601 | thd->column_usage= COLUMNS_WRITE; |
| 1602 | /* check simplicity and prepare unique test of view */ |
| 1603 | for (trans= trans_start; trans != trans_end; trans++) |
| 1604 | { |
| 1605 | if (trans->item->fix_fields_if_needed(thd, &trans->item)) |
| 1606 | { |
| 1607 | thd->column_usage= saved_column_usage; |
| 1608 | DBUG_RETURN(TRUE); |
| 1609 | } |
| 1610 | Item_field *field; |
| 1611 | /* simple SELECT list entry (field without expression) */ |
| 1612 | if (!(field= trans->item->field_for_view_update())) |
| 1613 | { |
| 1614 | // Do not check fields which we are not inserting into |
| 1615 | while((ex= it++)) |
| 1616 | { |
| 1617 | // The field used in the INSERT |
| 1618 | if (ex->real_item()->field_for_view_update() == |
| 1619 | trans->item->field_for_view_update()) |
| 1620 | break; |
| 1621 | } |
| 1622 | it.rewind(); |
| 1623 | if (!ex) |
| 1624 | continue; |
| 1625 | thd->column_usage= saved_column_usage; |
| 1626 | DBUG_RETURN(TRUE); |
| 1627 | } |
| 1628 | if (field->field->unireg_check == Field::NEXT_NUMBER) |
| 1629 | view->contain_auto_increment= 1; |
no test coverage detected