Hi,
Sergei Golubchik wrote:
> Hi!
>
> On Dec 19, Sunny Bains wrote:
>> Hi,
>>
>> I want to return the number of "rows affected" for the alter table
>> like below:
>>
>> mysql> alter table t1 add index i1(c1);
>> Query OK, 0 rows affected (0.02 sec)
>> Records: 0 Duplicates: 0 Warnings: 0
>>
>> In sql/sql_table.cc:bool mysql_alter_table(), after calling
>>
>> table->file->add_index(table, key_info, index_add_count)
>>
>> there doesn't seem to be a way to return the "rows affected".
>> The only time "copied" is set, is here:
>>
>> copied=deleted=0;
>> if (new_table && !(new_table->file->ha_table_flags() &
> HA_NO_COPY_ON_ALTER))
>> {
>> /* We don't want update TIMESTAMP fields during ALTER TABLE. */
>> new_table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
>> new_table->next_number_field=new_table->found_next_number_field;
>> error=copy_data_between_tables(table, new_table, create_list, ignore,
>> order_num, order, &copied, &deleted);
>> }
>
> Look at the end of the function:
>
> end_temporary:
> my_snprintf(tmp_name, sizeof(tmp_name), ER(ER_INSERT_INFO),
> (ulong) (copied + deleted), (ulong) deleted,
> (ulong) thd->cuted_fields);
> if (do_send_ok)
> send_ok(thd,copied+deleted,0L,tmp_name);
>
> the number of "rows affected" (second argument of send_ok()) is always the
> same as the number of "Records:" (fourth argument of my_snprintf()).
>
Perhaps I should have been more clear, I meant returning the number of
rows affected from file->add_index(), after creating the index(es).
Regards,
-sunny