我想知道如何从6000k+记录数据库中搜索单个记录。我已经为其编写了一个查询,但我面临的15s加载时间对于高效系统来说太长了,因此请帮助我以有效的方式进行搜索,以缩短搜索的响应时间。
$users = DB::select('select * from tablefour where Provider_Business_Mailing_Address_Fax_Number = ?', array($request['id']));
return $users;
Run Code Online (Sandbox Code Playgroud)
创建列索引,然后搜索将在该列上快速运行。这对我有帮助。
对于 Laravel:- 在 Schema 中执行此操作
final class AddIndexesTableFour extends Migration
{
public function up(): void
{
Schema::table('tablefour', function (Blueprint $table) {
$table->index('Provider_Business_Mailing_Address_Telephone_Number');
});
}
public function down(): void
{
Schema::table('tablefour', function (Blueprint $table) {
$table->dropIndex(['Provider_Business_Mailing_Address_Telephone_Number']);
});
}
}
Run Code Online (Sandbox Code Playgroud)