cursorPaginate forces order by id asc and messes up the index selection in mysql for incrementing true models #51644
-
I saw that it is also handling sort on unions.
to not force the order by when there are no sorts and the model has incrementing true. What impact may this have on should Reverse and Unions?
On big data tables of million rows UNIONS sound like a bad bad idea.. just like order by id desc as it will mess up the index selection in mysql. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
I see that the asc from query determines the id > or < in where Also I see there orWhere which is again messing up the indexes... |
Beta Was this translation helpful? Give feedback.
-
PLEASE someone fix this in the core: Main changes needed are: \Illuminate\Database\Eloquent\Builder::ensureOrderForCursorPagination
and
|
Beta Was this translation helpful? Give feedback.
-
Created an issue that got ignored FYI: #51691 I tweaked my brain in solving this so the issue being rejected due to improper formatting is above my patience at this moment:) |
Beta Was this translation helpful? Give feedback.
-
My bad. I apologize. It seems that if an index is used, the results will be sorted by that index asc so the sort is needed.... So my above suggestion of fix is valid only when there are no filters applied. so
instead of
Updated the comment #51644 (comment) So the fix will just transform a query from:
When conditions are present, there will always be a sort applied.
Benchmark on table with '3134570' rows in Mysql 8: With fix: With fix and condition: Without fix: |
Beta Was this translation helpful? Give feedback.
My bad. I apologize. It seems that if an index is used, the results will be sorted by that index asc so the sort is needed....
So my above suggestion of fix is valid only when there are no filters applied.
so
if (!$this->model->incrementing || $shouldReverse || $this->query->wheres !== []) {
instead of
if (!$this->model->incrementing || $shouldReverse) {
Updated the comment #51644 (comment)
So the fix will just transform a query from:
When conditions are pre…