Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 296
user2094178 Avatar asked Sep 15 '13 02:09

user2094178


People also ask

Should Deleted_at be indexed?

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

How would you implement soft delete in laravel with example?

To soft delete a model you may use: $model = Contents::find( $id ); $model->delete(); Deleted (soft) models are identified by the timestamp and if deleted_at field is NULL then it's not deleted and using the restore method actually makes the deleted_at field NULL .


1 Answers

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

like image 184
rap-2-h Avatar answered Oct 14 '22 10:10

rap-2-h