PHPHub 迁移数据库文件中 nullable 和索引的问题
数据库字段设置可为null,对索引有性能影响吗?
网上搜到的很多答案都是说有性能影响的,并且不提示设置为null,
文件路径:database/migrateions/2016_07_03_021841_create_users_table.php
内容:
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->integer('github_id')->index();
$table->string('github_url');
$table->string('email')->nullable()->index();
$table->string('name')->nullable()->index();
$table->string('login_token')->nullable();
$table->string('remember_token')->nullable();
$table->enum('is_banned', ['yes', 'no'])->default('no')->index();
$table->string('image_url')->nullable();
$table->integer('topic_count')->default(0)->index();
$table->integer('reply_count')->default(0)->index();
$table->integer('follower_count')->default(0)->index();
$table->string('city')->nullable();
$table->string('company')->nullable();
$table->string('twitter_account')->nullable();
$table->string('personal_website')->nullable();
$table->string('introduction')->nullable();
$table->string('certification')->nullable();
$table->integer('notification_count')->default(0);
$table->string('github_name')->index();
$table->string('real_name')->nullable();
$table->string('linkedin')->nullable();
$table->string('payment_qrcode')->nullable();
$table->string('wechat_qrcode')->nullable();
$table->string('avatar');
$table->string('login_qr')->nullable();
$table->string('wechat_openid')->nullable()->index();
$table->string('wechat_unionid')->nullable()->index();
$table->string('weibo_name')->nullable();
$table->string('weibo_link')->nullable();
$table->boolean('verified')->default(false)->index();
$table->string('verification_token')->nullable();
$table->enum('email_notify_enabled', ['yes', 'no'])->default('yes')->index();
$table->string('register_source')->index();
$table->timestamp('last_actived_at')->nullable();
$table->softDeletes();
$table->timestamps();
});
}
这种设置为nullable并建有索引的会有问题吗?
没有问题,非null的时候索引效率会比较高一点。