Skip to content

cursorPaginate forces order by id asc and messes up the index selection in mysql for incrementing true models #51644

Closed Answered by marius-mcp
marius-mcp asked this question in Q&A
Discussion options

You must be logged in to vote

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:

select * from table order by table.id asc limit 3;

to

select * from `table` limit 3"

AND

select * from `table` where (`table`.`id` > 2) order by table.id asc limit 3"

to

select * from `table` where (`table`.`id` > 2) limit 3"

When conditions are pre…

Replies: 4 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@marius-mcp
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by marius-mcp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant