Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySql Add Index : 0 Rows Affected

Tags:

indexing

mysql

Alter table table1 add index col1_idx (column1);

Even though the table1 has many rows and all of the have non null values for column1, the above query says "0 Rows AFfected". Why could this be?

like image 863
simplfuzz Avatar asked Jun 01 '12 06:06

simplfuzz


People also ask

Does adding an index lock a table?

Yes you can. It will lock the table you're adding an index to while it's being created. If the table is large, it may take awhile as it has to read each row while building the index.

What happen if add index on all column in table?

Adding an index means that the database has to maintain it, that means that it has to be updated, so the more writes you have, the more the index will be updated. Save this answer.

What does add index do in MySQL?

In MySQL, an index can be created on a table when the table is created with CREATE TABLE command. Otherwise, CREATE INDEX enables to add indexes to existing tables. A multiple-column index can be created using multiple columns.

Does MySQL support partial index?

MySQL does not support partial indexes.


1 Answers

That is because the query is not directly affecting any rows as opposed to an update statement where you modify the row. It (very, very, very basically) only changes how the column is stored and sorted.

like image 91
alexn Avatar answered Oct 26 '22 19:10

alexn