Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

novoselovmaks's avatar

Bulk Insert is very slow when the data contains values with a question mark

Laravel Version: 9.52.5 PHP Version: 8.1.7 Database Driver & Version: 10.6.8-MariaDB-1:10.6.8+maria~stretch

Hello

Insert is very slow when I want to save values with a question mark.

When processing for a long time, I immediately see my data in the DB table, but insert is still not finished.

but if I escape the question mark with two slashes, then the insertion works quickly. But the data is saved with a single slash.

A similar problem with: upsert, insertOrIgnore

Tell me how to get around this problem?

Example:

for ($i=0;$i<=1000;$i++)
{
        $data[] = [
            'host' => 'site.ru',
            'url' => "https://site.ru/page/?query=$i",
            'created_at' => \DB::raw('now()'),
            'updated_at' => \DB::raw('now()'),
        ];
 }
 Model::insert($data); 
0 likes
2 replies
fullstackalien's avatar

I'm dealing with this same issue right now. Did you ever figure anything out?

theartisandev's avatar

Hmmmm strange issue. Have you tried with the DB query builder directly and does it still happen?

DB::table('model')->insert([
    ...
]);

Please or to participate in this conversation.