| 9701 | |
| 9702 | |
| 9703 | bool optimize_schema_tables_memory_usage(List<TABLE_LIST> &tables) |
| 9704 | { |
| 9705 | DBUG_ENTER("optimize_schema_tables_memory_usage"); |
| 9706 | |
| 9707 | List_iterator<TABLE_LIST> tli(tables); |
| 9708 | |
| 9709 | while (TABLE_LIST *table_list= tli++) |
| 9710 | { |
| 9711 | if (!table_list->schema_table) |
| 9712 | continue; |
| 9713 | |
| 9714 | TABLE *table= table_list->table; |
| 9715 | THD *thd=table->in_use; |
| 9716 | |
| 9717 | if (!thd->fill_information_schema_tables()) |
| 9718 | continue; |
| 9719 | |
| 9720 | if (!table->is_created()) |
| 9721 | { |
| 9722 | TMP_TABLE_PARAM *p= table_list->schema_table_param; |
| 9723 | TMP_ENGINE_COLUMNDEF *from_recinfo, *to_recinfo; |
| 9724 | DBUG_ASSERT(table->s->keys == 0); |
| 9725 | |
| 9726 | uchar *cur= table->field[0]->ptr; |
| 9727 | /* first recinfo could be a NULL bitmap, not an actual Field */ |
| 9728 | from_recinfo= to_recinfo= p->start_recinfo + (cur != table->record[0]); |
| 9729 | for (uint i=0; i < table->s->fields; i++, from_recinfo++) |
| 9730 | { |
| 9731 | Field *field= table->field[i]; |
| 9732 | DBUG_ASSERT(field->vcol_info == 0); |
| 9733 | DBUG_ASSERT(from_recinfo->length); |
| 9734 | DBUG_ASSERT(from_recinfo->length == field->pack_length_in_rec()); |
| 9735 | if (bitmap_is_set(table->read_set, i)) |
| 9736 | { |
| 9737 | field->move_field(cur); |
| 9738 | field->reset(); |
| 9739 | *to_recinfo++= *from_recinfo; |
| 9740 | cur+= from_recinfo->length; |
| 9741 | } |
| 9742 | else |
| 9743 | { |
| 9744 | field= new (thd->mem_root) Field_string(cur, 0, field->null_ptr, |
| 9745 | field->null_bit, Field::NONE, |
| 9746 | &field->field_name, field->dtcollation()); |
| 9747 | field->init(table); |
| 9748 | field->field_index= i; |
| 9749 | DBUG_ASSERT(field->pack_length_in_rec() == 0); |
| 9750 | table->field[i]= field; |
| 9751 | } |
| 9752 | } |
| 9753 | if ((table->s->reclength= (ulong)(cur - table->record[0])) == 0) |
| 9754 | { |
| 9755 | /* all fields were optimized away. Force a non-0-length row */ |
| 9756 | table->s->reclength= to_recinfo->length= 1; |
| 9757 | to_recinfo->type= FIELD_NORMAL; |
| 9758 | to_recinfo++; |
| 9759 | } |
| 9760 | store_record(table, s->default_values); |
no test coverage detected