Does Laravel's “soft_delete” need index on MySQL?

前端 未结 3 1051
忘了有多久
忘了有多久 2020-12-13 06:59

If i\'m using soft delete in laravel 4.2 (database is mysql), every eloquent query has WHERE deleted_at IS NULL. There are no indexes on deleted_at

3条回答
  •  没有蜡笔的小新
    2020-12-13 07:21

    I don't know why the above by @N.B. has so many upvotes, in my context I find this completely incorrect.

    I added indexes to deleted_at timestamps on some keys tables and enjoyed some queries dropping from 32s to less than 5.4ms. It really depends on the nature of of your app.

    In my scenario, I have 3 tables with soft deletes, some simple joins (all with indexes), but my queries suffered due to the default nature of Laravel's handling of soft deletes.

    I highly recommended indexing these columns so your app does choke when record numbers elevate.

提交回复
热议问题