<bdo id='Nsu1f'></bdo><ul id='Nsu1f'></ul>
  • <small id='Nsu1f'></small><noframes id='Nsu1f'>

    <tfoot id='Nsu1f'></tfoot>

      <legend id='Nsu1f'><style id='Nsu1f'><dir id='Nsu1f'><q id='Nsu1f'></q></dir></style></legend>
      1. <i id='Nsu1f'><tr id='Nsu1f'><dt id='Nsu1f'><q id='Nsu1f'><span id='Nsu1f'><b id='Nsu1f'><form id='Nsu1f'><ins id='Nsu1f'></ins><ul id='Nsu1f'></ul><sub id='Nsu1f'></sub></form><legend id='Nsu1f'></legend><bdo id='Nsu1f'><pre id='Nsu1f'><center id='Nsu1f'></center></pre></bdo></b><th id='Nsu1f'></th></span></q></dt></tr></i><div id='Nsu1f'><tfoot id='Nsu1f'></tfoot><dl id='Nsu1f'><fieldset id='Nsu1f'></fieldset></dl></div>

        Laravel 的“soft_delete"是否会被删除?需要在 MySQL 上建立索引吗?

        时间:2023-10-25

        <small id='ltfkh'></small><noframes id='ltfkh'>

          • <i id='ltfkh'><tr id='ltfkh'><dt id='ltfkh'><q id='ltfkh'><span id='ltfkh'><b id='ltfkh'><form id='ltfkh'><ins id='ltfkh'></ins><ul id='ltfkh'></ul><sub id='ltfkh'></sub></form><legend id='ltfkh'></legend><bdo id='ltfkh'><pre id='ltfkh'><center id='ltfkh'></center></pre></bdo></b><th id='ltfkh'></th></span></q></dt></tr></i><div id='ltfkh'><tfoot id='ltfkh'></tfoot><dl id='ltfkh'><fieldset id='ltfkh'></fieldset></dl></div>
                <bdo id='ltfkh'></bdo><ul id='ltfkh'></ul>
                <tfoot id='ltfkh'></tfoot>
                    <tbody id='ltfkh'></tbody>
                  <legend id='ltfkh'><style id='ltfkh'><dir id='ltfkh'><q id='ltfkh'></q></dir></style></legend>

                  本文介绍了Laravel 的“soft_delete"是否会被删除?需要在 MySQL 上建立索引吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如果我在 laravel 4.2 中使用软删除(数据库是 mysql),每个雄辩的查询都有 WHERE deleted_at IS NULL.deleted_at 上没有索引.

                  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.

                  • 在大桌子上会很慢吗?(或者可能 IS NULL 在不需要索引的情况下进行了优化)
                  • 我应该在 deleted_at 列上添加索引吗?
                  • Will it be slow on big tables? (or maybe IS NULL is optimized without needing an index)
                  • Should I add an index on the deleted_at column?

                  那么,Laravel 的soft_delete"deleted_at 列是否需要在 MySQL 中建立索引?

                  So, does Laravel's "soft_delete" deleted_at column need an index in MySQL?

                  说明: Laravel 在 deleted_at 列中存储时间戳,以表示记录何时被软删除,而不是布尔值.

                  Clarification: Laravel stores a timestamp in the deleted_at column to denote when a record has been soft deleted, as opposed to a boolean value.

                  推荐答案

                  deleted_at 列不是一个好的索引候选.与评论相比,我将尝试更好地解释:索引仅在基数相对较高时才有用.基数是描述数据集中索引唯一性的数字.这意味着它是记录总数除以唯一记录总数.

                  The column deleted_at is not a good index candidate. I'll try to explain better compared to the comment: indexes are useful only when their cardinality is relatively high. Cardinality is a number that describes index uniqueness in the data-set. That means it's total number of records divided by total unique records.

                  例如,主键的基数为1.每条记录都包含主键的唯一值.1 也是最高的数字.您可以将其视为100%".

                  For example, the cardinality of primary key is 1. Every record contains unique value for primary key. 1 is also, the highest number. You can consider it as a "100%".

                  但是,诸如deleted_at 之类的列没有这样的值.Laravel 对删除的_at 所做的是检查它是否为空.这意味着它有两个可能的值.包含两个值的列具有极低的基数,基数随着记录数的增加而减少.

                  But, a column such as deleted_at doesn't have such a value. What Laravel does with deleted_at is check whether it is or isn't null. That means it has two possible values. Columns that contain two values have extremely low cardinality which decreases as number of records goes up.

                  您可以为这样的列建立索引,但这没有任何帮助.将会发生的情况是它可能会减慢速度并占用空间.

                  You can index such a column, but it won't be of any help. What will happen is that it could slow things down and take up space.

                  TL;DR:不,您不必为该列建立索引,索引不会对性能产生有益影响.

                  TL;DR: no, you don't have to index that column, index will have no beneficial impact on performance.

                  这篇关于Laravel 的“soft_delete"是否会被删除?需要在 MySQL 上建立索引吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何确定mysql索引是否完全适合内存 下一篇:你如何达到每行 8060 字节和每个(varchar,nvarchar)值 8000 的限制?

                  相关文章

                  <small id='Mjpz0'></small><noframes id='Mjpz0'>

                    <i id='Mjpz0'><tr id='Mjpz0'><dt id='Mjpz0'><q id='Mjpz0'><span id='Mjpz0'><b id='Mjpz0'><form id='Mjpz0'><ins id='Mjpz0'></ins><ul id='Mjpz0'></ul><sub id='Mjpz0'></sub></form><legend id='Mjpz0'></legend><bdo id='Mjpz0'><pre id='Mjpz0'><center id='Mjpz0'></center></pre></bdo></b><th id='Mjpz0'></th></span></q></dt></tr></i><div id='Mjpz0'><tfoot id='Mjpz0'></tfoot><dl id='Mjpz0'><fieldset id='Mjpz0'></fieldset></dl></div>
                      <bdo id='Mjpz0'></bdo><ul id='Mjpz0'></ul>

                    1. <tfoot id='Mjpz0'></tfoot>

                      <legend id='Mjpz0'><style id='Mjpz0'><dir id='Mjpz0'><q id='Mjpz0'></q></dir></style></legend>