You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've come across an issue, which is causing fastpaginate to operate about 3x slower than normal paginate.
I believe this is the same thing as mentioned in issue #41
From what I can see (I may be wrong here), when using fastpaginate, 3 queries are executed:
A pagination query (SELECT count(*) as aggregate...) to populate page numbers
A limit/offset/range query (SELECT id FROM table WHERE <your ORM where conditions>) to get the IDs to select
A results query (SELECT <selected_columns> FROM table WHERE <your ORM conditions> AND id IN ( <list_from_last_query>)
I have a complex where query run, which is executed by fastpaginate (SELECT id FROM ...) to get the ID list, and then it does the results query (SELECT <rows> FROM ...) and adds the WHERE id IN (...)), however, it leaves the rest of the complex where query there, so it's searching through all the WHEREs etc as -well- as the ID in ...
(for those curious, its complex due to applying a multi-option filter to results)
This means that FastPaginate takes about 30 seconds (between the pagination query, ID list query and results query) to execute where the inbuilt paginator (with just the pagination query and results query) takes about 10 seconds.
I've done some light testing in raw SQL using the final results query that fastpaginate executed (grabbed from telescope). If I run the query in my SQL client, it takes about 22 seconds (which matches telescopes execution time display)... if I remove my complex where query and just leave it as the ID where (SELECT <columns> FROM table WHERE id IN (...)), it takes 50-100ms.
Final results query as executed by fastpaginate
Same query as above, but with all WHERE clauses removed except WHERE id IN (...)
Sure, I can probably do more to optimise the database and/or queries... But from what I've seen (admittedly, I'm not super skilled in proper deep debugging of database performance), it would seem like having fastPaginate rewrite the last query to only use the WHERE id IN (...) and none of the other WHERE etc clauses could potentially have some performance assists in certain cases. Not sure how hard this would be (or if it's even possible), but would be amazing if it could be done.
Telescope Query Stats - FastPaginate
Telescope Query Stats - normal Paginate
These are the queries in question that are being executed by the above.
I'm not very experienced with the laravel base query builder, but from playing around in tinkerwell, could you possibly just clear the wheres from the builder for the final query and then add the IDs whereIn? Would that work?
I've come across an issue, which is causing fastpaginate to operate about 3x slower than normal paginate.
I believe this is the same thing as mentioned in issue #41
From what I can see (I may be wrong here), when using fastpaginate, 3 queries are executed:
SELECT count(*) as aggregate...
) to populate page numbersSELECT id FROM table WHERE <your ORM where conditions>
) to get the IDs to selectSELECT <selected_columns> FROM table WHERE <your ORM conditions> AND id IN ( <list_from_last_query>
)I have a complex where query run, which is executed by fastpaginate (
SELECT id FROM ...
) to get the ID list, and then it does the results query (SELECT <rows> FROM ...
) and adds theWHERE id IN (...)
), however, it leaves the rest of the complex where query there, so it's searching through all the WHEREs etc as -well- as theID in ...
(for those curious, its complex due to applying a multi-option filter to results)
This means that FastPaginate takes about 30 seconds (between the pagination query, ID list query and results query) to execute where the inbuilt paginator (with just the pagination query and results query) takes about 10 seconds.
I've done some light testing in raw SQL using the final results query that fastpaginate executed (grabbed from telescope). If I run the query in my SQL client, it takes about 22 seconds (which matches telescopes execution time display)... if I remove my complex where query and just leave it as the ID where (
SELECT <columns> FROM table WHERE id IN (...)
), it takes 50-100ms.Final results query as executed by fastpaginate

Same query as above, but with all WHERE clauses removed except

WHERE id IN (...)
Sure, I can probably do more to optimise the database and/or queries... But from what I've seen (admittedly, I'm not super skilled in proper deep debugging of database performance), it would seem like having fastPaginate rewrite the last query to only use the
WHERE id IN (...)
and none of the other WHERE etc clauses could potentially have some performance assists in certain cases. Not sure how hard this would be (or if it's even possible), but would be amazing if it could be done.Telescope Query Stats - FastPaginate

Telescope Query Stats - normal Paginate

These are the queries in question that are being executed by the above.
Executed by fastPaginate:
Changing the second query to
cuts off about 20 seconds or so in execution.
The text was updated successfully, but these errors were encountered: