Search code examples
mysqllaraveleloquent

Eloquent ORM, deleted_at has no index when using soft deleting


If I use $table->softDeletes() in a migration, a deleted_at timestamp nullable column is added to the table.

From now on I can come to the conclusion that any query against this table via eloquent will carry a WHERE deleted_at IS NULL clause, assuring only live records are returned.

But I noticed there is no index created for deleted_at. Shouldn't be paramount for this column to have an index?

I hope I'm missing something.


Solution

  • According to this answer, you should not index your deleted_at column. There will be no beneficial impact on performance.