索引的疑问以及字段注释的建议
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('installments', function (Blueprint $table) {
$table->bigIncrements('id')->comment('编号');
$table->string('no')->unique()->comment('分期流水号');
$table->unsignedBigInteger('user_id')->comment('用户编号');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->unsignedBigInteger('order_id')->comment('对应的商品订单编号');
$table->foreign('order_id')->references('id')->on('orders')->onDelete('cascade');
$table->decimal('total_amount')->comment('总本金');
$table->unsignedInteger('count')->comment('还款期数');
$table->float('fee_rate')->comment('手续费率');
$table->float('fine_rate')->comment('逾期费率');
$table->string('status')->default(\App\Models\Installment::STATUS_PENDING)->comment('还款状态');
$table->timestamps();
});
}
1、如上的建表语句,在自己开发中,总觉会给 user_id, order_id 等这样的字段添加 ->index() 索引,至于这个索引对查询的性能到底是提升、提升多少、还是降低了性能不知道如何跟踪,有点靠感觉。但是看老师的教程基本没看到这种普通索引的创建,老师可以讲讲对这个索引创建需要注意的地方吗?
2、另外建议在迁移文件中添加注释字段,便于后期对数据表的顺利解读,表示看别人没注释的表经常是一脸懵逼,一点个人习惯。
推荐文章: