发布于 4年前

为 Laravel 迁移的 created_at 和 updated_at 字段添加索引

Laravel 迁移中 timestamps() 会创建 created_atupdated_at 字段。 为 created_at 字段增加索引能极大提升使用此字段排序时的速度:

Schema::create('posts', function(Blueprint $table) {
    $table->increments('id');
    ...
    $table->timestamps();
    // 单独创建索引
    $table->index('updated_at');
    $table->index('created_at');
});
©2020 edoou.com   京ICP备16001874号-3