0

In which cases do I need to call the index method in my migration file?

I don't really understand the description in the documentation.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Tobi
  • 83
  • 8
  • When you need one. See http://stackoverflow.com/questions/3567981/how-do-mysql-indexes-work for MySQL on when/why to index. – ceejayoz Mar 23 '16 at 18:07

1 Answers1

1

Actually, in SQL the indexing is a mechanism to speed up the database lookup. Hence, there are couple of types of indexing available including unique and primary. So, the index method is used to create an index of your table with provided keys where other indexes (unique and primary) have their own characteristics.

So, if you just want to create an index to speed up the query then use the index method. this is a good reference to read about indexes.

An index is a distinct structure in the database that is built using the create index statement. It requires its own disk space and holds a copy of the indexed table data.

Basically, you don't need to create an index and if you use a column as primary key then that's enough, no need to create any index. Also you may check the wiki.

The Alpha
  • 143,660
  • 29
  • 287
  • 307