0

I have a table like this:

| id | user_id | ... | ... | ...

Where id is the primary key. What indexing should I apply to the user_id column (note that there can be multiple rows in this table from the same user)? Just a regular index?

  • 2
    Its not compulsory to to use indexes. Use them if it is required. And if required... please mention the reason for indexing that column. – Rajadip Oct 02 '17 at 19:31
  • If it's a foreign key, it's indexed anyway. If not, don't bother. – Nikolaus Oct 02 '17 at 20:59
  • Yes, use `index`. And, yes, _bother_ to use that index. https://stackoverflow.com/questions/2955459/what-is-an-index-in-sql – Jarek Tkaczyk Oct 03 '17 at 13:14

1 Answers1

0

Look into Eloquent Relationships - https://laravel.com/docs/5.5/eloquent-relationships#defining-relationships

Depending on the relationship, one-to-one, one-to-many or many-to-many, you will set up foreign keys in your database migrations and define the relationship type in the related models.

There is no need to apply indexing to the user_id column over and above that.

kerrin
  • 3,376
  • 1
  • 26
  • 36