-
Notifications
You must be signed in to change notification settings - Fork 11.6k
Compile full DELETE with JOIN including ORDER BY and LIMIT in MySQL grammar #57138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compile full DELETE with JOIN including ORDER BY and LIMIT in MySQL grammar #57138
Conversation
Moved to draft as tests are failing |
update tests to cover mysql specific delete with join restrictions |
Why not just generate the invalid statement always, so that you get the error back from MySQL? |
@GrahamCampbell
|
Some MySQL servers do support delete join with limit and order by though. For example Vitess and PlanetScale. vitessio/vitess#14959 |
It works by selecting the rows with a lock for update, and then performing the delete using a wherein. |
@GrahamCampbell |
I still think it's better to just allow the server to complain the query is invalid. |
@GrahamCampbell |
I sort of agree that maybe we should just add the LIMIT and if the underlying MySQL system doesn't like it then it will error anyways? But, those using PlanetScale would still be able to use that feature? |
@taylorotwell agree, maybe it's better option and good compromise. And this still solve my initial problem. I've changed title and description. Enable ORDER BY and LIMIT compilation in MySQL DELETE … JOIN queries, updating tests to assert full SQL generation. |
Can we send this to |
…g actions and names (laravel#56920) * Ensure cached and uncached routes share same precedence * formatting * Formatting * formatting * Fix tests
* SQLite: Allow setting any pragmas * formatting --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
…ith ?LoggerInterface (laravel#57028)
Finding the middle of a list of values using the float div operator (/) is wrong, and goes wrong at some higher values where the int/2 is not representable as a float to single digit precision. That's why intdiv() exists.
* Fix PHP 8.5 null-key deprecations * Fix getOrPut * Update InteractsWithIO.php * Update Collection.php --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
This reverts commit af710f5.
* fix static analysis error * fix typehint instead
…aravel#57157) This adds null coalescing to maintain backward compatibility when Htmlable::toHtml() returns non-string values. **Breaking Change Context:** The addition of explicit `: string` return type creates a BC break because Htmlable::toHtml() only has PHPDoc type hints, not runtime enforcement. IMHO it should probably be reverted, this commit provides at least some backward compatibility. **Example of previously valid code that now breaks:** ```php class CustomHtmlable implements Htmlable { public function toHtml() { // Valid before: PHPDoc says @return string but no runtime enforcement return $this->hasContent() ? $this->content : null; } } // This worked before but now causes TypeError echo e(new CustomHtmlable());
* use copy instead of reference * style fix
* Remove Request overview from Exceptions * Fix HTTP status code
Co-authored-by: Sergey Danilchenko <s.danilchenko@ttbooking.ru>
Co-authored-by: Sergey Danilchenko <s.danilchenko@ttbooking.ru>
…e joined clause handling
bd43b53
to
accc64a
Compare
I'll close this PR and open a new one against master with a clean branch based on the latest upstream. |
Problem
By default, Laravel silently ignores
ORDER BY
andLIMIT
onDELETE … JOIN
queries when using the MySQL grammar.This results in unexpected behavior: instead of deleting rows in small batches, the query deletes all matching rows at once.
Example:
Expected: delete in batches of 500
Actual: deletes all 500k+ rows in one query
Fix
compileDeleteWithJoins
override inMySqlGrammar
.JOIN
,ORDER BY
, andLIMIT
instead of stripping them.Why
ORDER BY
andLIMIT
, which could lead to accidental mass deletions.DELETE … JOIN … ORDER BY/LIMIT
.QueryException
.