Closed
Description
- Laravel Version: 5.8.32
- PHP Version: 7.3.8
- Database Driver & Version: MariaDB 10.2.23
Description / Repro Steps:
- Build a query that leverages where/orWhere
User::query()
->where(function (Builder $query) {
// basic where
})
->orWhere(function (Builder $query) {
// basic where
})
->chunkById(50, function (Collection $users) {
// logic
});
This generates
SELECT * FROM … WHERE a OR b AND id > X
Which when grouped becomes
SELECT * FROM … WHERE a OR (b AND id > X)
While I think it should be
SELECT * FROM … WHERE (a OR b) AND id > X
This led to a situation where our queue system ran out of bounds and just queued millions of millions of jobs until redis died out.
Workaround
User::query()
->where(function (Builder $query) {
$query->where(function (Builder $query) {
// basic where
})
->orWhere(function (Builder $query) {
// basic where
});
})
->chunkById(50, function (Collection $users) {
// logic
});
We basically just shove the logic into a where closure to force the grouping. I think this is a bug or at least unexpected behavior.