I want to know how to search a single record from a 6000k+ record database. I have written a query for it but I am facing 15s load time it's too high for the efficient system so please help me to search in an efficient way to take lower response time in searching.
$users = DB::select('select * from tablefour where Provider_Business_Mailing_Address_Fax_Number = ?', array($request['id'])); 
return $users;
                
Make the column index then search will work fast on that column.This help me.
For Laravel:- Do this in 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']);
        });
    }
}
                        1st Only select those columns which you needed.
$users = \DB::table('tablefour')->select(['columnone','columntwo'])->whereIn('Provider_Business_Mailing_Address_Fax_Number',array($request['id']))->get();
return $users;
2nd
Make indexing on those columns in which columns are you selecting.
Check @Rana Nadeem answer for how to make indexing.
using migration
Schema::table('tablefour', function (Blueprint $table) {
    $table->index('user_id');
});
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With