4

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;
2
  • 4
    Have you created an index for Provider_Business_Mailing_Address_Fax_Number column? May 13, 2020 at 11:25
  • welcome to SO. here is my opinion, there are several way to query optimisation in database, in your situation database is more responsible than PHP or Laravel May 13, 2020 at 11:30

2 Answers 2

5

enter image description here

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']);
        });
    }
}
0
2

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');
});

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.