Skip to content

Commit f758b16

Browse files
[8.x] Add support for MariaDB to skip locked rows with the database queue driver (#39311)
* Add support for MariaDB to skip locked rows with the database queue driver As documented in https://mariadb.com/kb/en/select/#skip-locked since MariaDB 10.6 there is support for skipping locked rows when fetching from the database. This change adds support to it. * Update DatabaseQueue.php Co-authored-by: Taylor Otwell <[email protected]>
1 parent 4b785c6 commit f758b16

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/Illuminate/Queue/DatabaseQueue.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Illuminate\Queue\Jobs\DatabaseJob;
99
use Illuminate\Queue\Jobs\DatabaseJobRecord;
1010
use Illuminate\Support\Carbon;
11+
use Illuminate\Support\Str;
1112
use PDO;
1213

1314
class DatabaseQueue extends Queue implements QueueContract, ClearableQueue
@@ -251,10 +252,13 @@ protected function getNextAvailableJob($queue)
251252
protected function getLockForPopping()
252253
{
253254
$databaseEngine = $this->database->getPdo()->getAttribute(PDO::ATTR_DRIVER_NAME);
254-
$databaseVersion = $this->database->getConfig('version') ?? $this->database->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION);
255255

256-
if ($databaseEngine === 'mysql' && ! strpos($databaseVersion, 'MariaDB') && version_compare($databaseVersion, '8.0.1', '>=') ||
257-
$databaseEngine === 'pgsql' && version_compare($databaseVersion, '9.5', '>=')) {
256+
$databaseVersion = $this->database->getConfig('version') ??
257+
$this->database->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION);
258+
259+
if (($databaseEngine === 'mysql' && version_compare($databaseVersion, '8.0.1', '>=')) ||
260+
(strpos($databaseVersion, 'MariaDB') && version_compare(Str::after($databaseVersion, '-'), '10.6.0', '>=')) ||
261+
($databaseEngine === 'pgsql' && version_compare($databaseVersion, '9.5', '>='))) {
258262
return 'FOR UPDATE SKIP LOCKED';
259263
}
260264

0 commit comments

Comments
 (0)